| | |
| | | const location = useLocation(); |
| | | const { systemInfo, tenantList } = props; |
| | | |
| | | const { control, handleSubmit, watch, setValue, getValues } = useForm(); |
| | | const { control, handleSubmit, watch, setValue, getValues, setError, clearErrors } = useForm(); |
| | | |
| | | const [loading, setLoading] = useState(false); |
| | | const [showPassword, setShowPassword] = useState(false); |
| | |
| | | login( |
| | | data, |
| | | location.state ? (location.state).nextPathname : '/' |
| | | ).catch((error) => { |
| | | ).catch((res) => { |
| | | setLoading(false); |
| | | notify( |
| | | typeof error === 'string' |
| | | ? error |
| | | : typeof error === 'undefined' || !error.message |
| | | ? 'ra.auth.sign_in_error' |
| | | : error.message, |
| | | { |
| | | type: 'error', |
| | | messageArgs: { |
| | | _: |
| | | typeof error === 'string' |
| | | ? error |
| | | : error && error.message |
| | | ? error.message |
| | | : undefined, |
| | | }, |
| | | } |
| | | ); |
| | | const { code, msg, data } = res; |
| | | if (code === 10003) { |
| | | setError('username', { |
| | | message: msg |
| | | }) |
| | | } else if (code === 10004) { |
| | | setError('username', { |
| | | message: msg |
| | | }) |
| | | } else if (code === 10001) { |
| | | setError('password', { |
| | | message: msg |
| | | }) |
| | | } else { |
| | | notify(msg, { type: 'error', messageArgs: { _: msg } }); |
| | | } |
| | | }); |
| | | }; |
| | | |
| | |
| | | component="form" onSubmit={handleSubmit(onSubmit)} noValidate |
| | | > |
| | | <Stack spacing={2}> |
| | | <Controller |
| | | {/* <Controller |
| | | name="tenantId" |
| | | control={control} |
| | | rules={{ required: true }} |
| | |
| | | /> |
| | | ); |
| | | }} |
| | | /> |
| | | /> */} |
| | | |
| | | <Controller |
| | | name="username" |
| | | control={control} |
| | | defaultValue="" |
| | | rules={{ required: true }} |
| | | render={({ field }) => ( |
| | | render={({ field, fieldState: { error } }) => ( |
| | | <TextField |
| | | {...field} |
| | | label={translate("page.login.username")} |
| | |
| | | disabled={loading} |
| | | autoFocus |
| | | autoComplete="off" |
| | | error={!!error} |
| | | helperText={error?.message || ""} |
| | | /> |
| | | )} |
| | | /> |
| | |
| | | control={control} |
| | | defaultValue="" |
| | | rules={{ required: true }} |
| | | render={({ field }) => ( |
| | | render={({ field, fieldState: { error } }) => ( |
| | | <TextField |
| | | {...field} |
| | | label={translate("page.login.password")} |
| | |
| | | variant="standard" |
| | | disabled={loading} |
| | | autoComplete="off" |
| | | error={!!error} |
| | | helperText={error?.message || ""} |
| | | InputProps={{ |
| | | endAdornment: ( |
| | | <InputAdornment position="end"> |
| | |
| | | <Button |
| | | type="submit" |
| | | variant="contained" |
| | | disabled={loading || !(tenantId && username && password)} |
| | | disabled={loading || !(true && username && password)} |
| | | sx={{ |
| | | // backgroundColor: "#3D4BA7" |
| | | }} |