Skip to content

Commit

Permalink
chore(Customer): refetch on add subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
ansmonjol committed Mar 10, 2023
1 parent 76edf62 commit aa35d90
Showing 1 changed file with 1 addition and 29 deletions.
30 changes: 1 addition & 29 deletions src/hooks/customer/useAddSubscription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -91,6 +89,7 @@ export const useAddSubscription: UseAddSubscription = ({
})
}
},
refetchQueries: ['getCustomer'],
})

const selectedPlan = useMemo(() => {
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit aa35d90

Please sign in to comment.