✨
This commit is contained in:
47
src/store/signin/reducer.ts
Normal file
47
src/store/signin/reducer.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { type SignInState } from "./state";
|
||||
import { type SignInAction } from "./action";
|
||||
|
||||
export const initialState: SignInState = {
|
||||
isSubmiting: false,
|
||||
signInUser: {
|
||||
account: "",
|
||||
password: "",
|
||||
},
|
||||
signUpUser: {
|
||||
account: "",
|
||||
defaultRole: "Buyer",
|
||||
nickName: "",
|
||||
password: "",
|
||||
},
|
||||
};
|
||||
|
||||
export function signInReducer(
|
||||
state: SignInState,
|
||||
action: SignInAction,
|
||||
): SignInState {
|
||||
switch (action.type) {
|
||||
case "set_sign_in":
|
||||
return {
|
||||
...state,
|
||||
signInUser: {
|
||||
...state.signInUser,
|
||||
...action.payload?.signInUser,
|
||||
},
|
||||
};
|
||||
case "set_sign_up":
|
||||
return {
|
||||
...state,
|
||||
signUpUser: {
|
||||
...state.signUpUser,
|
||||
...action.payload?.signUpUser,
|
||||
},
|
||||
};
|
||||
case "set_is_submiting":
|
||||
return {
|
||||
...state,
|
||||
isSubmiting: action.payload?.isSubmiting ?? false,
|
||||
};
|
||||
default:
|
||||
throw Error(`wrong action type:${action.type}`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user