49 lines
1.0 KiB
TypeScript
49 lines
1.0 KiB
TypeScript
import { type SignInState } from "./state";
|
|
import { type SignInAction } from "./action";
|
|
import { UserRoles } from "../../api/models";
|
|
|
|
export const initialState: SignInState = {
|
|
isSubmiting: false,
|
|
signInUser: {
|
|
account: "",
|
|
password: "",
|
|
},
|
|
signUpUser: {
|
|
account: "",
|
|
defaultRole: UserRoles.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}`);
|
|
}
|
|
}
|