From ae6057be8b45b6a0b93640521e9e7fde684d98c8 Mon Sep 17 00:00:00 2001 From: ilya Smiyukha Date: Sun, 13 Aug 2023 11:11:12 +0200 Subject: [PATCH] signup modal changes --- .../EmailSubscriptionModal.tsx | 24 +++++++------------ .../modals/EmailSubscriptionModal/machine.ts | 24 +++++++++---------- 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/packages/ui/src/memberships/modals/EmailSubscriptionModal/EmailSubscriptionModal.tsx b/packages/ui/src/memberships/modals/EmailSubscriptionModal/EmailSubscriptionModal.tsx index b13a3adb9f..384f475571 100644 --- a/packages/ui/src/memberships/modals/EmailSubscriptionModal/EmailSubscriptionModal.tsx +++ b/packages/ui/src/memberships/modals/EmailSubscriptionModal/EmailSubscriptionModal.tsx @@ -29,13 +29,7 @@ export const EmailSubscriptionModal = () => { const [, setMembersEmail] = useLocalStorage>('membersEmail') const { wallet } = useMyAccounts() const [state, send] = useMachine(EmailSubscriptionMachine) - const { - data, - error, - send: mutate, - } = useBackend({ - mutation: SIGNUP_MUTATION, - }) + const signupMutation = useBackend({ mutation: SIGNUP_MUTATION }) const signEmail = async () => { const timestamp = Date.now() @@ -54,12 +48,12 @@ export const EmailSubscriptionModal = () => { const signUp = async () => { if (state.event.type === 'SIGNED') { - await mutate({ + await signupMutation.send({ memberId: parseFloat(member.id), name: member.name, email: state.context.email, - signature: state.event.signature, - timestamp: state.event.timestamp, + signature: state.context.signature, + timestamp: state.context.timestamp, }) } } @@ -68,23 +62,23 @@ export const EmailSubscriptionModal = () => { if (state.matches('signature')) { signEmail() } - if (state.matches('transaction')) { + if (state.matches('signup')) { signUp() } }, [state]) useEffect(() => { - if (data) { + if (signupMutation.data) { send('SUCCESS') setMembersEmail((emails) => ({ ...emails, [member.id]: state.context.email || '' })) hideModal() } - if (error) { + if (signupMutation.error) { send('ERROR') } - }, [data, error]) + }, [signupMutation]) - if (state.matches('prepare')) { + if (state.matches('form')) { return ( } - | { value: 'transaction'; context: Context } + | { value: 'signup'; context: Context } | { value: 'success'; context: Context } | { value: 'error'; context: Context } @@ -26,9 +27,9 @@ export type EmailSubscriptionEvent = export const EmailSubscriptionMachine = createMachine, EmailSubscriptionEvent, EmailSubscriptionState>( { - initial: 'prepare', + initial: 'form', states: { - prepare: { + form: { on: { DONE: { target: 'signature', @@ -41,19 +42,18 @@ export const EmailSubscriptionMachine = createMachine, EmailSub signature: { on: { SIGNED: { - target: 'transaction', - actions: (_, event) => - assign({ - signature: event.signature, - timestamp: event.timestamp, - }), + target: 'signup', + actions: assign({ + signature: (_, event) => event.signature, + timestamp: (_, event) => event.timestamp, + }), }, CANCEL: { target: 'canceled', }, }, }, - transaction: { + signup: { on: { SUCCESS: { target: 'success', @@ -69,7 +69,7 @@ export const EmailSubscriptionMachine = createMachine, EmailSub }, cancel: { target: 'canceled', - action: 'prepare', + action: 'form', }, }), },