Skip to content

Commit

Permalink
Merge pull request #595 from dappforce/improvement/event
Browse files Browse the repository at this point in the history
No finish login from effect after submit create profile
  • Loading branch information
olehmell authored Mar 13, 2024
2 parents 3d3a0e0 + c010e5d commit 4f7a17b
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/components/auth/LoginModal/CreateProfileModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useMyMainAddress } from '@/stores/my-account'
import { cx } from '@/utils/class-names'
import { encodeProfileSource } from '@/utils/profile'
import { zodResolver } from '@hookform/resolvers/zod'
import { useEffect, useState } from 'react'
import { useEffect, useRef, useState } from 'react'
import { Controller, useForm } from 'react-hook-form'
import { z } from 'zod'
import { finishLogin, getRedirectCallback } from './utils'
Expand All @@ -26,9 +26,10 @@ export default function CreateProfileModal({
const hasRedirectCallback = !!getRedirectCallback()
const myAddress = useMyMainAddress()
const { data: profile } = getProfileQuery.useQuery(myAddress ?? '')
const hasSubmitted = useRef(false)

useEffect(() => {
if (profile?.profileSpace?.id) {
if (profile?.profileSpace?.id && !hasSubmitted.current) {
finishLogin(props.closeModal)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand All @@ -47,6 +48,7 @@ export default function CreateProfileModal({
>
<CreateProfileForm
loadingUntilTxSuccess={hasRedirectCallback}
onSubmit={() => (hasSubmitted.current = true)}
onTxSuccess={
hasRedirectCallback
? () => {
Expand Down Expand Up @@ -76,10 +78,12 @@ const formSchema = z.object({
type FormSchema = z.infer<typeof formSchema>

function CreateProfileForm({
onSubmit,
onSuccessSent,
onTxSuccess,
loadingUntilTxSuccess,
}: {
onSubmit?: () => void
onSuccessSent?: () => void
onTxSuccess?: () => void
loadingUntilTxSuccess?: boolean
Expand Down Expand Up @@ -116,8 +120,9 @@ function CreateProfileForm({
}}
>
{({ mutateAsync, isLoading }) => {
const onSubmit = handleSubmit(async (data) => {
const handleCreateProfileSubmit = handleSubmit(async (data) => {
sendEvent('account_settings_changed', { profileSource: 'custom' })
onSubmit?.()
await mutateAsync({
content: {
name: data.name,
Expand All @@ -133,7 +138,10 @@ function CreateProfileForm({
})

return (
<form onSubmit={onSubmit} className={cx('flex flex-col gap-4')}>
<form
onSubmit={handleCreateProfileSubmit}
className={cx('flex flex-col gap-4')}
>
<div className='self-center'>
<Controller
control={control}
Expand Down

0 comments on commit 4f7a17b

Please sign in to comment.