- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 686
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): support binding email (#1418)
* feat(web): support binding email
1 parent
ea07b91
commit ce871fa
Showing
18 changed files
with
441 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { useState } from "react"; | ||
import { Button } from "@chakra-ui/react"; | ||
import clsx from "clsx"; | ||
import { t } from "i18next"; | ||
|
||
import { useSendEmailCodeMutation } from "@/pages/auth/service"; | ||
import useGlobalStore from "@/pages/globalStore"; | ||
|
||
export function SendEmailCodeButton(props: { | ||
getEmail: any; | ||
className?: string; | ||
emailAccount?: string; | ||
type: string; | ||
}) { | ||
const { getEmail, className, emailAccount, type } = props; | ||
const [isSendSmsCode, setIsSendSmsCode] = useState(false); | ||
const [countdown, setCountdown] = useState(60); | ||
const sendSmsCodeMutation = useSendEmailCodeMutation(); | ||
|
||
const { showSuccess, showError } = useGlobalStore(); | ||
|
||
const handleSendSmsCode = async () => { | ||
const email = getEmail(emailAccount); | ||
|
||
if (isSendSmsCode) { | ||
return; | ||
} | ||
|
||
const isValidate = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(email); | ||
if (!isValidate) { | ||
showError(t("AuthPanel.EmailTip")); | ||
return; | ||
} | ||
|
||
setIsSendSmsCode(true); | ||
setCountdown(60); | ||
const timer = setInterval(() => { | ||
setCountdown((countdown) => { | ||
if (countdown === 0) { | ||
clearInterval(timer); | ||
setIsSendSmsCode(false); | ||
return 0; | ||
} | ||
return countdown - 1; | ||
}); | ||
}, 1000); | ||
|
||
const res = await sendSmsCodeMutation.mutateAsync({ | ||
email, | ||
type, | ||
}); | ||
|
||
if (res?.data) { | ||
showSuccess(t("AuthPanel.SmsCodeSendSuccess")); | ||
} | ||
}; | ||
|
||
return ( | ||
<Button | ||
className={clsx("w-20", className)} | ||
variant={isSendSmsCode ? "thirdly_disabled" : "thirdly"} | ||
onClick={handleSendSmsCode} | ||
> | ||
{isSendSmsCode ? `${countdown}s` : t("AuthPanel.getValidationCode")} | ||
</Button> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.