CreatePassword.tsx 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import Box from "@/components/Box";
  2. import Buttons from "@/components/Buttons";
  3. import Inputs from "@/components/Inputs";
  4. import Texts from "@/components/Texts";
  5. import { ComponentStatus, TextType } from "@/utils/types";
  6. import { View, Image, Text } from "@tarojs/components";
  7. import { useEffect, useState } from "react";
  8. import { useTranslation } from "react-i18next";
  9. import { useDispatch, useSelector } from "react-redux";
  10. import check from '@assets/svg/check.svg'
  11. import './Auth.scss'
  12. import Taro from "@tarojs/taro";
  13. import { register } from "@/services/user";
  14. export default function Component(prop: { name: string, email: string }) {
  15. const { t } = useTranslation()
  16. const dispatch = useDispatch();
  17. const [password, setPassword] = useState('');
  18. const [repeat, setRepeat] = useState('');
  19. const handlePasswordChange = (value: string) => {
  20. setPassword(value);
  21. };
  22. const handleRepeatChange = (value: string) => {
  23. setRepeat(value);
  24. };
  25. const isButtonDisabled = password === '' || repeat === '';
  26. const user = useSelector((state: any) => state.user);
  27. useEffect(() => {
  28. if (user.isLogin) {
  29. Taro.navigateBack({
  30. delta: 2
  31. })
  32. Taro.redirectTo({
  33. url: '/pages/clock/ChooseScenario'
  34. })
  35. }
  36. }, [user.isLogin])
  37. function loginComponent() {
  38. return <View>
  39. <Inputs value={password} isSecure={true} onChange={handlePasswordChange} placeholder={t('feature.auth.create_password.input_password_placeholder')}></Inputs>
  40. <View style={{ height: 20 }} />
  41. <Inputs value={repeat} isSecure={true} onChange={handleRepeatChange} placeholder={t('feature.auth.create_password.input_password_confirm_placeholder')}></Inputs>
  42. </View>
  43. }
  44. function registerF() {
  45. if (isButtonDisabled) {
  46. return;
  47. }
  48. dispatch(register(
  49. global.username,
  50. global.email,
  51. password
  52. ) as any);
  53. }
  54. return <View style={{ backgroundColor: '#000', flex: 1, flexDirection: 'column', display: 'flex', width: '100vw', height: '100vh' }}>
  55. <Texts text={t('feature.auth.create_password.title')} type={TextType.primary}></Texts>
  56. <Texts text={t('feature.auth.create_password.sub_title')} type={TextType.secondary}></Texts>
  57. <Box children={loginComponent()}></Box>
  58. <Buttons
  59. onClick={registerF}
  60. title={t('feature.auth.create_password.btn_next')}
  61. style={{ marginLeft: 23, marginRight: 23, marginTop: 20, marginBottom: 20 }}
  62. status={isButtonDisabled ? ComponentStatus.disable : ComponentStatus.enable}></Buttons>
  63. <View className="agree_view">
  64. <Image style='width:12px;height:12px;' src={check} />
  65. <Text className='agree_text'>{t('page.auth.agreement')}</Text>
  66. </View>
  67. <View style={{ flex: 1 }} />
  68. <View className="footer">
  69. <Text className="have_account">{t('feature.auth.create_password.footer_desc')}</Text>
  70. <Text className="login">{t('feature.auth.create_password.footer_login')}</Text>
  71. </View>
  72. </View>
  73. }