You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

66 lines
2.0 KiB

import proxy from "../proxy";
import { toast } from "react-toastify";
const initialState = {
status: proxy.status(),
loading: false,
error: null,
list: null,
domains: [],
mothers: [],
profileStatus: false,
setDone: false,
};
export default function user(state = initialState, action) {
let { type, data } = action;
switch (type) {
case "user/login":
case "user/register":
case "user/switchRole":
case "public/sendOTP":
toast.success("کد به شماره شما ارسال گردید.");
return { ...state, loading: false, status: data.profile, error: null };
case "user/otp/login":
window.location = "https://dnvn.ir/";
toast.success("به دانوین خوش آمدید.");
return {
...state,
loading: false,
status: data.profile,
error: null,
};
case "user/getProfile":
localStorage.setItem("userData", JSON.stringify(data));
return {
...state,
loading: false,
status: data,
error: null,
setDone: false,
};
case "user/logout":
localStorage.removeItem("refresh");
localStorage.removeItem("access");
localStorage.removeItem("userData");
window.location = "https://dnvn.ir/";
return { ...state, loading: false, status: proxy.status(), error: null };
case "user/getUserRole":
return { ...state, loading: false, userRoles: data, error: null };
case "user/list":
return { ...state, loading: false, list: data, error: null };
case "user/domains":
return { ...state, loading: false, domains: data, error: null };
case "mothers/list":
return { ...state, loading: false, mothers: data, error: null };
case "user/setProfile":
return { ...state, loading: false, error: null, setDone: true };
case "user/loading":
return { ...state, loading: true };
case "user/error":
toast.error(data.message);
return { ...state, loading: false, error: data.message };
default:
return state;
}
}