CreatePassword.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import Box from "@/components/layout/Box";
  2. import Buttons from "@/components/basic/Buttons";
  3. import Inputs from "@/components/input/Inputs";
  4. import Texts from "@/components/basic/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. import { ColorType } from "@/context/themes/color";
  15. import { registerSuccess } from "@/store/user";
  16. let useNavigation;
  17. if (process.env.TARO_ENV == 'rn') {
  18. useNavigation = require("@react-navigation/native").useNavigation
  19. }
  20. export default function Component(prop: { name?: string, email?: string }) {
  21. const { t } = useTranslation()
  22. const dispatch = useDispatch();
  23. const [password, setPassword] = useState('');
  24. const [repeat, setRepeat] = useState('');
  25. const handlePasswordChange = (value: string) => {
  26. setPassword(value);
  27. };
  28. const handleRepeatChange = (value: string) => {
  29. setRepeat(value);
  30. };
  31. const isButtonDisabled = password === '' || repeat === '';
  32. const user = useSelector((state: any) => state.user);
  33. let navigation;
  34. if (useNavigation) {
  35. navigation = useNavigation()
  36. }
  37. useEffect(() => {
  38. if (user.isLogin) {
  39. navigation.pop(3)
  40. return
  41. Taro.navigateBack({
  42. delta: 2
  43. })
  44. Taro.redirectTo({
  45. url: '/pages/clock/ChooseScenario'
  46. })
  47. }
  48. }, [user.isLogin])
  49. function loginComponent() {
  50. return <View>
  51. <Inputs value={password} isSecure={true} onChange={handlePasswordChange} onConfirm={(e) => { }} placeholder={t('feature.auth.create_password.input_password_placeholder')}></Inputs>
  52. <View style={{ height: 20 }} />
  53. <Inputs value={repeat} isSecure={true} onChange={handleRepeatChange} onConfirm={(e) => { }} placeholder={t('feature.auth.create_password.input_password_confirm_placeholder')}></Inputs>
  54. </View>
  55. }
  56. function registerF() {
  57. if (isButtonDisabled) {
  58. return;
  59. }
  60. register(
  61. global.username,
  62. global.email,
  63. password
  64. ).then(res => {
  65. dispatch(registerSuccess(res))
  66. }).catch(e => {
  67. console.log('oppsu')
  68. })
  69. }
  70. return <View style={{ backgroundColor: '#000', width: '100%', height: '100%' }}>
  71. <Texts text={t('feature.auth.create_password.title')} type={TextType.primary}></Texts>
  72. <Texts text={t('feature.auth.create_password.sub_title')} type={TextType.secondary}></Texts>
  73. {loginComponent()}
  74. <Buttons
  75. onClick={registerF}
  76. title={t('feature.auth.create_password.btn_next')}
  77. btnStyle={{ marginLeft: 23, marginRight: 23, marginTop: 20, marginBottom: 20, height: 44, borderRadius: 22, backgroundColor: ColorType.fast }}
  78. disabled={isButtonDisabled}
  79. ></Buttons>
  80. <View className="agree_view">
  81. <Image style='width:12px;height:12px;' src={check} />
  82. <Text className='agree_text'>{t('page.auth.agreement')}</Text>
  83. </View>
  84. <View style={{ flex: 1 }} />
  85. <View className="footer">
  86. <Text className="have_account">{t('feature.auth.create_password.footer_desc')}</Text>
  87. <Text className="login2">{t('feature.auth.create_password.footer_login')}</Text>
  88. </View>
  89. </View>
  90. }