({
children,
alerts = ALERT_DEFAULTS,
loadedAlerts,
isFetched,
updateAlerts,
}: AlertContextProviderProps)
| 54 | } |
| 55 | |
| 56 | export const AlertContextProvider = ({ |
| 57 | children, |
| 58 | alerts = ALERT_DEFAULTS, |
| 59 | loadedAlerts, |
| 60 | isFetched, |
| 61 | updateAlerts, |
| 62 | }: AlertContextProviderProps): ReactElement => { |
| 63 | const { mutateAsync: updateRemoteAlerts } = useMutation< |
| 64 | unknown, |
| 65 | unknown, |
| 66 | Alerts |
| 67 | >({ |
| 68 | mutationFn: (params) => |
| 69 | gqlClient.request(UPDATE_ALERTS, { |
| 70 | data: params, |
| 71 | }), |
| 72 | onMutate: (params) => updateAlerts({ ...alerts, ...params }), |
| 73 | |
| 74 | onError: (_, params) => { |
| 75 | const rollback = Object.keys(params).reduce( |
| 76 | (values, key) => ({ ...values, [key]: alerts[key] }), |
| 77 | {}, |
| 78 | ); |
| 79 | |
| 80 | updateAlerts({ ...alerts, ...rollback }); |
| 81 | }, |
| 82 | }); |
| 83 | |
| 84 | const { mutateAsync: updateLastReferralReminder } = useMutation({ |
| 85 | mutationFn: () => gqlClient.request(UPDATE_LAST_REFERRAL_REMINDER), |
| 86 | }); |
| 87 | |
| 88 | const { mutateAsync: updateLastBootPopup } = useMutation({ |
| 89 | mutationFn: () => gqlClient.request(UPDATE_LAST_BOOT_POPUP), |
| 90 | |
| 91 | onMutate: () => |
| 92 | updateAlerts({ |
| 93 | ...alerts, |
| 94 | lastBootPopup: new Date(), |
| 95 | bootPopup: false, |
| 96 | }), |
| 97 | |
| 98 | onError: () => { |
| 99 | updateAlerts({ |
| 100 | ...alerts, |
| 101 | lastBootPopup: null, |
| 102 | bootPopup: true, |
| 103 | }); |
| 104 | }, |
| 105 | }); |
| 106 | |
| 107 | const { mutateAsync: updateHasSeenOpportunity } = useMutation< |
| 108 | unknown, |
| 109 | unknown, |
| 110 | boolean | void |
| 111 | >({ |
| 112 | mutationFn: (hasSeenOpportunity = true) => |
| 113 | gqlClient.request(UPDATE_HAS_SEEN_OPPORTUNITY, { hasSeenOpportunity }), |
nothing calls this directly
no outgoing calls
no test coverage detected