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.
 
 
 

73 lines
1.9 KiB

import proxy from "../proxy";
import { toast } from "react-toastify";
const initialState = {
status: {
name: 'کوروش',
lastName: 'زراندوز',
roles: [],
rolesString: [
{
id: 1,
roleName: 'پایه ششم',
},
{
id: 2,
roleName: 'مدیر',
},
]
},
loading: false,
error: null,
list: null,
domains: [],
mothers: [],
profileStatus: false,
setDone: false,
setLogin: 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":
return { ...state, loading: false, status: data.profile, error: null };
case "user/login":
case "user/otp/login":
if (data.profile.username == null) {
window.location.replace('/register')
}
return {
...state,
loading: false,
status: data.profile,
error: null,
setLogin: !state.setLogin,
};
case "user/getProfile":
localStorage.setItem("userData", JSON.stringify(data));
return { ...state, loading: false, status: data, error: null, setDone: false, };
case "user/logout":
window.location.reload()
return { ...state, loading: false, status: proxy.status(), error: null };
case "user/getUserRole":
return { ...state, loading: false, userRoles: data, error: null };
case "user/setProfile":
toast.success("تغییرات اعمال شد.");
return { ...state, loading: false, error: null, setDone: true };
case "loading":
return { ...state, loading: true };
case "error":
return { ...state, loading: false, error: data.message };
case 'SET_USER_STATUS':
return {...state, status: data};
default:
return state;
}
}