-
-
- {totalDocs > 0 && (
-
+ {/* {listIsLoading && (
+
+
+
+ )} */}
+
+
+ {showAlert && (
+
setShowAlert(false)}
+ >
+ {deleteUserMessage}
+
)}
+
+
+
+
+
+ {totalDocs > 0 && (
+
+ )}
+ {totalDocs > 0 && (
+
+
setSearch(e.target.value)}
+ />
+
+
+ )}
+
{totalDocs > 0 && (
-
-
+
+
+
)}
-
- {totalDocs > 0 && (
-
-
-
-
-
- )}
- {totalDocs > 0 && (
-
-
-
+
-
-
-
setLimit(e.target.value)}
- >
- {totalDocs &&
- Array.from(Array(totalDocs > 100 ? 100 : totalDocs).keys()).map((day, index) => {
- return (
-
- );
- })}
-
+
+
+ setLimit(e.target.value)}
+ >
+ {totalDocs &&
+ Array.from(Array(totalDocs > 100 ? 100 : totalDocs).keys()).map((day, index) => {
+ return (
+
+ );
+ })}
+
+
-
- )}
+ )}
- {!users.length && (
-
- No User found
-
- )}
-
- {users &&
- users.map((user: any, index: number) => {
- return (
-
+ {users &&
+ users.map((user: any, index: number) => {
+ return (
+
-
-
First Name:
-
{user.firstName}
-
+ >
+
+
First Name:
+
{user.firstName}
+
-
-
Last Name:
-
{user.lastName}
-
+
+
Last Name:
+
{user.lastName}
+
-
-
Email:
-
{truncate(user.email, 20)}
-
+
+
Email:
+
{truncate(user.email, 20)}
+
-
-
Gender:
-
{user.gender}
-
+
+
Gender:
+
{user.gender}
+
-
+
-
-
Date Of Birth:
-
{user.dateOfBirth}
-
+
-
-
Created At:
-
- {' '}
- {moment(user.createdAt).format(format())}
-
-
+
+
Date Of Birth:
+
{user.dateOfBirth}
+
-
-
Updated At:
-
- {moment(user.updatedAt).format(format())}
-
-
+
+
Created At:
+
+ {' '}
+ {moment(user.createdAt).format(format())}
+
+
+
+
+
Updated At:
+
+ {moment(user.updatedAt).format(format())}
+
+
-
-
-
-
+
+
+
+
+
+
+
-
- );
- })}
+ );
+ })}
+
@@ -302,7 +347,8 @@ const mapStateToProps = (state: ReducerType) => {
};
const mapDispatchToProps = {
- getUsers
+ getUsers,
+ restDeleteUser
};
export default connect(
diff --git a/pages/change-password.tsx b/pages/change-password.tsx
deleted file mode 100644
index 648fb6f..0000000
--- a/pages/change-password.tsx
+++ /dev/null
@@ -1,23 +0,0 @@
-/** @format */
-
-import Head from "next/head";
-import React from "react";
-import { Fragment } from "react";
-import type { NextPage } from "next";
-
-import ChangePasswordPageComponent from "../components/change-password-page/change-password-page";
-
-const ChangePasswordScreen: NextPage = () => {
- return (
-
-
- Change Your Password
-
-
-
-
-
- );
-};
-
-export default ChangePasswordScreen;
diff --git a/pages/index.tsx b/pages/index.tsx
index b3f5d29..bce5069 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -1,11 +1,10 @@
-/** @format */
import Head from 'next/head';
import { GetServerSideProps } from 'next';
import type { NextPage } from 'next';
import Link from 'next/link';
import React from 'react';
-import { Card, CardBody, Button } from 'reactstrap';
+
import { truncate } from '../utils/functions/helpers';
diff --git a/pages/order.tsx b/pages/order.tsx
index fc34fe2..6551b05 100644
--- a/pages/order.tsx
+++ b/pages/order.tsx
@@ -1,23 +1,49 @@
-/** @format */
-
-import Head from "next/head";
-import React from "react";
-import { Fragment } from "react";
-import type { NextPage } from "next";
-
-import OrderPageComponent from "../components/order-page/order-page";
-
-const OrderPage: NextPage = () => {
- return (
-
-
- LogIn to the website
-
-
-
-
-
- );
+import { connect } from 'react-redux';
+import Head from 'next/head';
+import React, { useEffect } from 'react';
+import { Fragment } from 'react';
+
+import OrderPageComponent from '../components/order-page/order-page';
+import { ReducerType } from '../redux/reducers/rootReducer';
+import Login from './login';
+const OrderPage = (props: any) => {
+ const { isAuthenticated, isADmin } = props.auth;
+
+ useEffect(() => {
+ const redirectToLogin = () => {
+ if (!isAuthenticated) {
+ return
;
+ }
+ };
+
+ redirectToLogin();
+ }, [isAuthenticated]);
+
+ if (!isAuthenticated) {
+ return
;
+ }
+
+ return (
+
+
+ LogIn to the website
+
+
+
+
+
+ );
+};
+
+const mapStateToProps = (state: ReducerType) => {
+ return {
+ auth: state.auth
+ };
};
-export default OrderPage;
+const mapDispatchToProps = {};
+
+export default connect(
+ mapStateToProps,
+ mapDispatchToProps
+)(OrderPage);
diff --git a/pages/signup.tsx b/pages/signup.tsx
index 559f30b..0c763f9 100644
--- a/pages/signup.tsx
+++ b/pages/signup.tsx
@@ -1,4 +1,4 @@
-/** @format */
+
import Head from 'next/head';
import React from 'react';
diff --git a/redux/actions/adminActions.ts b/redux/actions/adminActions.ts
new file mode 100644
index 0000000..9fa3738
--- /dev/null
+++ b/redux/actions/adminActions.ts
@@ -0,0 +1,125 @@
+import {
+ USER_LIST_FAILER,
+ USER_LIST_SUCCESS,
+ USER_LIST_LOADING,
+ USER_POST_LOADING, USER_POST_SUCCESS,USER_POST_FAILER,USER_POST_REST,
+ USER_DELETE_FAILER,
+ USER_DELETE_SUCCESS,
+ USER_DELETE_LOADING,
+ USER_DELETE_REST,
+ GET_INDIVIDUAL_USER_LOADING,
+ GET_INDIVIDUAL_USER_SUCCESS,
+ GET_INDIVIDUAL_USER_FAILER,
+ GET_INDIVIDUAL_USER_REST,
+ USER_UPDATE_LOADING,
+ USER_UPDATE_SUCCESS,
+ USER_UPDATE_FAILER,
+ USER_UPDATE_REST,
+} from '../../constants/ActionTypes';
+
+import { UserType } from '../../types';
+import apiRequests from '../../utils/api';
+
+const getHostUrl = 'http://localhost:5000/api/v1';
+
+
+
+
+// Users
+export const getUsers = (payload: string) => async (dispatch: any) => {
+
+ dispatch({ type: USER_LIST_LOADING });
+ try {
+ const response = await apiRequests({
+ method: 'get',
+ url: `${getHostUrl}${payload}`,
+ });
+ dispatch({ type: USER_LIST_SUCCESS, payload: response });
+ } catch (error: any) {
+ dispatch({
+ type: USER_LIST_FAILER,
+ // eslint-disable-next-line prettier/prettier
+ payload: { error: error?.data?.message || error.statusText },
+ });
+ }
+};
+
+
+export const restUser = () => async (dispatch: any) => { dispatch({ type: USER_POST_REST }) }
+
+export const createUser = (user: UserType) => async (dispatch: any) => {
+ dispatch({ type: USER_POST_LOADING });
+ try {
+ const response = await apiRequests({
+ method: 'post',
+ url: `${getHostUrl}/admin/users`,
+ data: user,
+ });
+ dispatch({ type: USER_POST_SUCCESS, payload: response });
+ } catch (error: any) {
+ dispatch({
+ type: USER_POST_FAILER,
+ payload: { error: error?.data?.message || error.statusText },
+ });
+ }
+};
+
+
+export const deleteUser = (id: string) => async (dispatch: any) => {
+ dispatch({ type: USER_DELETE_LOADING });
+ try {
+ const response = await apiRequests({
+ method: 'delete',
+ url: `${getHostUrl}/admin/users/${id}`,
+ });
+ dispatch({ type: USER_DELETE_SUCCESS, payload: response });
+ } catch (error: any) {
+ dispatch({
+ type: USER_DELETE_FAILER,
+ payload: { error: error?.data?.message || error.statusText },
+ });
+ }
+};
+
+
+export const restDeleteUser = () => async (dispatch: any) => { dispatch({ type: USER_DELETE_REST }) }
+
+
+export const getIndividualUser = (id: string) => async (dispatch: any) => {
+ dispatch({ type: GET_INDIVIDUAL_USER_LOADING });
+ try {
+ const response = await apiRequests({
+ method: 'get',
+ url: `${getHostUrl}/admin/users/${id}`,
+ });
+ dispatch({ type: GET_INDIVIDUAL_USER_SUCCESS, payload: response });
+ } catch (error: any) {
+ dispatch({
+ type: GET_INDIVIDUAL_USER_FAILER,
+ payload: { error: error?.data?.message || error.statusText },
+ });
+ }
+};
+
+export const restGetIndividualUser = () => async (dispatch: any) => { dispatch({ type: GET_INDIVIDUAL_USER_REST }) }
+
+
+export const updateUser = (user: UserType, id:string) => async (dispatch: any) => {
+dispatch({ type: USER_UPDATE_LOADING });
+ try {
+ const response = await apiRequests({
+ method: 'patch',
+ url: `${getHostUrl}/admin/users/${id}`,
+ data: user,
+ });
+ dispatch({ type: USER_UPDATE_SUCCESS, payload: response });
+
+ } catch (error: any) {
+ dispatch({
+ type: USER_UPDATE_FAILER,
+ payload: { error: error?.data?.message || error.statusText },
+ });
+ }
+};
+
+export const restUpdateUser = () => async (dispatch: any) => { dispatch({ type: USER_UPDATE_REST }) }
\ No newline at end of file
diff --git a/redux/actions/authActions.ts b/redux/actions/authActions.ts
new file mode 100644
index 0000000..05d3b75
--- /dev/null
+++ b/redux/actions/authActions.ts
@@ -0,0 +1,151 @@
+import {
+ AUTH_SIGINUP_LOADING, AUTH_SIGINUP_SUCCESS, AUTH_SIGINUP_FAILER, AUTH_SIGINUP_REST,
+ AUTH_CONFIRM_EMAIL_LOADING,
+ AUTH_CONFIRM_EMAIL_SUCCESS,
+ AUTH_CONFIRM_EMAIL_FAILER,
+ AUTH_CONFIRM_EMAIL_REST,
+ AUTH_LOGIN_LOADING,
+ AUTH_LOGIN_SUCCESS,
+ AUTH_LOGIN_FAILER,
+ AUTH_LOGIN_REST,
+ USER_LIST_FAILER,
+ REMOVE_AUTHENTICATED_USER,
+ FORGET_PASSWORD_LOADING,
+ FORGET_PASSWORD_SUCCESS,
+ FORGET_PASSWORD_FAILER,
+ FORGET_PASSWORD_REST,
+ REST_PASSWORD_LOADING,REST_PASSWORD_SUCCESS, REST_PASSWORD_FAILER, REST_PASSWORD_REST
+} from '../../constants/ActionTypes';
+
+import { UserType,ResetPasswordType } from '../../types';
+
+import apiRequests from '../../utils/api';
+
+const getHostUrl = 'http://localhost:5000/api/v1';
+
+// AUTH
+
+export const signUp = (user: UserType) => async (dispatch: any) => {
+ dispatch({ type: AUTH_SIGINUP_LOADING });
+ try {
+ const response = await apiRequests({
+ method: 'post',
+ url: `${getHostUrl}/auth/signup`,
+ data: user,
+ });
+ dispatch({ type: AUTH_SIGINUP_SUCCESS, payload: response });
+ } catch (error: any) {
+ dispatch({
+ type:AUTH_SIGINUP_FAILER,
+ // eslint-disable-next-line prettier/prettier
+ payload: { error: error?.data?.message || error.statusText },
+ });
+ }
+};
+
+
+export const verifyEmail = (data:ResetPasswordType) => async (dispatch: any) => {
+ dispatch({ type: AUTH_CONFIRM_EMAIL_LOADING});
+ try {
+ const response = await apiRequests({
+ method: 'get',
+ url: `${getHostUrl}/auth/verify-email/${data.userId}/${data.token}`,
+ });
+ dispatch({ type: AUTH_CONFIRM_EMAIL_SUCCESS, payload: response });
+ } catch (error: any) {
+ dispatch({
+ type:AUTH_CONFIRM_EMAIL_FAILER,
+ // eslint-disable-next-line prettier/prettier
+ payload: { error: error?.data?.message || error.statusText },
+ });
+ }
+};
+
+
+export const LogIn = (user: UserType) => async (dispatch: any) => {
+ dispatch({ type: AUTH_LOGIN_LOADING });
+ try {
+ const response = await apiRequests({
+ method: 'post',
+ url: `${getHostUrl}/auth/login`,
+ data: user,
+ });
+ dispatch({ type: AUTH_LOGIN_SUCCESS, payload: response });
+ } catch (error: any) {
+ dispatch({
+ type: AUTH_LOGIN_FAILER,
+ payload: { error: error?.data?.message || error.statusText },
+ });
+ }
+};
+
+export const logOut = (payload: string) => async (dispatch: any) => {
+ dispatch({
+ type: USER_LIST_FAILER,
+ payload: "error",
+ });
+ }
+
+
+export const removeAuthenticatedUser = () => async (dispatch: any) => {
+ dispatch({
+ type: REMOVE_AUTHENTICATED_USER ,
+ });
+ }
+
+
+
+
+ export const forgetPassword = (email: UserType) => async (dispatch: any) => {
+
+ dispatch({ type: FORGET_PASSWORD_LOADING });
+ try {
+ const response = await apiRequests({
+ method: 'post',
+ url: `${getHostUrl}/auth/forget-password`,
+ data: email,
+ });
+ dispatch({ type: FORGET_PASSWORD_SUCCESS, payload: response });
+ } catch (error: any) {
+ dispatch({
+ type:FORGET_PASSWORD_FAILER,
+ // eslint-disable-next-line prettier/prettier
+ payload: { error: error?.data?.message || error.statusText },
+ });
+ }
+};
+
+
+
+
+export const restPassword = (data:ResetPasswordType) => async (dispatch: any) => {
+ dispatch({ type: REST_PASSWORD_LOADING });
+ try {
+ const response = await apiRequests({
+ method: 'post',
+ url: `${getHostUrl}/auth/reset-password/${data.userId}/${data.token}`,
+ data: data,
+ });
+ dispatch({ type: REST_PASSWORD_SUCCESS, payload: response });
+ } catch (error: any) {
+ dispatch({
+ type:REST_PASSWORD_FAILER,
+ // eslint-disable-next-line prettier/prettier
+ payload: { error: error?.data?.message || error.statusText },
+ });
+ }
+};
+
+
+
+export const restVerifyEmail = () => async (dispatch: any) => { dispatch({ type: AUTH_CONFIRM_EMAIL_REST }) }
+
+
+export const restPasswordRest = () => async (dispatch: any) => { dispatch({ type: REST_PASSWORD_REST }) }
+
+
+export const restforgetPassword = () => async (dispatch: any) => { dispatch({ type: FORGET_PASSWORD_REST }) }
+
+export const restLoginState = () => async (dispatch: any) => { dispatch({ type: AUTH_LOGIN_REST }) }
+
+export const restSignUpState = () => async (dispatch: any) => { dispatch({ type: AUTH_SIGINUP_REST }) }
diff --git a/redux/actions/index.ts b/redux/actions/index.ts
index 870acd7..2b48b30 100644
--- a/redux/actions/index.ts
+++ b/redux/actions/index.ts
@@ -1,122 +1,3 @@
-import {
- AUTH_LOADING,
- AUTH_FAILER,
- AUTH_SUCCESS,
- AUTH_LOGIN_LOADING,
- AUTH_LOGIN_SUCCESS,
- AUTH_LOGIN_FAILER,
- USER_LIST_FAILER,
- USER_LIST_SUCCESS,
- USER_LIST_LOADING,
- USER_POST_LOADING, USER_POST_SUCCESS,USER_POST_FAILER,USER_POST_REST,
- USER_DELETE_FAILER,
- USER_DELETE_SUCCESS,
- USER_DELETE_LOADING
-} from '../../constants/ActionTypes';
-
-import { UserType } from '../../types/user';
-import apiRequests from '../../utils/api';
-
-const getHostUrl = 'http://localhost:5000/api/v1';
-
-// AUTH
-export const signUp = (user: UserType) => async (dispatch: any) => {
- dispatch({ type: AUTH_LOADING });
- try {
- const response = await apiRequests({
- method: 'Post',
- url: `${getHostUrl}/users/signup`,
- data: user,
- });
- dispatch({ type: AUTH_SUCCESS, payload: response });
- } catch (error: any) {
- dispatch({
- type: AUTH_FAILER,
- payload: { error: error?.data?.message || error.statusText },
- });
- }
-};
-
-export const LogIn = (user: UserType) => async (dispatch: any) => {
- dispatch({ type: AUTH_LOGIN_LOADING });
- try {
- const response = await apiRequests({
- method: 'Post',
- url: `${getHostUrl}/users/login`,
- data: user,
- });
- dispatch({ type: AUTH_LOGIN_SUCCESS, payload: response });
- } catch (error: any) {
- dispatch({
- type: AUTH_LOGIN_FAILER,
- payload: { error: error?.data?.message || error.statusText },
- });
- }
-};
-
-export const logOut = (payload: string) => async (dispatch: any) => {
- dispatch({
- type: USER_LIST_FAILER,
- payload: "error",
- });
- }
-
-
-// Users
-export const getUsers = (payload: string) => async (dispatch: any) => {
-
- dispatch({ type: USER_LIST_LOADING });
- try {
- const response = await apiRequests({
- method: 'get',
- url: `${getHostUrl}${payload}`,
- });
- dispatch({ type: USER_LIST_SUCCESS, payload: response });
- } catch (error: any) {
- dispatch({
- type: USER_LIST_FAILER,
- payload: { error: error?.data?.message || error.statusText },
- });
- }
-};
-
-
-export const restUser = () => async (dispatch: any) => { dispatch({ type: USER_POST_REST }) }
-
-export const createUser = (user: UserType) => async (dispatch: any) => {
- dispatch({ type: USER_POST_LOADING });
- try {
- const response = await apiRequests({
- method: 'post',
- url: `${getHostUrl}/admin/users`,
- data: user,
- });
- dispatch({ type: USER_POST_SUCCESS, payload: response });
- } catch (error: any) {
- dispatch({
- type: USER_POST_FAILER,
- payload: { error: error?.data?.message || error.statusText },
- });
- }
-};
-
-
-
-export const deleteUser = (id: string) => async (dispatch: any) => {
- dispatch({ type: USER_DELETE_LOADING });
- try {
- const response = await apiRequests({
- method: 'delete',
- url: `${getHostUrl}/admin/users/${id}`,
- });
- dispatch({ type: USER_DELETE_SUCCESS, payload: response });
- } catch (error: any) {
- dispatch({
- type: USER_DELETE_FAILER,
- payload: { error: error?.data?.message || error.statusText },
- });
- }
-};
-
-
+export * from './authActions';
+export * from './adminActions';
diff --git a/redux/actions/users.ts b/redux/actions/users.ts
deleted file mode 100644
index f8aad1f..0000000
--- a/redux/actions/users.ts
+++ /dev/null
@@ -1,56 +0,0 @@
-import {
- AUTH_LOADING,
- AUTH_FAILER,
- AUTH_SUCCESS,
- AUTH_LOGIN_LOADING,
- AUTH_LOGIN_SUCCESS,
- AUTH_LOGIN_FAILER,
- IS_AUTH,
- USER_LIST_FAILER,
- USER_LIST_SUCCESS,
- USER_LIST_LOADING,
- USER_POST,
-} from '../../constants/ActionTypes';
-
-import { UserType } from '../../types/user';
-
-import apiRequests from '../../utils/api';
-
-const getHostUrl = 'http://localhost:5000/api/v1';
-
-// AUTH
-export const signUp = (user: UserType) => async (dispatch: any) => {
- dispatch({ type: AUTH_LOADING });
- try {
- const response = await apiRequests({
- method: 'Post',
- url: `${getHostUrl}/users/signup`,
- data: user,
- });
- dispatch({ type: AUTH_SUCCESS, payload: response });
- } catch (error: any) {
- dispatch({
- type: AUTH_FAILER,
- payload: { error: error?.data?.message || error.statusText },
- });
- }
-};
-
-export const LogIn = (user: UserType) => async (dispatch: any) => {
- dispatch({ type: AUTH_LOGIN_LOADING });
- try {
- const response = await apiRequests({
- method: 'Post',
- url: `${getHostUrl}/users/login`,
- data: user,
- });
- dispatch({ type: AUTH_LOGIN_SUCCESS, payload: response });
- } catch (error: any) {
- dispatch({
- type: AUTH_LOGIN_FAILER,
- payload: { error: error?.data?.message || error.statusText },
- });
- }
-};
-
-
diff --git a/redux/reducers/adminReducer.ts b/redux/reducers/adminReducer.ts
new file mode 100644
index 0000000..1108afb
--- /dev/null
+++ b/redux/reducers/adminReducer.ts
@@ -0,0 +1,239 @@
+import { AnyAction } from 'redux';
+
+import {
+ USER_LIST_FAILER,
+ USER_LIST_SUCCESS,
+ USER_LIST_LOADING,
+ USER_POST_LOADING,
+ USER_POST_SUCCESS,
+ USER_LIST_REST,
+ USER_POST_FAILER,
+ USER_POST_REST,
+ USER_DELETE_FAILER,
+ USER_DELETE_SUCCESS,
+ USER_DELETE_LOADING,
+ USER_DELETE_REST,
+ GET_INDIVIDUAL_USER_LOADING,
+ GET_INDIVIDUAL_USER_SUCCESS,
+ GET_INDIVIDUAL_USER_FAILER,
+ GET_INDIVIDUAL_USER_REST,
+ USER_UPDATE_LOADING,
+ USER_UPDATE_SUCCESS,
+ USER_UPDATE_FAILER,
+ USER_UPDATE_REST
+} from '../../constants/ActionTypes';
+
+const initialState = {
+ list: {},
+ listIsLoading: false,
+ listIsSuccess: false,
+ listIsError: false,
+ listMessage: '',
+ users: [],
+ totalDocs: 0,
+
+ postUserIsPending: false,
+ postUserIsSuccess: false,
+ postUserIsError: false,
+ postUserMessage: '',
+
+ deleteUseredUser: [],
+ deleteUserIsPending: false,
+ deleteUserIsSuccess: false,
+ deleteUserIsError: false,
+ deleteUserMessage: '',
+
+ individualUser: [],
+ getIndividualUserIsPending: false,
+ getIndividualUserIsSuccess: false,
+ getIndividualUserIsError: false,
+ getIndividualUserIsMessage: '',
+
+ updatedUser: [],
+ updateUserIsPending: false,
+ updateUserIsSuccess: false,
+ updateUserIsError: false,
+ updateUserMessage: ''
+};
+
+export default function actionReducer(state = initialState, action: AnyAction) {
+ switch (action.type) {
+ case USER_LIST_LOADING:
+ return {
+ ...state,
+ listIsLoading: true,
+ listIsSuccess: false,
+ listIsError: false,
+ listMessage: 'PENDING'
+ };
+ case USER_LIST_SUCCESS:
+ return {
+ ...state,
+ users: action.payload.data.users || [],
+ totalDocs: action.payload.data.totalDocs || 0,
+ list: action.payload || {},
+ listIsLoading: false,
+ listIsSuccess: true,
+ listIsError: false,
+ listMessage: action.payload.message || 'Success'
+ };
+ case USER_LIST_FAILER:
+ return {
+ ...state,
+ users: [],
+ list: {},
+ listIsLoading: false,
+ listIsSuccess: false,
+ listIsError: true,
+ listMessage: action.payload.message || action.payload.error || 'Error'
+ };
+ case USER_LIST_REST:
+ return {
+ ...state,
+ users: [],
+ list: {},
+ listIsLoading: false,
+ listIsSuccess: false,
+ listIsError: false,
+ listMessage: ''
+ };
+
+ case USER_POST_LOADING:
+ return {
+ ...state,
+ postUserIsPending: true,
+ postUserIsSuccess: false,
+ postUserIsError: false,
+ postUserMessage: 'PENDING'
+ };
+ case USER_POST_SUCCESS:
+ return {
+ ...state,
+ postUserIsPending: false,
+ postUserIsSuccess: true,
+ postUserIsError: false,
+ postUserMessage: action.payload.message || 'Success'
+ };
+ case USER_POST_FAILER:
+ return {
+ ...state,
+ postUserIsPending: false,
+ postUserIsSuccess: false,
+ postUserIsError: true,
+ postUserMessage: action.payload.message || action.payload.error || 'Error'
+ };
+ case USER_POST_REST:
+ return {
+ ...state,
+ postUserIsPending: false,
+ postUserIsSuccess: false,
+ postUserIsError: false,
+ postUserMessage: ''
+ };
+ case USER_DELETE_LOADING:
+ return {
+ ...state,
+ deleteUserIsPending: true,
+ deleteUserIsSuccess: false,
+ deleteUserIsError: false,
+ deleteUserMessage: 'PENDING'
+ };
+ case USER_DELETE_SUCCESS:
+ return {
+ ...state,
+ deleteUserIsPending: false,
+ deleteUserIsSuccess: true,
+ deleteUserIsError: false,
+ deleteUserMessage: action.payload.message || 'Success'
+ };
+ case USER_DELETE_FAILER:
+ return {
+ ...state,
+ deleteUserIsPending: false,
+ deleteUserIsSuccess: false,
+ deleteUserIsError: true,
+ deleteUserMessage: action.payload.message || action.payload.error || 'Error'
+ };
+ case USER_DELETE_REST:
+ return {
+ ...state,
+ deleteUserIsPending: false,
+ deleteUserIsSuccess: false,
+ deleteUserIsError: false,
+ deleteUserMessage: ''
+ };
+ case GET_INDIVIDUAL_USER_LOADING:
+ return {
+ ...state,
+ getIndividualUserIsLoading: true,
+ getIndividualUserIsSuccess: false,
+ getIndividualUserIsError: false,
+ getIndividualUserIsMessage: 'PENDING'
+ };
+ case GET_INDIVIDUAL_USER_SUCCESS:
+ return {
+ ...state,
+ individualUser: action.payload.data.user || [],
+ getIndividualUserIsLoading: false,
+ getIndividualUserIsSuccess: true,
+ getIndividualUserIsError: false,
+ getIndividualUserIsMessage: action.payload.message || 'Success'
+ };
+ case GET_INDIVIDUAL_USER_FAILER:
+ return {
+ ...state,
+ individualUser: [],
+ getIndividualUserIsLoading: false,
+ getIndividualUserIsSuccess: false,
+ getIndividualUserIsError: true,
+ getIndividualUserIsMessage: action.payload.message || action.payload.error || 'Error'
+ };
+ case GET_INDIVIDUAL_USER_REST:
+ return {
+ ...state,
+ individualUser: [],
+ getIndividualUserIsLoading: false,
+ getIndividualUserIsSuccess: false,
+ getIndividualUserIsError: false,
+ getIndividualUserIsMessage: ''
+ };
+ case USER_UPDATE_LOADING:
+ return {
+ ...state,
+ getIndividualUserIsLoading: true,
+ getIndividualUserIsSuccess: false,
+ getIndividualUserIsError: false,
+ getIndividualUserIsMessage: 'PENDING'
+ };
+ case USER_UPDATE_SUCCESS:
+ return {
+ ...state,
+ updatedUser: action.payload.data.users || [],
+ updateUserIsPending: false,
+ updateUserIsSuccess: true,
+ updateUserIsError: false,
+ updateUserMessage: action.payload.message || 'Success'
+ };
+ case USER_UPDATE_FAILER:
+ return {
+ ...state,
+ updatedUser: [],
+ updateUserIsPending: false,
+ updateUserIsSuccess: false,
+ updateUserIsError: true,
+ updateUserMessage: action.payload.message || action.payload.error || 'Error'
+ };
+ case USER_UPDATE_REST:
+ return {
+ ...state,
+ updatedUser: [],
+ updateUserIsPending: false,
+ updateUserIsSuccess: false,
+ updateUserIsError: false,
+ updateUserMessage: ''
+ };
+
+ default:
+ return state;
+ }
+}
diff --git a/redux/reducers/authReducer.ts b/redux/reducers/authReducer.ts
index 6b74fed..aff6e8a 100644
--- a/redux/reducers/authReducer.ts
+++ b/redux/reducers/authReducer.ts
@@ -1,65 +1,146 @@
import { AnyAction } from 'redux';
import {
- AUTH_LOADING,
- AUTH_FAILER,
- AUTH_SUCCESS,
+ IS_AUTHENTICATED_SUCCESS,
+ AUTH_SIGINUP_LOADING,
+ AUTH_SIGINUP_SUCCESS,
+ AUTH_SIGINUP_FAILER,
+ AUTH_SIGINUP_REST,
+ AUTH_CONFIRM_EMAIL_LOADING,
+ AUTH_CONFIRM_EMAIL_SUCCESS,
+ AUTH_CONFIRM_EMAIL_FAILER,
+ AUTH_CONFIRM_EMAIL_REST,
AUTH_LOGIN_LOADING,
AUTH_LOGIN_SUCCESS,
AUTH_LOGIN_FAILER,
- IS_AUTH,
-} from '../../constants/ActionTypes';
+ AUTH_LOGIN_REST,
+ REMOVE_AUTHENTICATED_USER,
+ FORGET_PASSWORD_LOADING,
+ FORGET_PASSWORD_SUCCESS,
+ FORGET_PASSWORD_FAILER,
+ FORGET_PASSWORD_REST,
+ REST_PASSWORD_LOADING,
+ REST_PASSWORD_SUCCESS,
+ REST_PASSWORD_FAILER,
+ REST_PASSWORD_REST
+} from '../../constants';
import { saveUserInLocalStorage } from '../../utils/functions/helpers';
+import { _authPrototypeReducerState as ReducerState } from '../../types';
-const initialState = {
+const initialState: ReducerState = {
loginUser: {},
loginUserIsLoading: false,
loginUserIsSuccess: false,
loginUserIsError: false,
loginMessage: '',
+ confirmEmailIsLoading: false,
+ confirmEmailIsSuccess: false,
+ confirmEmailIsError: false,
+ confirmEmailIsMessage: '',
+
signUpUser: {},
signUpUserIsLoading: false,
signUpUserIsSuccess: false,
signUpUserIsError: false,
signUpUserMessage: '',
- isAuth: false,
+ isAuthenticated: false,
+ isADmin: false,
+
+ forgetPasswordIsLoading: false,
+ forgetPasswordIsSuccess: false,
+ forgetPasswordIsError: false,
+ forgetPasswordMessage: '',
+
+ restPasswordIsLoading: false,
+ restPasswordIsSuccess: false,
+ restPasswordIsError: false,
+ restPasswordMessage: ''
};
export default function actionReducer(state = initialState, action: AnyAction) {
switch (action.type) {
- case IS_AUTH:
+ case IS_AUTHENTICATED_SUCCESS:
+ return {
+ ...state,
+ isAuthenticated: true
+ };
+ case REMOVE_AUTHENTICATED_USER:
return {
...state,
- isAuth: true,
+ isAuthenticated: false,
+ isADmin: false
};
- case AUTH_LOADING:
+ case AUTH_SIGINUP_LOADING:
return {
...state,
signUpUserIsLoading: true,
signUpUserIsSuccess: false,
signUpUserIsError: false,
- signUpUserMessage: 'PENDING',
+ signUpUserMessage: 'PENDING'
};
- case AUTH_SUCCESS:
+ case AUTH_SIGINUP_SUCCESS:
return {
...state,
signUpUser: action.payload || {},
signUpUserIsLoading: false,
signUpUserIsSuccess: true,
signUpUserIsError: false,
- signUpUserMessage: action.payload?.message || 'Success',
+ signUpUserMessage: action.payload.message || 'Success'
};
- case AUTH_FAILER:
+ case AUTH_SIGINUP_FAILER:
return {
...state,
signUpUser: {},
signUpUserIsLoading: false,
signUpUserIsSuccess: false,
signUpUserIsError: true,
- signUpUserMessage: action.payload?.message || action.payload?.error || 'Error',
+ signUpUserMessage: action.payload.message || action.payload.error || 'Error'
+ };
+
+ case AUTH_SIGINUP_REST:
+ return {
+ ...state,
+ signUpUser: {},
+ signUpUserIsLoading: false,
+ signUpUserIsSuccess: false,
+ signUpUserIsError: false,
+ signUpUserMessage: ''
+ };
+
+ case AUTH_CONFIRM_EMAIL_LOADING:
+ return {
+ ...state,
+ confirmEmailIsLoading: true,
+ confirmEmailIsSuccess: false,
+ confirmEmailIsError: false,
+ confirmEmailIsMessage: 'PENDING'
+ };
+ case AUTH_CONFIRM_EMAIL_SUCCESS:
+ return {
+ ...state,
+ confirmEmailIsLoading: false,
+ confirmEmailIsSuccess: true,
+ confirmEmailIsError: false,
+ confirmEmailIsMessage: action.payload.message || 'Success'
+ };
+ case AUTH_CONFIRM_EMAIL_FAILER:
+ return {
+ ...state,
+ confirmEmailIsLoading: false,
+ confirmEmailIsSuccess: false,
+ confirmEmailIsError: true,
+ confirmEmailIsMessage: action.payload.message || action.payload.error || 'Error'
+ };
+ case AUTH_CONFIRM_EMAIL_REST:
+ return {
+ ...state,
+ confirmEmailIsLoading: false,
+ confirmEmailIsSuccess: false,
+ confirmEmailIsError: false,
+ confirmEmailIsMessage: ''
};
case AUTH_LOGIN_LOADING:
@@ -68,18 +149,19 @@ export default function actionReducer(state = initialState, action: AnyAction) {
loginUserIsLoading: true,
loginUserIsSuccess: false,
loginUserIsError: false,
- loginMessage: 'PENDING',
+ loginMessage: 'PENDING'
};
case AUTH_LOGIN_SUCCESS:
- saveUserInLocalStorage(action.payload);
+ saveUserInLocalStorage(action.payload.data.user.token);
return {
...state,
- loginUser: action.payload || {},
+ isADmin: action.payload.data.user.role || false,
+ loginUser: action.payload.data || {},
loginUserIsLoading: false,
loginUserIsSuccess: true,
loginUserIsError: false,
- loginMessage: action.payload?.message || 'Success',
- isAuth: true,
+ loginMessage: action.payload.message || 'Success',
+ isAuthenticated: true
};
case AUTH_LOGIN_FAILER:
return {
@@ -88,7 +170,82 @@ export default function actionReducer(state = initialState, action: AnyAction) {
loginUserIsLoading: false,
loginUserIsSuccess: false,
loginUserIsError: true,
- loginMessage: action.payload?.message || action.payload?.error || 'Error',
+ loginMessage: action.payload.message || action.payload.error || 'Error'
+ };
+ case AUTH_LOGIN_REST:
+ return {
+ ...state,
+ loginUser: {},
+ loginUserIsLoading: false,
+ loginUserIsSuccess: false,
+ loginUserIsError: false,
+ loginMessage: ''
+ };
+
+ case FORGET_PASSWORD_LOADING:
+ return {
+ ...state,
+ forgetPasswordIsLoading: true,
+ forgetPasswordIsSuccess: false,
+ forgetPasswordIsError: false,
+ forgetPasswordMessage: 'PENDING'
+ };
+ case FORGET_PASSWORD_SUCCESS:
+ return {
+ ...state,
+ forgetPasswordIsLoading: false,
+ forgetPasswordIsSuccess: true,
+ forgetPasswordIsError: false,
+ forgetPasswordMessage: action.payload.message || 'Success'
+ };
+ case FORGET_PASSWORD_FAILER:
+ return {
+ ...state,
+ forgetPasswordIsLoading: false,
+ forgetPasswordIsSuccess: false,
+ forgetPasswordIsError: true,
+ forgetPasswordMessage: action.payload.message || action.payload.error || 'Error'
+ };
+ case FORGET_PASSWORD_REST:
+ return {
+ ...state,
+ forgetPasswordIsLoading: false,
+ forgetPasswordIsSuccess: false,
+ forgetPasswordIsError: false,
+ forgetPasswordMessage: ''
+ };
+
+ case REST_PASSWORD_LOADING:
+ return {
+ ...state,
+ restPasswordIsLoading: true,
+ restPasswordIsSuccess: false,
+ restPasswordIsError: false,
+ restPasswordMessage: 'PENDING'
+ };
+ case REST_PASSWORD_SUCCESS:
+ return {
+ ...state,
+ restPasswordIsLoading: false,
+ restPasswordIsSuccess: true,
+ restPasswordIsError: false,
+ restPasswordMessage: action.payload.message || 'Success'
+ };
+ case REST_PASSWORD_FAILER:
+ return {
+ ...state,
+ restPasswordIsLoading: false,
+ restPasswordIsSuccess: false,
+ restPasswordIsError: true,
+ restPasswordMessage: action.payload.message || action.payload.error || 'Error'
+ };
+ case REST_PASSWORD_REST:
+ return {
+ ...state,
+ restPasswordIsLoading: false,
+ restPasswordIsSuccess: false,
+ restPasswordIsError: false,
+ restPasswordMessage: ''
};
default:
diff --git a/redux/reducers/rootReducer.ts b/redux/reducers/rootReducer.ts
index 9dad1f1..41dad97 100644
--- a/redux/reducers/rootReducer.ts
+++ b/redux/reducers/rootReducer.ts
@@ -1,10 +1,10 @@
import { combineReducers } from 'redux';
-import userReducer from './usersReducer';
+import userReducer from './adminReducer';
import authReducer from './authReducer';
const rootReducer = combineReducers({
auth: authReducer,
- users: userReducer,
+ users: userReducer
});
export type ReducerType = ReturnType
;
diff --git a/redux/reducers/usersReducer.ts b/redux/reducers/usersReducer.ts
deleted file mode 100644
index 1d0ba63..0000000
--- a/redux/reducers/usersReducer.ts
+++ /dev/null
@@ -1,131 +0,0 @@
-import { AnyAction } from 'redux';
-
-import {
- USER_LIST_FAILER,
- USER_LIST_SUCCESS,
- USER_LIST_LOADING,
- USER_POST_LOADING,
- USER_POST_SUCCESS,
- USER_POST_FAILER,
- USER_POST_REST,
- USER_DELETE_FAILER,
- USER_DELETE_SUCCESS,
- USER_DELETE_LOADING
-} from '../../constants/ActionTypes';
-
-const initialState = {
- list: {},
- listIsLoading: false,
- listIsSuccess: false,
- listIsError: false,
- listMessage: '',
- users: [],
- totalDocs:0,
-
-
- postUserIsPending: false,
- postUserIsSuccess: false,
- postUserIsError: false,
- postUserMessage: '',
-
- deleteUserIsPending: false,
- deleteUserIsSuccess: false,
- deleteUserIsError: false,
- deleteUserMessage: ''
-};
-
-export default function actionReducer(state = initialState, action: AnyAction) {
- switch (action.type) {
- case USER_LIST_LOADING:
- return {
- ...state,
- listIsLoading: true,
- listIsSuccess: false,
- listIsError: false,
- listMessage: 'PENDING'
- };
- case USER_LIST_SUCCESS:
- return {
- ...state,
- users: action.payload?.data?.users || [],
- totalDocs:action.payload?.data?.totalDocs || 0,
- list: action.payload || {},
- listIsLoading: false,
- listIsSuccess: true,
- listIsError: false,
- listMessage: action.payload.message || 'Success'
- };
- case USER_LIST_FAILER:
- return {
- ...state,
- users: [],
- list: {},
- listIsLoading: false,
- listIsSuccess: false,
- listIsError: true,
- listMessage: action.payload.message || action.payload.error || 'Error'
- };
-
- case USER_POST_LOADING:
- return {
- ...state,
- postUserIsPending: true,
- postUserIsSuccess: false,
- postUserIsError: false,
- postUserMessage: 'PENDING'
- };
- case USER_POST_SUCCESS:
- return {
- ...state,
- postUserIsPending: false,
- postUserIsSuccess: true,
- postUserIsError: false,
- postUserMessage: action.payload.message || 'Success'
- };
- case USER_POST_FAILER:
- return {
- ...state,
- postUserIsPending: false,
- postUserIsSuccess: false,
- postUserIsError: true,
- postUserMessage: action.payload.message || action.payload.error || 'Error'
- };
-
- case USER_POST_REST:
- return {
- ...state,
- postUserIsPending: false,
- postUserIsSuccess: false,
- postUserIsError: false,
- postUserMessage: ''
- };
-
- case USER_DELETE_LOADING:
- return {
- ...state,
- deleteUserIsPending: true,
- deleteUserIsSuccess: false,
- deleteUserIsError: false,
- deleteUserMessage: 'PENDING'
- };
- case USER_DELETE_SUCCESS:
- return {
- ...state,
- deleteUserIsPending: false,
- deleteUserIsSuccess: true,
- deleteUserIsError: false,
- deleteUserMessage: action.payload.message || 'Success'
- };
- case USER_DELETE_FAILER:
- return {
- ...state,
-
- deleteUserIsPending: false,
- deleteUserIsSuccess: false,
- deleteUserIsError: true,
- deleteUserMessage: action.payload.message || 'Success'
- };
- default:
- return state;
- }
-}
diff --git a/redux/reducers/usersReducerTest.ts b/redux/reducers/usersReducerTest.ts
new file mode 100644
index 0000000..5e96143
--- /dev/null
+++ b/redux/reducers/usersReducerTest.ts
@@ -0,0 +1,223 @@
+import { AnyAction } from 'redux';
+
+import {
+ USER_LIST_FAILER,
+ USER_LIST_SUCCESS,
+ USER_LIST_LOADING,
+ USER_POST_LOADING,
+ USER_POST_SUCCESS,
+ USER_POST_FAILER,
+ USER_POST_REST,
+ USER_DELETE_FAILER,
+ USER_DELETE_SUCCESS,
+ USER_DELETE_LOADING,
+ USER_DELETE_REST,
+ GET_INDIVIDUAL_USER_LOADING,
+ GET_INDIVIDUAL_USER_SUCCESS,
+ GET_INDIVIDUAL_USER_FAILER,
+ GET_INDIVIDUAL_USER_REST,
+ USER_UPDATE_LOADING,
+ USER_UPDATE_SUCCESS,
+ USER_UPDATE_FAILER,
+ USER_UPDATE_REST
+} from '../../constants/ActionTypes';
+
+const initialState = {
+ list: {},
+ listIsLoading: false,
+ listIsSuccess: false,
+ listIsError: false,
+ listMessage: '',
+ users: [],
+ totalDocs: 0,
+
+ postUserIsPending: false,
+ postUserIsSuccess: false,
+ postUserIsError: false,
+ postUserMessage: '',
+
+ deleteUseredUser: [],
+ deleteUserIsPending: false,
+ deleteUserIsSuccess: false,
+ deleteUserIsError: false,
+ deleteUserMessage: '',
+
+ individualUser: [],
+ getIndividualUserIsPending: false,
+ getIndividualUserIsSuccess: false,
+ getIndividualUserIsError: false,
+ individualUserMessage: '',
+
+ updatedUser: [],
+ updateUserIsPending: false,
+ updateUserIsSuccess: false,
+ updateUserIsError: false
+};
+
+export default function actionReducer(state = initialState, action: AnyAction) {
+ switch (action.type) {
+ case USER_LIST_LOADING:
+ return {
+ ...state,
+ listIsLoading: true,
+ listIsSuccess: false,
+ listIsError: false,
+ listMessage: 'PENDING'
+ };
+ case USER_LIST_SUCCESS:
+ return {
+ ...state,
+ users: action.payload.data.users || [],
+ totalDocs: action.payload.data.totalDocs || 0,
+ list: action.payload || {},
+ listIsLoading: false,
+ listIsSuccess: true,
+ listIsError: false,
+ listMessage: action.payload.message || 'Success'
+ };
+ case USER_LIST_FAILER:
+ return {
+ ...state,
+ users: [],
+ list: {},
+ listIsLoading: false,
+ listIsSuccess: false,
+ listIsError: true,
+ listMessage: action.payload.message || action.payload.error || 'Error'
+ };
+
+ case USER_POST_LOADING:
+ return {
+ ...state,
+ postUserIsPending: true,
+ postUserIsSuccess: false,
+ postUserIsError: false,
+ postUserMessage: 'PENDING'
+ };
+ case USER_POST_SUCCESS:
+ return {
+ ...state,
+ postUserIsPending: false,
+ postUserIsSuccess: true,
+ postUserIsError: false,
+ postUserMessage: action.payload.message || 'Success'
+ };
+ case USER_POST_FAILER:
+ return {
+ ...state,
+ postUserIsPending: false,
+ postUserIsSuccess: false,
+ postUserIsError: true,
+ postUserMessage: action.payload.message || action.payload.error || 'Error'
+ };
+ case USER_POST_REST:
+ return {
+ ...state,
+ postUserIsPending: false,
+ postUserIsSuccess: false,
+ postUserIsError: false,
+ postUserMessage: ''
+ };
+ case USER_DELETE_LOADING:
+ return {
+ ...state,
+ deleteUserIsPending: true,
+ deleteUserIsSuccess: false,
+ deleteUserIsError: false,
+ deleteUserMessage: 'PENDING'
+ };
+ case USER_DELETE_SUCCESS:
+ return {
+ ...state,
+ deleteUserIsPending: false,
+ deleteUserIsSuccess: true,
+ deleteUserIsError: false,
+ deleteUserMessage: action.payload.message || 'Success'
+ };
+ case USER_DELETE_FAILER:
+ return {
+ ...state,
+ deleteUserIsPending: false,
+ deleteUserIsSuccess: false,
+ deleteUserIsError: true,
+ deleteUserMessage: action.payload.message || action.payload.error || 'Error'
+ };
+ case USER_DELETE_REST:
+ return {
+ ...state,
+ deleteUserIsPending: false,
+ deleteUserIsSuccess: false,
+ deleteUserIsError: false,
+ deleteUserMessage: ''
+ };
+ case GET_INDIVIDUAL_USER_LOADING:
+ return {
+ ...state,
+ getIndividualUserIsLoading: true,
+ getIndividualUserIsSuccess: false,
+ getIndividualUserIsError: false,
+ individualUserMessage: 'PENDING'
+ };
+ case GET_INDIVIDUAL_USER_SUCCESS:
+ return {
+ ...state,
+ individualUser: action.payload.data.user || [],
+ getIndividualUserIsLoading: false,
+ getIndividualUserIsSuccess: true,
+ getIndividualUserIsError: false,
+ individualUserMessage: action.payload.message || 'Success'
+ };
+ case GET_INDIVIDUAL_USER_FAILER:
+ return {
+ ...state,
+ individualUser: [],
+ getIndividualUserIsLoading: false,
+ getIndividualUserIsSuccess: false,
+ getIndividualUserIsError: true,
+ individualUserMessage: action.payload.message || action.payload.error || 'Error'
+ };
+ case GET_INDIVIDUAL_USER_REST:
+ return {
+ ...state,
+ getIndividualUserIsLoading: false,
+ getIndividualUserIsSuccess: false,
+ getIndividualUserIsError: false
+ };
+ case USER_UPDATE_LOADING:
+ return {
+ ...state,
+ getIndividualUserIsLoading: true,
+ getIndividualUserIsSuccess: false,
+ getIndividualUserIsError: false,
+ individualUserMessage: 'PENDING'
+ };
+ case USER_UPDATE_SUCCESS:
+ return {
+ ...state,
+ updatedUser: action.payload.data.user || [],
+ updateUserIsPending: false,
+ updateUserIsSuccess: true,
+ updateUserIsError: false,
+ individualUserMessage: action.payload.message || 'Success'
+ };
+ case USER_UPDATE_FAILER:
+ return {
+ ...state,
+ updatedUser: [],
+ updateUserIsPending: false,
+ updateUserIsSuccess: false,
+ updateUserIsError: true,
+ individualUserMessage: action.payload.message || action.payload.error || 'Error'
+ };
+ case USER_UPDATE_REST:
+ return {
+ ...state,
+ updatedUser: [],
+ updateUserIsPending: false,
+ updateUserIsSuccess: false,
+ updateUserIsError: false
+ };
+ default:
+ return state;
+ }
+}
diff --git a/redux/store/configureStore.ts b/redux/store/configureStore.ts
index 3605e67..cc8447f 100644
--- a/redux/store/configureStore.ts
+++ b/redux/store/configureStore.ts
@@ -14,9 +14,9 @@ declare global {
// Log only in development
// let middlewares =
-process.env.NODE_ENV === `development`
- ? [ReduxLoggerMiddleware, ReduxThunkMiddleware, ReduxPromiseMiddleware]
- : [ReduxThunkMiddleware, ReduxPromiseMiddleware];
+// process.env.NODE_ENV === `development`
+// ? [ReduxLoggerMiddleware, ReduxThunkMiddleware, ReduxPromiseMiddleware]
+// : [ReduxThunkMiddleware, ReduxPromiseMiddleware];
let middlewares = [ReduxThunkMiddleware];
@@ -27,6 +27,27 @@ const composeEnhancers =
const enhancer = composeEnhancers(applyMiddleware(...middlewares));
-const makeStore: MakeStore> = () => createStore(rootReducer, enhancer);
+const makeStore = ({ isServer }) => {
+ if (isServer) {
+ return createStore(rootReducer, enhancer);
+ } else {
+ //If it's on client side, create a store which will persist
+ const { persistStore, persistReducer, autoRehydrate } = require('redux-persist');
+ const storage = require('redux-persist/lib/storage').default;
+ const persistConfig = {
+ key: 'nextjs',
+ whitelist: ['auth', 'users', 'user'], // only counter will be persisted, add other reducers if needed
+ storage // if needed, use a safer storage
+ };
+
+ const persistedReducer = persistReducer(persistConfig, rootReducer); // Create a new reducer with our existing reducer
+
+ const store = createStore(persistedReducer, {}, ...middlewares); // Creating the store again
+
+ store.__persistor = persistStore(store); // This creates a persistor object & push that persisted object to .__persistor, so that we can avail the persistability feature
+
+ return store;
+ }
+};
export const wrapper = createWrapper(makeStore);
diff --git a/redux/store/configureStoreTem.js b/redux/store/configureStoreTem.js
new file mode 100644
index 0000000..93370c5
--- /dev/null
+++ b/redux/store/configureStoreTem.js
@@ -0,0 +1,41 @@
+import { createWrapper } from 'next-redux-wrapper';
+import { applyMiddleware, createStore } from 'redux';
+import logger from 'redux-logger';
+import thunkMiddleware from 'redux-thunk';
+import rootReducer from '../reducers/rootReducer';
+
+const bindMiddleware = middleware => {
+ if (process.env.NODE_ENV !== 'production') {
+ const { composeWithDevTools } = require('@redux-devtools/extension');
+ return composeWithDevTools(applyMiddleware(...middleware));
+ }
+ return applyMiddleware(...middleware);
+};
+
+const makeStore = ({ isServer }) => {
+ if (isServer) {
+ //If it's on server side, create a store
+ return createStore(rootReducer, bindMiddleware([thunkMiddleware, logger]));
+ } else {
+ //If it's on client side, create a store which will persist
+ const { persistStore, persistReducer, autoRehydrate } = require('redux-persist');
+ const storage = require('redux-persist/lib/storage').default;
+
+ const persistConfig = {
+ key: 'nextjs',
+ whitelist: ['auth'], // only auth will be persisted, add other reducers if needed
+ storage // if needed, use a safer storage
+ };
+
+ const persistedReducer = persistReducer(persistConfig, rootReducer); // Create a new reducer with our existing reducer
+
+ const store = createStore(persistedReducer, {}, bindMiddleware([thunkMiddleware, logger])); // Creating the store again
+
+ store.__persistor = persistStore(store); // This creates a persistor object & push that persisted object to .__persistor, so that we can avail the persistability feature
+
+ return store;
+ }
+};
+
+// Export the wrapper & wrap the pages/_app.js with this wrapper only
+export const wrapper = createWrapper(makeStore);
diff --git a/tsconfig.json b/tsconfig.json
index f7663f1..c40b9c2 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,7 +1,6 @@
{
- "compilerOptions": {
+ "compilerOptions": {
"target": "es5",
- "lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
@@ -13,8 +12,21 @@
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
- "jsx": "preserve"
- },
- "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "pages/admin/users-table.tsx", "redux/store/test.js", "components/pagination/pagination.js", "components/modal/modal.js"],
- "exclude": ["node_modules"]
+ "jsx": "preserve",
+ "baseUrl": ".",
+ "allowSyntheticDefaultImports": true,
+ "noUnusedLocals": true,
+ "noUnusedParameters": true,
+ "preserveConstEnums": true,
+ "removeComments": false,
+ "sourceMap": true,
+ "lib": [
+ "dom",
+ "dom.iterable",
+ "esnext"
+ ],
+ },
+ "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
+ "exclude": ["node_modules"]
+
}
diff --git a/types/auth.ts b/types/auth.ts
new file mode 100644
index 0000000..905b62b
--- /dev/null
+++ b/types/auth.ts
@@ -0,0 +1,58 @@
+export type UserType = {
+ firstName: string;
+ lastName: string;
+ email: string;
+ password: string;
+ confirmPassword: string;
+ role: string;
+ gender: string;
+ month: string;
+ day: number;
+ year: string;
+ acceptTerms: boolean;
+};
+
+export type forgetPasswordEmailType = {
+ email: string;
+};
+
+export type ResetPasswordType = {
+ email?: string;
+ password: string;
+ confirmPassword: string;
+ acceptTerms?: boolean;
+ userId?: string;
+ token?: string;
+};
+
+export interface _authPrototypeReducerState {
+ loginUser: any;
+ loginUserIsLoading: boolean;
+ loginUserIsSuccess: boolean;
+ loginUserIsError: boolean;
+ loginMessage: string;
+
+ confirmEmailIsLoading: boolean;
+ confirmEmailIsSuccess: boolean;
+ confirmEmailIsError: boolean;
+ confirmEmailIsMessage: string;
+
+ signUpUser: any;
+ signUpUserIsLoading: boolean;
+ signUpUserIsSuccess: boolean;
+ signUpUserIsError: boolean;
+ signUpUserMessage: string;
+
+ isAuthenticated: boolean;
+ isADmin: boolean;
+
+ forgetPasswordIsLoading: boolean;
+ forgetPasswordIsSuccess: boolean;
+ forgetPasswordIsError: boolean;
+ forgetPasswordMessage: string;
+
+ restPasswordIsLoading: boolean;
+ restPasswordIsSuccess: boolean;
+ restPasswordIsError: boolean;
+ restPasswordMessage: string;
+}
diff --git a/types/index.ts b/types/index.ts
new file mode 100644
index 0000000..269586e
--- /dev/null
+++ b/types/index.ts
@@ -0,0 +1 @@
+export * from './auth';
diff --git a/types/user.ts b/types/user.ts
deleted file mode 100644
index 0f7b007..0000000
--- a/types/user.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-export type UserType = {
- firstName: string;
- lastName: string;
- email: string;
- password: string;
- confirmPassword: string;
- role: string;
- gender: string;
- month: string;
- day: number;
- year: string;
- acceptTerms: boolean;
-};
diff --git a/utils/api/lib/axiosConfig.ts b/utils/api/lib/axiosConfig.ts
index 65f0b91..1ad35a6 100644
--- a/utils/api/lib/axiosConfig.ts
+++ b/utils/api/lib/axiosConfig.ts
@@ -1,10 +1,13 @@
import axios, { AxiosError, AxiosResponse, AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios';
-let AUTH_TOKEN;
+
+
+let AUTH_TOKEN:any;
if (typeof window !== 'undefined') {
- AUTH_TOKEN = 'Bearer ' + JSON.parse(localStorage.getItem('user'))?.token;
+ AUTH_TOKEN = 'Bearer ' + JSON.parse(localStorage.getItem('authToken'));
}
+
// default config that will be applied to every request.
axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
diff --git a/utils/functions/helpers.ts b/utils/functions/helpers.ts
index c22ef7f..5d369bf 100644
--- a/utils/functions/helpers.ts
+++ b/utils/functions/helpers.ts
@@ -1,4 +1,4 @@
-import { UserType } from '../../types/user';
+import { UserType } from '../../types/auth';
// function to truncate(cut) the string if the length of given string
// bigger than given number(n)
@@ -20,14 +20,14 @@ export function getYearsIntBetween(startYear = 1940) {
return years;
}
-export const saveUserInLocalStorage = (user: UserType) => {
- localStorage.setItem('user', JSON.stringify(user));
+export const format = () => {
+ return 'YYYY-MM-DD';
};
-export const removedUserFromLocalStorage = () => {
- localStorage.removeItem('user');
+export const saveUserInLocalStorage = (token: string) => {
+ localStorage.setItem('authToken', JSON.stringify(token));
};
-export const format = () => {
- return 'YYYY-MM-DD';
+export const removedUserFromLocalStorage = () => {
+ localStorage.removeItem('authToken');
};