|
|
@@ -0,0 +1,56 @@
|
|
|
+import { createSlice } from "@reduxjs/toolkit";
|
|
|
+
|
|
|
+export enum ResultType {
|
|
|
+ idle = 'idle',
|
|
|
+ ing = 'ing',
|
|
|
+ success = 'success',
|
|
|
+ fail = 'fail',
|
|
|
+ countdown = 'countdown'
|
|
|
+
|
|
|
+}
|
|
|
+interface ResultState {
|
|
|
+ title: string | null;
|
|
|
+ type: any | ResultType.idle;
|
|
|
+ seconds: number | 0;
|
|
|
+}
|
|
|
+
|
|
|
+const initialState: ResultState = {
|
|
|
+ title: null,
|
|
|
+ type: null,
|
|
|
+ seconds: 0
|
|
|
+}
|
|
|
+
|
|
|
+const resultSlice = createSlice({
|
|
|
+ name: 'user',
|
|
|
+ initialState,
|
|
|
+ reducers: {
|
|
|
+ checkStart(state) {
|
|
|
+ state.title = 'Success';
|
|
|
+ state.type = ResultType.ing;
|
|
|
+ },
|
|
|
+ checkSuccess(state) {
|
|
|
+ state.title = 'Success';
|
|
|
+ state.type = ResultType.success;
|
|
|
+ },
|
|
|
+ checkFail(state) {
|
|
|
+ state.title = 'Fail';
|
|
|
+ state.type = ResultType.fail;
|
|
|
+ },
|
|
|
+ checkCountdown(state, action) {
|
|
|
+ state.type = ResultType.countdown;
|
|
|
+ state.seconds = action.payload;
|
|
|
+ },
|
|
|
+ checkCountdownEnd(state) {
|
|
|
+ state.type = ResultType.idle;
|
|
|
+ state.seconds = 0;
|
|
|
+ },
|
|
|
+ resetStatus(state) {
|
|
|
+ state.type = ResultType.idle;
|
|
|
+ state.seconds = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+);
|
|
|
+
|
|
|
+export const { checkStart, checkSuccess, checkFail, checkCountdownEnd, checkCountdown, resetStatus } = resultSlice.actions;
|
|
|
+export default resultSlice.reducer;
|