feat: reset verify states after completion
This commit is contained in:
@ -2,7 +2,7 @@ import { Button } from "@/components/ui/button";
|
|||||||
import Avatar from "@/feature/Avatar";
|
import Avatar from "@/feature/Avatar";
|
||||||
import { useAuth } from "@/store/auth";
|
import { useAuth } from "@/store/auth";
|
||||||
import { useVerify } from "@/store/verify";
|
import { useVerify } from "@/store/verify";
|
||||||
import type { FC } from "react";
|
import { type FC } from "react";
|
||||||
|
|
||||||
const VerifyReviewPage: FC = () => {
|
const VerifyReviewPage: FC = () => {
|
||||||
const profile = useAuth((s) => s.profile);
|
const profile = useAuth((s) => s.profile);
|
||||||
@ -38,7 +38,7 @@ const VerifyReviewPage: FC = () => {
|
|||||||
disabled={verifying}
|
disabled={verifying}
|
||||||
onClick={finishVerify}
|
onClick={finishVerify}
|
||||||
>
|
>
|
||||||
Back Home
|
Finish
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -13,28 +13,25 @@ export type VerifyStep = "email" | "avatar" | "review";
|
|||||||
|
|
||||||
export interface IVerifyState {
|
export interface IVerifyState {
|
||||||
step: VerifyStep | null | false;
|
step: VerifyStep | null | false;
|
||||||
|
|
||||||
redirect: string | null;
|
redirect: string | null;
|
||||||
|
|
||||||
loadStep: (profile: UserProfile) => void;
|
|
||||||
|
|
||||||
requesting: boolean;
|
requesting: boolean;
|
||||||
requested: boolean;
|
requested: boolean;
|
||||||
requestOTP: () => Promise<void>;
|
|
||||||
|
|
||||||
confirming: boolean;
|
confirming: boolean;
|
||||||
confirmOTP: (req: ConfirmEmailRequest) => Promise<void>;
|
|
||||||
|
|
||||||
uploading: boolean;
|
uploading: boolean;
|
||||||
uploadAvatar: (image: File) => Promise<void>;
|
|
||||||
|
|
||||||
verifying: boolean;
|
verifying: boolean;
|
||||||
verify: () => Promise<void>;
|
|
||||||
|
|
||||||
setRedirect: (redirect: string) => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useVerify = create<IVerifyState>((set) => ({
|
export interface IVerifyActions {
|
||||||
|
loadStep: (profile: UserProfile) => void;
|
||||||
|
requestOTP: () => Promise<void>;
|
||||||
|
confirmOTP: (req: ConfirmEmailRequest) => Promise<void>;
|
||||||
|
uploadAvatar: (image: File) => Promise<void>;
|
||||||
|
verify: () => Promise<void>;
|
||||||
|
setRedirect: (redirect: string) => void;
|
||||||
|
reset: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const initialState: IVerifyState = {
|
||||||
step: null,
|
step: null,
|
||||||
redirect: null,
|
redirect: null,
|
||||||
|
|
||||||
@ -43,6 +40,12 @@ export const useVerify = create<IVerifyState>((set) => ({
|
|||||||
confirming: false,
|
confirming: false,
|
||||||
uploading: false,
|
uploading: false,
|
||||||
verifying: false,
|
verifying: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useVerify = create<IVerifyState & IVerifyActions>((set, get) => ({
|
||||||
|
...initialState,
|
||||||
|
|
||||||
|
reset: () => set(initialState),
|
||||||
|
|
||||||
loadStep: (profile) => {
|
loadStep: (profile) => {
|
||||||
if (!profile.email_verified) {
|
if (!profile.email_verified) {
|
||||||
@ -116,6 +119,7 @@ export const useVerify = create<IVerifyState>((set) => ({
|
|||||||
console.log("ERR: Failed to finish verification:", err);
|
console.log("ERR: Failed to finish verification:", err);
|
||||||
} finally {
|
} finally {
|
||||||
set({ verifying: false });
|
set({ verifying: false });
|
||||||
|
get().reset();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
Reference in New Issue
Block a user