MCPcopy Index your code
hub / github.com/simstudioai/sim / useUnsubscribeMutation

Function useUnsubscribeMutation

apps/sim/hooks/queries/unsubscribe.ts:50–76  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

48 * affected option immediately reflects the unsubscribed state.
49 */
50export function useUnsubscribeMutation() {
51 const queryClient = useQueryClient()
52 return useMutation<UnsubscribeActionResponse, Error, UnsubscribeVariables>({
53 mutationFn: ({ email, token, type }) =>
54 requestJson(unsubscribePostContract, { body: { email, token, type } }),
55 onSuccess: (_data, { email, token, type }) => {
56 const key = unsubscribeKeys.detail(email, token)
57 queryClient.setQueryData<UnsubscribeData>(key, (previous) => {
58 if (!previous) return previous
59 const preferenceKey =
60 type === 'all'
61 ? 'unsubscribeAll'
62 : (`unsubscribe${type.charAt(0).toUpperCase()}${type.slice(1)}` as
63 | 'unsubscribeMarketing'
64 | 'unsubscribeUpdates'
65 | 'unsubscribeNotifications')
66 return {
67 ...previous,
68 currentPreferences: {
69 ...previous.currentPreferences,
70 [preferenceKey]: true,
71 },
72 }
73 })
74 },
75 })
76}

Callers 2

UnsubscribeContentFunction · 0.90

Calls 1

requestJsonFunction · 0.90

Tested by

no test coverage detected