edit profile

This commit is contained in:
hamid zarghami
2026-07-25 10:59:52 +03:30
parent 52bb36ac3c
commit 42528f4d5c
9 changed files with 356 additions and 197 deletions
+31 -69
View File
@@ -1,14 +1,12 @@
import { FC, Fragment, useState } from 'react'
import { FC, Fragment, useEffect, useState } from 'react'
import Input from '../../../components/Input'
import { Edit, TickCircle } from 'iconsax-react'
import { Edit } from 'iconsax-react'
import { useTranslation } from 'react-i18next'
import Button from '../../../components/Button'
import { isEmail } from '../../../config/func'
import DefaulModal from '../../../components/DefaulModal'
import OTPInput from 'react-otp-input'
import { useUpdateEmail } from '../hooks/useProfileData'
import { ErrorType } from '../../../helpers/types'
import { toast } from '../../../components/Toast';
import { toast } from '../../../components/Toast'
type Props = {
email: string | null,
@@ -20,17 +18,20 @@ const Email: FC<Props> = (props: Props) => {
const { t } = useTranslation('global')
const [email, setEmail] = useState<string>(props.email ? props.email : '')
const [isReadOnly, setIsReadOnly] = useState<boolean>(true)
const [showModal, setShowModal] = useState<boolean>(false)
const [code, setCode] = useState<string>('')
const updateEmail = useUpdateEmail()
const handleShowModal = () => {
updateEmail.mutate({ email: email }, {
useEffect(() => {
setEmail(props.email ? props.email : '')
}, [props.email])
const handleSendVerification = () => {
updateEmail.mutate({ email }, {
onSuccess: () => {
toast(t('profile.link_email'), 'success')
setIsReadOnly(true)
},
onError: (error: ErrorType) => {
toast(error.response?.data?.error.message[0], 'error')
toast(error.response?.data?.error?.message?.[0], 'error')
}
})
}
@@ -45,17 +46,30 @@ const Email: FC<Props> = (props: Props) => {
onChange={(e) => setEmail(e.target.value)}
/>
{
!props.isVerified &&
!props.isVerified && isReadOnly &&
<div className='text-[10px] absolute left-24 text-red-400 top-[34px]'>
{t('profile.email_not_verified')}
</div>
}
{
isReadOnly ?
<div onClick={() => setIsReadOnly(false)} className='flex cursor-pointer relative -top-3 gap-1 text-[#0047FF] text-xs items-center'>
<Edit className='xl:size-[18px] size-4' color='#0047FF' />
<div>
{t('edit')}
<div className='flex items-center gap-3 relative -top-3'>
{
!props.isVerified && !!email &&
<button
type='button'
onClick={handleSendVerification}
disabled={updateEmail.isPending}
className='text-[#0047FF] text-xs whitespace-nowrap disabled:opacity-50'
>
{t('profile.resend_email')}
</button>
}
<div onClick={() => setIsReadOnly(false)} className='flex cursor-pointer gap-1 text-[#0047FF] text-xs items-center'>
<Edit className='xl:size-[18px] size-4' color='#0047FF' />
<div>
{t('edit')}
</div>
</div>
</div>
:
@@ -63,65 +77,13 @@ const Email: FC<Props> = (props: Props) => {
label={t('save')}
className='px-4 w-fit'
disabled={!isEmail(email)}
onClick={handleShowModal}
onClick={handleSendVerification}
isLoading={updateEmail.isPending}
/>
}
</div>
<DefaulModal
open={showModal}
close={() => setShowModal(false)}
isHeader
title_header={t('profile.confrim_email')}
>
<div className='mt-7'>
<div className='text-xs text-center'>
کد تایید به ایمیل {email} ارسال شده است.برای تایید کد مربوطه را وارد کنید.
</div>
<div className='mt-10'>کد تایید</div>
<div className='mt-2 w-full flex justify-center dltr otp'>
<OTPInput
value={code}
onChange={setCode}
shouldAutoFocus
renderInput={(props) =>
<input
{...props}
type='tel'
autoComplete="one-time-code"
inputMode="numeric"
className='w-full h-[50px] flex-1 mx-2 bg-white bg-opacity-30 border rounded-2.5' />
}
/>
</div>
<div className='mt-14 flex justify-end border-t border-border pt-8'>
<div className='flex gap-5'>
<Button
className='bg-white bg-opacity-40 text-description w-[150px] text-xs'
label='لغو'
onClick={() => setShowModal(false)}
/>
<Button
className='w-[150px] text-xs'
>
<div className='flex gap-2 items-center'>
<TickCircle
size={20}
color='white'
/>
<div>{t('wallet.submit_slip')}</div>
</div>
</Button>
</div>
</div>
</div>
</DefaulModal>
</Fragment>
)
}
export default Email
export default Email