Submit fix (#4978)
* Fix submit logic * Fix type * Align submit task creation 1:1 with callsites * blegh. `useThrottledValue` * make `useThrottledValue`'s time required --------- Co-authored-by: Hailey <me@haileyok.com>
This commit is contained in:
+21
-22
@@ -26,6 +26,11 @@ export enum SignupStep {
|
||||
CAPTCHA,
|
||||
}
|
||||
|
||||
type SubmitTask = {
|
||||
code: string | undefined
|
||||
mutableProcessed: boolean // OK to mutate assuming it's never read in render.
|
||||
}
|
||||
|
||||
export type SignupState = {
|
||||
hasPrev: boolean
|
||||
activeStep: SignupStep
|
||||
@@ -41,6 +46,8 @@ export type SignupState = {
|
||||
|
||||
error: string
|
||||
isLoading: boolean
|
||||
|
||||
pendingSubmit: null | SubmitTask
|
||||
}
|
||||
|
||||
export type SignupAction =
|
||||
@@ -58,6 +65,7 @@ export type SignupAction =
|
||||
| {type: 'setVerificationCode'; value: string}
|
||||
| {type: 'setError'; value: string}
|
||||
| {type: 'setIsLoading'; value: boolean}
|
||||
| {type: 'submit'; task: SubmitTask}
|
||||
|
||||
export const initialState: SignupState = {
|
||||
hasPrev: false,
|
||||
@@ -74,6 +82,8 @@ export const initialState: SignupState = {
|
||||
|
||||
error: '',
|
||||
isLoading: false,
|
||||
|
||||
pendingSubmit: null,
|
||||
}
|
||||
|
||||
export function is13(date: Date) {
|
||||
@@ -149,6 +159,10 @@ export function reducer(s: SignupState, a: SignupAction): SignupState {
|
||||
next.error = a.value
|
||||
break
|
||||
}
|
||||
case 'submit': {
|
||||
next.pendingSubmit = a.task
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
next.hasPrev = next.activeStep !== SignupStep.INFO
|
||||
@@ -169,19 +183,17 @@ interface IContext {
|
||||
export const SignupContext = React.createContext<IContext>({} as IContext)
|
||||
export const useSignupContext = () => React.useContext(SignupContext)
|
||||
|
||||
export function useSubmitSignup({
|
||||
state,
|
||||
dispatch,
|
||||
}: {
|
||||
state: SignupState
|
||||
dispatch: (action: SignupAction) => void
|
||||
}) {
|
||||
export function useSubmitSignup() {
|
||||
const {_} = useLingui()
|
||||
const {createAccount} = useSessionApi()
|
||||
const onboardingDispatch = useOnboardingDispatch()
|
||||
|
||||
return useCallback(
|
||||
async (verificationCode?: string) => {
|
||||
async (
|
||||
state: SignupState,
|
||||
dispatch: (action: SignupAction) => void,
|
||||
verificationCode?: string,
|
||||
) => {
|
||||
if (!state.email) {
|
||||
dispatch({type: 'setStep', value: SignupStep.INFO})
|
||||
return dispatch({
|
||||
@@ -270,19 +282,6 @@ export function useSubmitSignup({
|
||||
dispatch({type: 'setIsLoading', value: false})
|
||||
}
|
||||
},
|
||||
[
|
||||
state.email,
|
||||
state.password,
|
||||
state.handle,
|
||||
state.serviceDescription?.phoneVerificationRequired,
|
||||
state.serviceUrl,
|
||||
state.userDomain,
|
||||
state.inviteCode,
|
||||
state.dateOfBirth,
|
||||
dispatch,
|
||||
_,
|
||||
onboardingDispatch,
|
||||
createAccount,
|
||||
],
|
||||
[_, onboardingDispatch, createAccount],
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user