From aa35d9017daad581fe1b0fb1f5ecb78cdb54e1ff Mon Sep 17 00:00:00 2001 From: Alexandre Monjol Date: Thu, 9 Mar 2023 17:19:51 +0100 Subject: [PATCH] chore(Customer): refetch on add subscription --- src/hooks/customer/useAddSubscription.tsx | 30 +---------------------- 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/src/hooks/customer/useAddSubscription.tsx b/src/hooks/customer/useAddSubscription.tsx index 99ef3fff5..f4c16ae38 100644 --- a/src/hooks/customer/useAddSubscription.tsx +++ b/src/hooks/customer/useAddSubscription.tsx @@ -12,8 +12,6 @@ import { LagoApiError, CreateSubscriptionInput, CustomerSubscriptionFragmentDoc, - CustomerDetailsFragmentDoc, - CustomerDetailsFragment, } from '~/generated/graphql' import { SubscriptionUpdateInfo, addToast, hasDefinedGQLError } from '~/core/apolloClient' import { ComboBoxProps } from '~/components/form' @@ -91,6 +89,7 @@ export const useAddSubscription: UseAddSubscription = ({ }) } }, + refetchQueries: ['getCustomer'], }) const selectedPlan = useMemo(() => { @@ -176,33 +175,6 @@ export const useAddSubscription: UseAddSubscription = ({ ...values, }, }, - update(cache, { data: createData }) { - if (!createData?.createSubscription) return - - const cacheId = `Customer:${customerId}` - - const previousData: CustomerDetailsFragment | null = cache.readFragment({ - id: cacheId, - fragment: CustomerDetailsFragmentDoc, - fragmentName: 'CustomerDetails', - }) - - cache.writeFragment({ - id: cacheId, - fragment: CustomerDetailsFragmentDoc, - fragmentName: 'CustomerDetails', - data: { - ...previousData, - subscriptions: [ - createData?.createSubscription, - ...(previousData?.subscriptions || []).map((s) => ({ - ...s, - __typename: 'Subscription', // The query has nested fragment and the typename is removed - we need to re-add it for it to work - })), - ], - }, - }) - }, }) if (!hasDefinedGQLError('CurrenciesDoesNotMatch', errors)) {