|  |  |  | 
|---|
|  |  |  | const { code, msg, data } = res; | 
|---|
|  |  |  | if (code === 200) { | 
|---|
|  |  |  | notify(msg, { type: 'success', messageArgs: { _: msg } }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const timestamp = Math.floor(Date.now() / 1000); | 
|---|
|  |  |  | const expirationTime = timestamp + 60; | 
|---|
|  |  |  | localStorage.setItem('codeExpirationTime', expirationTime); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | setIsCounting(true); | 
|---|
|  |  |  | setCountdown(60); | 
|---|
|  |  |  | localStorage.setItem('codeCountdown', 60); | 
|---|
|  |  |  | } else if (code === 10005 || code === 10006) { | 
|---|
|  |  |  | setError('email', { | 
|---|
|  |  |  | message: msg | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | notify(msg, { type: 'error', messageArgs: { _: msg } }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // countdown | 
|---|
|  |  |  | useEffect(() => { | 
|---|
|  |  |  | const savedCountdown = localStorage.getItem('codeCountdown'); | 
|---|
|  |  |  | if (savedCountdown && !isCounting) { | 
|---|
|  |  |  | setCountdown(Number(savedCountdown)); | 
|---|
|  |  |  | setIsCounting(true); | 
|---|
|  |  |  | const codeExpirationTime = localStorage.getItem('codeExpirationTime'); | 
|---|
|  |  |  | if (codeExpirationTime) { | 
|---|
|  |  |  | const currentTimestamp = Math.floor(Date.now() / 1000); | 
|---|
|  |  |  | const remainingTime = codeExpirationTime - currentTimestamp; | 
|---|
|  |  |  | if (remainingTime > 0) { | 
|---|
|  |  |  | setCountdown(remainingTime); | 
|---|
|  |  |  | setIsCounting(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const interval = setInterval(() => { | 
|---|
|  |  |  | if (isCounting && countdown > 0) { | 
|---|
|  |  |  | setCountdown(prev => prev - 1); | 
|---|
|  |  |  | localStorage.setItem('codeCountdown', countdown - 1); | 
|---|
|  |  |  | } else if (countdown <= 0) { | 
|---|
|  |  |  | clearInterval(interval); | 
|---|
|  |  |  | setIsCounting(false); | 
|---|
|  |  |  | localStorage.removeItem('codeCountdown'); | 
|---|
|  |  |  | localStorage.removeItem('codeExpirationTime'); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }, 1000); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // register | 
|---|
|  |  |  | const onSubmit = (params) => { | 
|---|
|  |  |  | // console.log(params); | 
|---|
|  |  |  | setLoading(true); | 
|---|
|  |  |  | register(params).then(res => { | 
|---|
|  |  |  | setLoading(false); | 
|---|
|  |  |  | const { code, msg, data } = res; | 
|---|
|  |  |  | if (code === 200) { | 
|---|
|  |  |  | console.log(data); | 
|---|
|  |  |  | notify(msg, { type: 'success', messageArgs: { _: msg } }); | 
|---|
|  |  |  | // to login | 
|---|
|  |  |  | login( | 
|---|
|  |  |  | params, | 
|---|
|  |  |  | location.state ? (location.state).nextPathname : '/' | 
|---|
|  |  |  | ).catch(({ code, msg }) => { | 
|---|
|  |  |  | setLoading(false); | 
|---|
|  |  |  | notify(msg, { type: 'error', messageArgs: { _: msg } }); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } else if (code === 10002) { | 
|---|
|  |  |  | setError("username", { | 
|---|
|  |  |  | message: msg | 
|---|