├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt └── src ├── App.css ├── App.js ├── App.test.js ├── api ├── passwordApi.js ├── ticketApi.js └── userApi.js ├── assets ├── data │ └── dummy-tickets.json └── img │ └── logo.png ├── components ├── add-ticket-form │ ├── AddTicketForm.comp.js │ ├── add-ticket-form.style.css │ ├── addTicketAction.js │ └── addTicketSlicer.js ├── breadcrumb │ └── Breadcrumb.comp.js ├── login │ ├── Login.comp.js │ └── loginSlice.js ├── message-history │ ├── MessageHistory.comp.js │ └── message-history.style.css ├── password-reset │ ├── PasswordReset.comp.js │ ├── UpdatePasswordForm.comp.js │ ├── passwordAction.js │ └── passwordSlice.js ├── private-route │ └── PrivateRoute.comp.js ├── registration-form │ ├── RegistrationForm.comp.js │ ├── userRegAction.js │ └── userRegestrationSlice.js ├── search-form │ └── SearchForm.comp.js ├── ticket-table │ └── TicketTable.comp.js └── update-ticket │ └── UpdateTicket.comp.js ├── index.css ├── index.js ├── layout ├── DefaultLayout.js └── partials │ ├── Footer.comp.js │ └── Header.comp.js ├── pages ├── dashboard │ ├── Dashboard.page.js │ ├── userAction.js │ └── userSlice.js ├── entry │ ├── Entry.page.js │ └── entry.style.css ├── new-ticket │ └── AddTicket.page.js ├── password-reset │ ├── PasswordOtpForm.page.js │ └── passwordOtpForm.style.css ├── registration │ ├── Registration.page.js │ └── registration.style.css ├── ticket-list │ ├── TicketLists.page.js │ ├── ticketsAction.js │ └── ticketsSlice.js ├── ticket │ └── Ticket.page.js └── user-verification │ ├── UserVerification.page.js │ └── userVerification.style.css ├── serviceWorker.js ├── setupTests.js ├── store.js └── utils └── validation.js /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This project is part of a YouTube tutorial Create CRM ticket system with MERN stack from scratch to deploy to AWS 2 | Here is the playlist https://youtube.com/playlist?list=PLtPNAX49WUFN8yq2vEuAY6AhM5EJOXQQ0 3 | 4 | ### Start project 5 | 6 | `npm start` 7 | 8 | If you need code before adding Redux in the project , clone from before-redux/toolkit 9 | 10 | `git clone -b before-redux/toolkit git@github.com:DentedCode/crm-frontend.git` 11 | 12 | ### Backend API 13 | 14 | Backend api for this app is in the following repo: 15 | `https://github.com/DentedCode/client-api` 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "crm-frontend", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@reduxjs/toolkit": "^1.5.0", 7 | "@testing-library/jest-dom": "^4.2.4", 8 | "@testing-library/react": "^9.5.0", 9 | "@testing-library/user-event": "^7.2.1", 10 | "axios": "^0.21.0", 11 | "bootstrap": "^4.5.2", 12 | "prop-types": "^15.7.2", 13 | "react": "^16.13.1", 14 | "react-bootstrap": "^1.3.0", 15 | "react-dom": "^16.13.1", 16 | "react-redux": "^7.2.2", 17 | "react-router-bootstrap": "^0.25.0", 18 | "react-router-dom": "^5.2.0", 19 | "react-scripts": "3.4.3" 20 | }, 21 | "scripts": { 22 | "start": "react-scripts start", 23 | "build": "react-scripts build", 24 | "test": "react-scripts test", 25 | "eject": "react-scripts eject" 26 | }, 27 | "eslintConfig": { 28 | "extends": "react-app" 29 | }, 30 | "browserslist": { 31 | "production": [ 32 | ">0.2%", 33 | "not dead", 34 | "not op_mini all" 35 | ], 36 | "development": [ 37 | "last 1 chrome version", 38 | "last 1 firefox version", 39 | "last 1 safari version" 40 | ] 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DentedCode/crm-frontend/f759f98e2a6cc1a6bc31c1c598ae9f182a9cec5a/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DentedCode/crm-frontend/f759f98e2a6cc1a6bc31c1c598ae9f182a9cec5a/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DentedCode/crm-frontend/f759f98e2a6cc1a6bc31c1c598ae9f182a9cec5a/public/logo512.png -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/App.css: -------------------------------------------------------------------------------- 1 | .default-layout { 2 | display: gird; 3 | grid-template-rows: 80px auto 3rem; 4 | grid-template-areas: 5 | "header" 6 | "main" 7 | "footer"; 8 | } 9 | 10 | header { 11 | grid-area: header; 12 | } 13 | 14 | main { 15 | grid-area: main; 16 | min-height: 88vh; 17 | } 18 | 19 | footer { 20 | grid-area: footer; 21 | background: black; 22 | padding: 1rem; 23 | color: white; 24 | } 25 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { BrowserRouter as Router, Switch, Route } from "react-router-dom"; 3 | 4 | import "./App.css"; 5 | import { PrivateRoute } from "./components/private-route/PrivateRoute.comp"; 6 | import { DefaultLayout } from "./layout/DefaultLayout"; 7 | import { Dashboard } from "./pages/dashboard/Dashboard.page"; 8 | import { UserVerification } from "./pages/user-verification/UserVerification.page"; 9 | import { Entry } from "./pages/entry/Entry.page"; 10 | import { PasswordOtpForm } from "./pages/password-reset/PasswordOtpForm.page"; 11 | import { Registration } from "./pages/registration/Registration.page"; 12 | import { AddTicket } from "./pages/new-ticket/AddTicket.page"; 13 | import { TicketLists } from "./pages/ticket-list/TicketLists.page"; 14 | import { Ticket } from "./pages/ticket/Ticket.page"; 15 | 16 | function App() { 17 | return ( 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 |

404 Page not found

49 |
50 |
51 |
52 |
53 | ); 54 | } 55 | 56 | export default App; 57 | -------------------------------------------------------------------------------- /src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render } from '@testing-library/react'; 3 | import App from './App'; 4 | 5 | test('renders learn react link', () => { 6 | const { getByText } = render(); 7 | const linkElement = getByText(/learn react/i); 8 | expect(linkElement).toBeInTheDocument(); 9 | }); 10 | -------------------------------------------------------------------------------- /src/api/passwordApi.js: -------------------------------------------------------------------------------- 1 | import axios from "axios"; 2 | 3 | const rootUrl = "http://localhost:3001/v1/"; 4 | const otpReqUrl = rootUrl + "user/reset-password"; 5 | const updatePassUrl = rootUrl + "user/reset-password"; 6 | 7 | export const reqPasswordOtp = email => { 8 | return new Promise(async (resolve, reject) => { 9 | try { 10 | const { data } = await axios.post(otpReqUrl, { email }); 11 | 12 | console.log(data); 13 | resolve(data); 14 | } catch (error) { 15 | reject(error); 16 | } 17 | }); 18 | }; 19 | 20 | export const updateUserPassword = passObj => { 21 | return new Promise(async (resolve, reject) => { 22 | try { 23 | const { data } = await axios.patch(updatePassUrl, passObj); 24 | 25 | console.log(data); 26 | resolve(data); 27 | } catch (error) { 28 | reject(error); 29 | } 30 | }); 31 | }; 32 | -------------------------------------------------------------------------------- /src/api/ticketApi.js: -------------------------------------------------------------------------------- 1 | import axios from "axios"; 2 | 3 | const rootUrl = "http://localhost:3001/v1/"; 4 | const ticketUlr = rootUrl + "ticket/"; 5 | const closeTicketUrl = rootUrl + "ticket/close-ticket/"; 6 | 7 | export const getAllTickets = () => { 8 | return new Promise(async (resolve, reject) => { 9 | try { 10 | const result = await axios.get("http://localhost:3001/v1/ticket", { 11 | headers: { 12 | Authorization: sessionStorage.getItem("accessJWT"), 13 | }, 14 | }); 15 | 16 | resolve(result); 17 | } catch (error) { 18 | reject(error); 19 | } 20 | }); 21 | }; 22 | 23 | export const getSingleTicket = (_id) => { 24 | return new Promise(async (resolve, reject) => { 25 | try { 26 | const result = await axios.get(ticketUlr + _id, { 27 | headers: { 28 | Authorization: sessionStorage.getItem("accessJWT"), 29 | }, 30 | }); 31 | 32 | resolve(result); 33 | } catch (error) { 34 | console.log(error.message); 35 | reject(error); 36 | } 37 | }); 38 | }; 39 | 40 | export const updateReplyTicket = (_id, msgObj) => { 41 | return new Promise(async (resolve, reject) => { 42 | try { 43 | const result = await axios.put(ticketUlr + _id, msgObj, { 44 | headers: { 45 | Authorization: sessionStorage.getItem("accessJWT"), 46 | }, 47 | }); 48 | 49 | resolve(result.data); 50 | } catch (error) { 51 | console.log(error.message); 52 | reject(error); 53 | } 54 | }); 55 | }; 56 | 57 | export const updateTicketStatusClosed = (_id) => { 58 | return new Promise(async (resolve, reject) => { 59 | try { 60 | const result = await axios.patch( 61 | closeTicketUrl + _id, 62 | {}, 63 | { 64 | headers: { 65 | Authorization: sessionStorage.getItem("accessJWT"), 66 | }, 67 | } 68 | ); 69 | 70 | resolve(result.data); 71 | } catch (error) { 72 | console.log(error.message); 73 | reject(error); 74 | } 75 | }); 76 | }; 77 | 78 | export const createNewTicket = (frmData) => { 79 | console.log("from api", frmData); 80 | return new Promise(async (resolve, reject) => { 81 | try { 82 | const result = await axios.post(ticketUlr, frmData, { 83 | headers: { 84 | Authorization: sessionStorage.getItem("accessJWT"), 85 | }, 86 | }); 87 | 88 | resolve(result.data); 89 | } catch (error) { 90 | console.log(error.message); 91 | reject(error); 92 | } 93 | }); 94 | }; 95 | -------------------------------------------------------------------------------- /src/api/userApi.js: -------------------------------------------------------------------------------- 1 | import axios from "axios"; 2 | 3 | const rootUrl = "http://localhost:3001/v1/"; 4 | const loginUrl = rootUrl + "user/login"; 5 | const userProfileUrl = rootUrl + "user"; 6 | const logoutUrl = rootUrl + "user/logout"; 7 | const newAccessJWT = rootUrl + "tokens"; 8 | const userVerificationUrl = userProfileUrl + "/verify"; 9 | 10 | export const userRegistration = (frmData) => { 11 | return new Promise(async (resolve, reject) => { 12 | try { 13 | const res = await axios.post(userProfileUrl, frmData); 14 | 15 | resolve(res.data); 16 | 17 | if (res.data.status === "success") { 18 | resolve(res.data); 19 | } 20 | } catch (error) { 21 | reject(error); 22 | } 23 | }); 24 | }; 25 | export const userRegistrationVerification = (frmData) => { 26 | return new Promise(async (resolve, reject) => { 27 | try { 28 | const res = await axios.patch(userVerificationUrl, frmData); 29 | 30 | resolve(res.data); 31 | if (res.data.status === "success") { 32 | resolve(res.data); 33 | } 34 | } catch (error) { 35 | reject({ status: "error", message: error.error }); 36 | } 37 | }); 38 | }; 39 | 40 | export const userLogin = (frmData) => { 41 | return new Promise(async (resolve, reject) => { 42 | try { 43 | const res = await axios.post(loginUrl, frmData); 44 | 45 | resolve(res.data); 46 | 47 | if (res.data.status === "success") { 48 | sessionStorage.setItem("accessJWT", res.data.accessJWT); 49 | localStorage.setItem( 50 | "crmSite", 51 | JSON.stringify({ refreshJWT: res.data.refreshJWT }) 52 | ); 53 | } 54 | } catch (error) { 55 | reject(error); 56 | } 57 | }); 58 | }; 59 | 60 | export const fetchUser = () => { 61 | return new Promise(async (resolve, reject) => { 62 | try { 63 | const accessJWT = sessionStorage.getItem("accessJWT"); 64 | 65 | if (!accessJWT) { 66 | reject("Token not found!"); 67 | } 68 | 69 | const res = await axios.get(userProfileUrl, { 70 | headers: { 71 | Authorization: accessJWT, 72 | }, 73 | }); 74 | 75 | resolve(res.data); 76 | } catch (error) { 77 | console.log(error); 78 | reject(error.message); 79 | } 80 | }); 81 | }; 82 | 83 | export const fetchNewAccessJWT = () => { 84 | return new Promise(async (resolve, reject) => { 85 | try { 86 | const { refreshJWT } = JSON.parse(localStorage.getItem("crmSite")); 87 | 88 | if (!refreshJWT) { 89 | reject("Token not found!"); 90 | } 91 | 92 | const res = await axios.get(newAccessJWT, { 93 | headers: { 94 | Authorization: refreshJWT, 95 | }, 96 | }); 97 | 98 | if (res.data.status === "success") { 99 | sessionStorage.setItem("accessJWT", res.data.accessJWT); 100 | } 101 | 102 | resolve(true); 103 | } catch (error) { 104 | if (error.message === "Request failed with status code 403") { 105 | localStorage.removeItem("crmSite"); 106 | } 107 | 108 | reject(false); 109 | } 110 | }); 111 | }; 112 | 113 | export const userLogout = async () => { 114 | try { 115 | await axios.delete(logoutUrl, { 116 | headers: { 117 | Authorization: sessionStorage.getItem("accessJWT"), 118 | }, 119 | }); 120 | } catch (error) { 121 | console.log(error); 122 | } 123 | }; 124 | -------------------------------------------------------------------------------- /src/assets/data/dummy-tickets.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": 1, 4 | "subject": "Email certificate expired", 5 | "status": "Client response pending", 6 | "addedAt": "2020-09-23", 7 | "history": [ 8 | { 9 | "date": "20-10-10", 10 | "message": "sjflsjl", 11 | "messageBy": "client" 12 | }, 13 | { 14 | "date": "20-10-10", 15 | "message": "sjflsjl", 16 | "messageBy": "operator" 17 | }, 18 | { 19 | "date": "20-10-10", 20 | "message": "sjflsjl", 21 | "messageBy": "client" 22 | } 23 | ] 24 | }, 25 | { 26 | "id": 2, 27 | "subject": "Issue with Email certificate", 28 | "status": "Client response pending", 29 | "addedAt": "2020-09-23" 30 | }, 31 | { 32 | "id": 3, 33 | "subject": "Issue app crashing", 34 | "status": "Client response pending", 35 | "addedAt": "2020-09-23" 36 | }, 37 | { 38 | "id": 4, 39 | "subject": "Issue with ssl certificate", 40 | "status": "Client response pending", 41 | "addedAt": "2020-09-23" 42 | }, 43 | { 44 | "id": 5, 45 | "subject": "Issue with ssl certificate", 46 | "status": "Client response pending", 47 | "addedAt": "2020-09-23" 48 | }, 49 | { 50 | "id": 6, 51 | "subject": "Issue with ssl certificate", 52 | "status": "Client response pending", 53 | "addedAt": "2020-09-23" 54 | }, 55 | { 56 | "id": 7, 57 | "subject": "Issue with ssl certificate", 58 | "status": "Client response pending", 59 | "addedAt": "2020-09-23" 60 | }, 61 | { 62 | "id": 8, 63 | "subject": "Issue with ssl certificate", 64 | "status": "Client response pending", 65 | "addedAt": "2020-09-23" 66 | }, 67 | { 68 | "id": 9, 69 | "subject": "Issue with ssl certificate", 70 | "status": "Client response pending", 71 | "addedAt": "2020-09-23" 72 | }, 73 | { 74 | "id": 10, 75 | "subject": "Issue with ssl certificate", 76 | "status": "Client response pending", 77 | "addedAt": "2020-09-23" 78 | } 79 | ] 80 | -------------------------------------------------------------------------------- /src/assets/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DentedCode/crm-frontend/f759f98e2a6cc1a6bc31c1c598ae9f182a9cec5a/src/assets/img/logo.png -------------------------------------------------------------------------------- /src/components/add-ticket-form/AddTicketForm.comp.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect } from "react"; 2 | import { useDispatch, useSelector } from "react-redux"; 3 | import { 4 | Form, 5 | Jumbotron, 6 | Row, 7 | Col, 8 | Button, 9 | Spinner, 10 | Alert, 11 | } from "react-bootstrap"; 12 | import { openNewTicket } from "./addTicketAction"; 13 | import { shortText } from "../../utils/validation"; 14 | import { restSuccessMSg } from "./addTicketSlicer"; 15 | 16 | import "./add-ticket-form.style.css"; 17 | 18 | const initialFrmDt = { 19 | subject: "", 20 | issueDate: "", 21 | message: "", 22 | }; 23 | const initialFrmError = { 24 | subject: false, 25 | issueDate: false, 26 | message: false, 27 | }; 28 | 29 | export const AddTicketForm = () => { 30 | const dispatch = useDispatch(); 31 | 32 | const { 33 | user: { name }, 34 | } = useSelector((state) => state.user); 35 | 36 | const { isLoading, error, successMsg } = useSelector( 37 | (state) => state.openTicket 38 | ); 39 | 40 | const [frmData, setFrmData] = useState(initialFrmDt); 41 | const [frmDataErro, setFrmDataErro] = useState(initialFrmError); 42 | 43 | useEffect(() => { 44 | return () => { 45 | successMsg && dispatch(restSuccessMSg()); 46 | }; 47 | }, [dispatch, frmData, frmDataErro]); 48 | 49 | const handleOnChange = (e) => { 50 | const { name, value } = e.target; 51 | 52 | setFrmData({ 53 | ...frmData, 54 | [name]: value, 55 | }); 56 | }; 57 | 58 | const handleOnSubmit = async (e) => { 59 | e.preventDefault(); 60 | 61 | setFrmDataErro(initialFrmError); 62 | 63 | const isSubjectValid = await shortText(frmData.subject); 64 | 65 | setFrmDataErro({ 66 | ...initialFrmError, 67 | subject: !isSubjectValid, 68 | }); 69 | 70 | dispatch(openNewTicket({ ...frmData, sender: name })); 71 | }; 72 | 73 | return ( 74 | 75 |

Add New Ticket

76 |
77 |
78 | {error && {error}} 79 | {successMsg && {successMsg}} 80 | {isLoading && } 81 |
82 |
83 | 84 | 85 | Subject 86 | 87 | 88 | 97 | 98 | {frmDataErro.subject && "SUbject is required!"} 99 | 100 | 101 | 102 | 103 | 104 | Issue Found 105 | 106 | 107 | 114 | 115 | 116 | 117 | Password 118 | 126 | 127 | 128 | 131 |
132 |
133 | ); 134 | }; 135 | 136 | // AddTicketForm.propTypes = { 137 | // handleOnSubmit: PropTypes.func.isRequired, 138 | // handleOnChange: PropTypes.func.isRequired, 139 | // frmDt: PropTypes.object.isRequired, 140 | // frmDataErro: PropTypes.object.isRequired, 141 | // }; 142 | -------------------------------------------------------------------------------- /src/components/add-ticket-form/add-ticket-form.style.css: -------------------------------------------------------------------------------- 1 | .add-new-ticket { 2 | max-width: 550px; 3 | margin-left: auto; 4 | margin-right: auto; 5 | 6 | box-shadow: 0px 0px 15px -5px black; 7 | } 8 | -------------------------------------------------------------------------------- /src/components/add-ticket-form/addTicketAction.js: -------------------------------------------------------------------------------- 1 | import { 2 | openNewTicketPending, 3 | openNewTicketSuccess, 4 | openNewTicketFail, 5 | } from "./addTicketSlicer"; 6 | import { createNewTicket } from "../../api/ticketApi"; 7 | 8 | export const openNewTicket = (frmData) => (dispatch) => { 9 | return new Promise(async (resolve, reject) => { 10 | try { 11 | dispatch(openNewTicketPending()); 12 | 13 | ////call api 14 | const result = await createNewTicket(frmData); 15 | if (result.status === "error") { 16 | return dispatch(openNewTicketFail(result.message)); 17 | } 18 | dispatch(openNewTicketSuccess(result.message)); 19 | } catch (error) { 20 | console.log(error); 21 | dispatch(openNewTicketFail(error.message)); 22 | } 23 | }); 24 | }; 25 | -------------------------------------------------------------------------------- /src/components/add-ticket-form/addTicketSlicer.js: -------------------------------------------------------------------------------- 1 | import { createSlice } from "@reduxjs/toolkit"; 2 | 3 | const initialState = { 4 | isLoading: false, 5 | error: "", 6 | successMsg: "", 7 | }; 8 | const newTicketSlice = createSlice({ 9 | name: "newTicket", 10 | initialState, 11 | reducers: { 12 | openNewTicketPending: (state) => { 13 | state.isLoading = true; 14 | }, 15 | openNewTicketSuccess: (state, { payload }) => { 16 | state.isLoading = false; 17 | state.successMsg = payload; 18 | }, 19 | openNewTicketFail: (state, { payload }) => { 20 | state.isLoading = true; 21 | state.error = payload; 22 | }, 23 | restSuccessMSg: (state) => { 24 | state.isLoading = true; 25 | state.successMsg = ""; 26 | }, 27 | }, 28 | }); 29 | 30 | export const { 31 | openNewTicketPending, 32 | openNewTicketSuccess, 33 | openNewTicketFail, 34 | restSuccessMSg, 35 | } = newTicketSlice.actions; 36 | export default newTicketSlice.reducer; 37 | -------------------------------------------------------------------------------- /src/components/breadcrumb/Breadcrumb.comp.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { Breadcrumb } from "react-bootstrap"; 3 | import { LinkContainer } from "react-router-bootstrap"; 4 | 5 | export const PageBreadcrumb = ({ page }) => { 6 | return ( 7 | 8 | 9 | Home 10 | 11 | {page} 12 | 13 | ); 14 | }; 15 | -------------------------------------------------------------------------------- /src/components/login/Login.comp.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect } from "react"; 2 | import PropTypes from "prop-types"; 3 | import { 4 | Container, 5 | Row, 6 | Col, 7 | Form, 8 | Button, 9 | Spinner, 10 | Alert, 11 | } from "react-bootstrap"; 12 | import { useDispatch, useSelector } from "react-redux"; 13 | import { useHistory, useLocation } from "react-router-dom"; 14 | 15 | import { loginPending, loginSuccess, loginFail } from "./loginSlice"; 16 | import { userLogin } from "../../api/userApi"; 17 | import { getUserProfile } from "../../pages/dashboard/userAction"; 18 | 19 | export const LoginForm = ({ formSwitcher }) => { 20 | const dispatch = useDispatch(); 21 | const history = useHistory(); 22 | let location = useLocation(); 23 | 24 | const { isLoading, isAuth, error } = useSelector(state => state.login); 25 | let { from } = location.state || { from: { pathname: "/" } }; 26 | 27 | useEffect(() => { 28 | sessionStorage.getItem("accessJWT") && history.replace(from); 29 | }, [history, isAuth]); 30 | 31 | const [email, setEmail] = useState("e2@e.com"); 32 | const [password, setPassword] = useState("password#1F"); 33 | 34 | const handleOnChange = e => { 35 | const { name, value } = e.target; 36 | 37 | switch (name) { 38 | case "email": 39 | setEmail(value); 40 | break; 41 | 42 | case "password": 43 | setPassword(value); 44 | break; 45 | 46 | default: 47 | break; 48 | } 49 | }; 50 | 51 | const handleOnSubmit = async e => { 52 | e.preventDefault(); 53 | 54 | if (!email || !password) { 55 | return alert("Fill up all the form!"); 56 | } 57 | 58 | dispatch(loginPending()); 59 | 60 | try { 61 | const isAuth = await userLogin({ email, password }); 62 | 63 | if (isAuth.status === "error") { 64 | return dispatch(loginFail(isAuth.message)); 65 | } 66 | 67 | dispatch(loginSuccess()); 68 | dispatch(getUserProfile()); 69 | history.push("/dashboard"); 70 | } catch (error) { 71 | dispatch(loginFail(error.message)); 72 | } 73 | }; 74 | 75 | return ( 76 | 77 | 78 | 79 |

Client Login

80 |
81 | {error && {error}} 82 |
83 | 84 | Email Address 85 | 93 | 94 | 95 | Password 96 | 104 | 105 | 106 | 107 | {isLoading && } 108 | 109 |
110 | 111 |
112 | 113 | 114 | 115 | Forget Password? 116 | 117 | 118 | 119 | 120 | Are you new here? Register Now 121 | 122 | 123 |
124 | ); 125 | }; 126 | 127 | LoginForm.propTypes = { 128 | formSwitcher: PropTypes.func.isRequired, 129 | }; 130 | -------------------------------------------------------------------------------- /src/components/login/loginSlice.js: -------------------------------------------------------------------------------- 1 | import { createSlice } from "@reduxjs/toolkit"; 2 | 3 | const initialState = { 4 | isLoading: false, 5 | isAuth: false, 6 | error: "", 7 | }; 8 | 9 | const loginSlice = createSlice({ 10 | name: "login", 11 | initialState, 12 | reducers: { 13 | loginPending: (state) => { 14 | state.isLoading = true; 15 | }, 16 | loginSuccess: (state) => { 17 | state.isLoading = false; 18 | state.isAuth = true; 19 | state.error = ""; 20 | }, 21 | loginFail: (state, { payload }) => { 22 | state.isLoading = false; 23 | state.error = payload; 24 | }, 25 | }, 26 | }); 27 | 28 | const { reducer, actions } = loginSlice; 29 | 30 | export const { loginPending, loginSuccess, loginFail } = actions; 31 | 32 | export default reducer; 33 | -------------------------------------------------------------------------------- /src/components/message-history/MessageHistory.comp.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import PropTypes from "prop-types"; 3 | import "./message-history.style.css"; 4 | 5 | export const MessageHistory = ({ msg }) => { 6 | if (!msg) return null; 7 | 8 | return msg.map((row, i) => ( 9 |
10 |
11 |
{row.sender}
12 |
13 | {row.msgAt && new Date(row.msgAt).toLocaleString()} 14 |
15 |
16 |
{row.message}
17 |
18 | )); 19 | }; 20 | 21 | MessageHistory.propTypes = { 22 | msg: PropTypes.array.isRequired, 23 | }; 24 | -------------------------------------------------------------------------------- /src/components/message-history/message-history.style.css: -------------------------------------------------------------------------------- 1 | .message-history { 2 | display: flex; 3 | flex-direction: row; 4 | justify-content: space-between; 5 | } 6 | 7 | .message-history:nth-child(even) { 8 | display: flex; 9 | flex-direction: row-reverse; 10 | justify-content: space-between; 11 | } 12 | 13 | .message { 14 | padding: 1rem; 15 | width: 80%; 16 | border: 1px solid #ced4da; 17 | border-radius: 0.25rem; 18 | } 19 | -------------------------------------------------------------------------------- /src/components/password-reset/PasswordReset.comp.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import { useDispatch, useSelector } from "react-redux"; 3 | import { sendPasswordResetOtp } from "./passwordAction"; 4 | 5 | import { 6 | Container, 7 | Row, 8 | Col, 9 | Form, 10 | Button, 11 | Alert, 12 | Spinner, 13 | } from "react-bootstrap"; 14 | 15 | export const ResetPassword = () => { 16 | const dispatch = useDispatch(); 17 | 18 | const [email, setEmail] = useState(""); 19 | 20 | const { isLoading, status, message } = useSelector(state => state.password); 21 | 22 | const handleOnResetSubmit = e => { 23 | e.preventDefault(); 24 | 25 | dispatch(sendPasswordResetOtp(email)); 26 | }; 27 | 28 | const handleOnChange = e => { 29 | const { value } = e.target; 30 | setEmail(value); 31 | }; 32 | 33 | return ( 34 | 35 | 36 | 37 |

Reset Password

38 |
39 | 40 | {message && ( 41 | 42 | {message} 43 | 44 | )} 45 | 46 | {isLoading && } 47 | 48 |
49 | 50 | Email Address 51 | 59 | 60 | 61 | 62 |
63 |
64 | 65 |
66 |
67 | ); 68 | }; 69 | -------------------------------------------------------------------------------- /src/components/password-reset/UpdatePasswordForm.comp.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect } from "react"; 2 | import { useDispatch, useSelector } from "react-redux"; 3 | import { updatePassword } from "./passwordAction"; 4 | 5 | import { 6 | Container, 7 | Row, 8 | Col, 9 | Form, 10 | Button, 11 | Spinner, 12 | Alert, 13 | } from "react-bootstrap"; 14 | 15 | const initialState = { 16 | pin: "", 17 | password: "sfsd#3Dsg", 18 | confirmPass: "sfsd#3Dsg", 19 | }; 20 | const passVerificationError = { 21 | isLenthy: false, 22 | hasUpper: false, 23 | hasLower: false, 24 | hasNumber: false, 25 | hasSpclChr: false, 26 | confirmPass: false, 27 | }; 28 | 29 | const UpdatePasswordForm = () => { 30 | const dispatch = useDispatch(); 31 | 32 | const [newPassword, setNewPassword] = useState(initialState); 33 | const [passwordError, setPasswordError] = useState(passVerificationError); 34 | 35 | const { isLoading, status, message, email } = useSelector( 36 | state => state.password 37 | ); 38 | 39 | const handleOnChange = e => { 40 | const { name, value } = e.target; 41 | 42 | setNewPassword({ ...newPassword, [name]: value }); 43 | 44 | if (name === "password") { 45 | const isLenthy = value.length > 8; 46 | const hasUpper = /[A-Z]/.test(value); 47 | const hasLower = /[a-z]/.test(value); 48 | const hasNumber = /[0-9]/.test(value); 49 | const hasSpclChr = /[@,#,$,%,&]/.test(value); 50 | 51 | setPasswordError({ 52 | ...passwordError, 53 | isLenthy, 54 | hasUpper, 55 | hasLower, 56 | hasNumber, 57 | hasSpclChr, 58 | }); 59 | } 60 | 61 | if (name === "confirmPass") { 62 | setPasswordError({ 63 | ...passwordError, 64 | confirmPass: newPassword.password === value, 65 | }); 66 | } 67 | }; 68 | 69 | const handleOnSubmit = e => { 70 | e.preventDefault(); 71 | // console.log(newUser); 72 | 73 | const { pin, password } = newPassword; 74 | 75 | const newPassObj = { 76 | pin, 77 | newPassword: password, 78 | email, 79 | }; 80 | dispatch(updatePassword(newPassObj)); 81 | }; 82 | 83 | return ( 84 | 85 | 86 | 87 |

Update Password

88 | 89 |
90 |
91 | 92 | 93 | {message && ( 94 | 95 | {message} 96 | 97 | )} 98 | {isLoading && } 99 | 100 | 101 | 102 | 103 | 104 |
105 | 106 | OTP 107 | 115 | 116 | 117 | 118 | Password 119 | 127 | 128 | 129 | 130 | Confirm Password 131 | 139 | 140 | 141 | {!passwordError.confirmPass && ( 142 |
Password doesn't match!
143 | )} 144 |
145 | 146 |
    147 |
  • 152 | Min 8 characters 153 |
  • 154 |
  • 159 | At least one upper case 160 |
  • 161 |
  • 166 | At least one lower case 167 |
  • 168 |
  • 173 | At least one number 174 |
  • 175 |
  • 180 | At least on of the special characters i.e @ # $ % &{" "} 181 |
  • 182 |
183 | 184 | 191 |
192 | 193 |
194 |
195 | ); 196 | }; 197 | 198 | export default UpdatePasswordForm; 199 | -------------------------------------------------------------------------------- /src/components/password-reset/passwordAction.js: -------------------------------------------------------------------------------- 1 | import { 2 | otpReqPending, 3 | otpReqSuccess, 4 | otpReqFail, 5 | updatePassSuccess, 6 | } from "./passwordSlice"; 7 | 8 | import { reqPasswordOtp, updateUserPassword } from "../../api/passwordApi"; 9 | 10 | export const sendPasswordResetOtp = email => async dispatch => { 11 | try { 12 | dispatch(otpReqPending()); 13 | 14 | const { status, message } = await reqPasswordOtp(email); 15 | 16 | if (status === "success") { 17 | return dispatch(otpReqSuccess({ message, email })); 18 | } 19 | 20 | dispatch(otpReqFail(message)); 21 | } catch (error) { 22 | dispatch(otpReqFail(error.message)); 23 | } 24 | }; 25 | 26 | export const updatePassword = frmData => async dispatch => { 27 | try { 28 | dispatch(otpReqPending()); 29 | 30 | const { status, message } = await updateUserPassword(frmData); 31 | 32 | if (status === "success") { 33 | return dispatch(updatePassSuccess(message)); 34 | } 35 | 36 | dispatch(otpReqFail(message)); 37 | } catch (error) { 38 | dispatch(otpReqFail(error.message)); 39 | } 40 | }; 41 | -------------------------------------------------------------------------------- /src/components/password-reset/passwordSlice.js: -------------------------------------------------------------------------------- 1 | import { createSlice } from "@reduxjs/toolkit"; 2 | 3 | const initialState = { 4 | isLoading: false, 5 | status: "", 6 | message: "", 7 | showUpdatePassForm: false, 8 | email: "", 9 | }; 10 | const passwordReset = createSlice({ 11 | name: "passwordReset", 12 | initialState, 13 | reducers: { 14 | otpReqPending: state => { 15 | state.isLoading = true; 16 | }, 17 | otpReqSuccess: (state, { payload }) => { 18 | state.isLoading = false; 19 | state.status = "success"; 20 | state.message = payload.message; 21 | state.email = payload.email; 22 | state.showUpdatePassForm = true; 23 | }, 24 | updatePassSuccess: (state, { payload }) => { 25 | state.isLoading = false; 26 | state.status = "success"; 27 | state.message = payload; 28 | // state.showOtpForm = false; 29 | }, 30 | otpReqFail: (state, { payload }) => { 31 | state.isLoading = false; 32 | state.status = "error"; 33 | state.message = payload; 34 | }, 35 | }, 36 | }); 37 | 38 | const { reducer, actions } = passwordReset; 39 | 40 | export const { 41 | otpReqPending, 42 | otpReqSuccess, 43 | otpReqFail, 44 | updatePassSuccess, 45 | } = actions; 46 | export default reducer; 47 | -------------------------------------------------------------------------------- /src/components/private-route/PrivateRoute.comp.js: -------------------------------------------------------------------------------- 1 | import React, { useEffect } from "react"; 2 | import { useSelector, useDispatch } from "react-redux"; 3 | import { Route, Redirect } from "react-router-dom"; 4 | import { loginSuccess } from "../login/loginSlice"; 5 | import { getUserProfile } from "../../pages/dashboard/userAction"; 6 | 7 | import { fetchNewAccessJWT } from "../../api/userApi"; 8 | 9 | import { DefaultLayout } from "../../layout/DefaultLayout"; 10 | 11 | export const PrivateRoute = ({ children, ...rest }) => { 12 | const dispatch = useDispatch(); 13 | const { isAuth } = useSelector(state => state.login); 14 | const { user } = useSelector(state => state.user); 15 | 16 | useEffect(() => { 17 | const updateAccessJWT = async () => { 18 | const result = await fetchNewAccessJWT(); 19 | result && dispatch(loginSuccess()); 20 | }; 21 | 22 | !user._id && dispatch(getUserProfile()); 23 | 24 | !sessionStorage.getItem("accessJWT") && 25 | localStorage.getItem("crmSite") && 26 | updateAccessJWT(); 27 | 28 | !isAuth && sessionStorage.getItem("accessJWT") && dispatch(loginSuccess()); 29 | }, [dispatch, isAuth, user._id]); 30 | 31 | return ( 32 | 35 | isAuth ? ( 36 | {children} 37 | ) : ( 38 | 44 | ) 45 | } 46 | /> 47 | ); 48 | }; 49 | -------------------------------------------------------------------------------- /src/components/registration-form/RegistrationForm.comp.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect } from "react"; 2 | import { 3 | Container, 4 | Row, 5 | Col, 6 | Form, 7 | Button, 8 | Spinner, 9 | Alert, 10 | } from "react-bootstrap"; 11 | import { newUserRegistration } from "./userRegAction"; 12 | import { useDispatch, useSelector } from "react-redux"; 13 | 14 | const initialState = { 15 | name: "Prem Acharya", 16 | phone: "0410000000", 17 | email: "fakeemail@email.com", 18 | company: "Dented Code", 19 | address: "George st Sydney", 20 | password: "sfsd#3Dsg", 21 | confirmPass: "sfsd#3Dsg", 22 | }; 23 | const passVerificationError = { 24 | isLenthy: false, 25 | hasUpper: false, 26 | hasLower: false, 27 | hasNumber: false, 28 | hasSpclChr: false, 29 | confirmPass: false, 30 | }; 31 | 32 | const RegistrationForm = () => { 33 | const dispatch = useDispatch(); 34 | const [newUser, setNewUser] = useState(initialState); 35 | const [passwordError, setPasswordError] = useState(passVerificationError); 36 | 37 | const { isLoading, status, message } = useSelector( 38 | (state) => state.registration 39 | ); 40 | 41 | useEffect(() => {}, [newUser]); 42 | 43 | const handleOnChange = (e) => { 44 | const { name, value } = e.target; 45 | 46 | setNewUser({ ...newUser, [name]: value }); 47 | 48 | if (name === "password") { 49 | const isLenthy = value.length > 8; 50 | const hasUpper = /[A-Z]/.test(value); 51 | const hasLower = /[a-z]/.test(value); 52 | const hasNumber = /[0-9]/.test(value); 53 | const hasSpclChr = /[@,#,$,%,&]/.test(value); 54 | 55 | setPasswordError({ 56 | ...passwordError, 57 | isLenthy, 58 | hasUpper, 59 | hasLower, 60 | hasNumber, 61 | hasSpclChr, 62 | }); 63 | } 64 | 65 | if (name === "confirmPass") { 66 | setPasswordError({ 67 | ...passwordError, 68 | confirmPass: newUser.password === value, 69 | }); 70 | } 71 | }; 72 | 73 | const handleOnSubmit = (e) => { 74 | e.preventDefault(); 75 | // console.log(newUser); 76 | const { name, phone, email, company, address, password } = newUser; 77 | 78 | const newRegistration = { 79 | name, 80 | phone, 81 | email, 82 | company, 83 | address, 84 | password, 85 | }; 86 | dispatch(newUserRegistration(newRegistration)); 87 | }; 88 | 89 | return ( 90 | 91 | 92 | 93 |

User Registration

94 | 95 |
96 |
97 | 98 | 99 | {message && ( 100 | 101 | {message} 102 | 103 | )} 104 | 105 | 106 | 107 | 108 | 109 |
110 | 111 | Full Name 112 | 120 | 121 | 122 | 123 | Phone 124 | 132 | 133 | 134 | 135 | Email address 136 | 144 | 145 | 146 | 147 | Company name 148 | 156 | 157 | 158 | 159 | Address 160 | 168 | 169 | 170 | 171 | Password 172 | 180 | 181 | 182 | 183 | Confirm Password 184 | 192 | 193 | 194 | {!passwordError.confirmPass && ( 195 |
Password doesn't match!
196 | )} 197 |
198 | 199 |
    200 |
  • 205 | Min 8 characters 206 |
  • 207 |
  • 212 | At least one upper case 213 |
  • 214 |
  • 219 | At least one lower case 220 |
  • 221 |
  • 226 | At least one number 227 |
  • 228 |
  • 233 | At least on of the special characters i.e @ # $ % &{" "} 234 |
  • 235 |
236 | 237 | 244 | {isLoading && } 245 | 246 | 247 |
248 | 249 | 250 | Already have an account Login Now 251 | 252 | 253 |
254 | ); 255 | }; 256 | 257 | export default RegistrationForm; 258 | -------------------------------------------------------------------------------- /src/components/registration-form/userRegAction.js: -------------------------------------------------------------------------------- 1 | import { 2 | registrationPending, 3 | registrationSuccess, 4 | registrationError, 5 | } from "./userRegestrationSlice"; 6 | 7 | import { userRegistration } from "../../api/userApi"; 8 | 9 | export const newUserRegistration = (frmDt) => async (dispatch) => { 10 | try { 11 | dispatch(registrationPending()); 12 | 13 | const result = await userRegistration(frmDt); 14 | result.status === "success" 15 | ? dispatch(registrationSuccess(result.message)) 16 | : dispatch(registrationError(result.message)); 17 | 18 | console.log(result); 19 | } catch (error) { 20 | dispatch(registrationError(error.message)); 21 | } 22 | }; 23 | -------------------------------------------------------------------------------- /src/components/registration-form/userRegestrationSlice.js: -------------------------------------------------------------------------------- 1 | import { createSlice } from "@reduxjs/toolkit"; 2 | 3 | const initialState = { 4 | isLoading: false, 5 | status: "", 6 | message: "", 7 | }; 8 | 9 | const userRegestrationSlice = createSlice({ 10 | name: "userRegistration", 11 | initialState, 12 | reducers: { 13 | registrationPending: (state) => { 14 | state.isLoading = true; 15 | }, 16 | registrationSuccess: (state, { payload }) => { 17 | state.isLoading = false; 18 | state.status = "success"; 19 | state.message = payload; 20 | }, 21 | registrationError: (state, { payload }) => { 22 | state.isLoading = false; 23 | state.status = "error"; 24 | state.message = payload; 25 | }, 26 | }, 27 | }); 28 | 29 | const { reducer, actions } = userRegestrationSlice; 30 | 31 | export const { 32 | registrationPending, 33 | registrationSuccess, 34 | registrationError, 35 | } = actions; 36 | 37 | export default reducer; 38 | -------------------------------------------------------------------------------- /src/components/search-form/SearchForm.comp.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { useDispatch } from "react-redux"; 3 | import { filterSerachTicket } from "../../pages/ticket-list/ticketsAction"; 4 | 5 | import { Form, Row, Col } from "react-bootstrap"; 6 | 7 | export const SearchForm = () => { 8 | const dispatch = useDispatch(); 9 | 10 | const handleOnChange = (e) => { 11 | const { value } = e.target; 12 | 13 | dispatch(filterSerachTicket(value)); 14 | }; 15 | 16 | return ( 17 |
18 |
19 | 20 | 21 | Search: 22 | 23 | 24 | 29 | 30 | 31 |
32 |
33 | ); 34 | }; 35 | -------------------------------------------------------------------------------- /src/components/ticket-table/TicketTable.comp.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { useSelector } from "react-redux"; 3 | 4 | import { Table } from "react-bootstrap"; 5 | 6 | import { Link } from "react-router-dom"; 7 | 8 | export const TicketTable = () => { 9 | const { searchTicketList, isLoading, error } = useSelector( 10 | (state) => state.tickets 11 | ); 12 | if (isLoading) return

Loading ...

; 13 | if (error) return

{error}

; 14 | 15 | return ( 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | {searchTicketList.length ? ( 27 | searchTicketList.map((row) => ( 28 | 29 | 30 | 33 | 34 | 35 | 36 | )) 37 | ) : ( 38 | 39 | 42 | 43 | )} 44 | 45 |
#SubjectsStatusOpened Date
{row._id} 31 | {row.subject} 32 | {row.status}{row.openAt && new Date(row.openAt).toLocaleString()}
40 | No ticket show{" "} 41 |
46 | ); 47 | }; 48 | -------------------------------------------------------------------------------- /src/components/update-ticket/UpdateTicket.comp.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import PropTypes from "prop-types"; 3 | import { useSelector, useDispatch } from "react-redux"; 4 | import { Form, Button } from "react-bootstrap"; 5 | 6 | import { replyOnTicket } from "../../pages/ticket-list/ticketsAction"; 7 | 8 | export const UpdateTicket = ({ _id }) => { 9 | const dispatch = useDispatch(); 10 | const { 11 | user: { name }, 12 | } = useSelector((state) => state.user); 13 | const [message, setMessage] = useState(""); 14 | 15 | const handleOnChange = (e) => { 16 | setMessage(e.target.value); 17 | }; 18 | 19 | const handleOnSubmit = (e) => { 20 | e.preventDefault(); 21 | 22 | const msgObj = { 23 | message, 24 | sender: name, 25 | }; 26 | 27 | dispatch(replyOnTicket(_id, msgObj)); 28 | setMessage(""); 29 | }; 30 | 31 | return ( 32 |
33 |
34 | Reply 35 | 36 | Please reply your message here or update the ticket 37 | 38 | 45 |
46 | 49 |
50 | 51 |
52 | ); 53 | }; 54 | 55 | UpdateTicket.propTypes = { 56 | _id: PropTypes.string.isRequired, 57 | }; 58 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import ReactDOM from "react-dom"; 3 | 4 | import { Provider } from "react-redux"; 5 | import store from "./store"; 6 | 7 | import "./index.css"; 8 | import App from "./App"; 9 | import "bootstrap/dist/css/bootstrap.min.css"; 10 | 11 | ReactDOM.render( 12 | 13 | 14 | 15 | 16 | , 17 | document.getElementById("root") 18 | ); 19 | 20 | // If you want your app to work offline and load faster, you can change 21 | // unregister() to register() below. Note this comes with some pitfalls. 22 | // Learn more about service workers: https://bit.ly/CRA-PWA 23 | -------------------------------------------------------------------------------- /src/layout/DefaultLayout.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { Header } from "./partials/Header.comp"; 3 | import { Footer } from "./partials/Footer.comp"; 4 | 5 | export const DefaultLayout = ({ children }) => { 6 | return ( 7 |
8 |
9 |
10 |
11 | 12 |
{children}
13 | 14 |
15 |
16 |
17 |
18 | ); 19 | }; 20 | -------------------------------------------------------------------------------- /src/layout/partials/Footer.comp.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | export const Footer = () => { 4 | return ( 5 |
6 | © CRM all right reserved - 2020. 7 |
8 | ); 9 | }; 10 | -------------------------------------------------------------------------------- /src/layout/partials/Header.comp.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { Navbar, Nav } from "react-bootstrap"; 3 | import logo from "../../assets/img/logo.png"; 4 | import { useHistory } from "react-router-dom"; 5 | import { LinkContainer } from "react-router-bootstrap"; 6 | 7 | import { userLogout } from "../../api/userApi"; 8 | 9 | export const Header = () => { 10 | const history = useHistory(); 11 | 12 | const logMeOut = () => { 13 | sessionStorage.removeItem("accessJWT"); 14 | localStorage.removeItem("crmSite"); 15 | userLogout(); 16 | history.push("/"); 17 | }; 18 | 19 | return ( 20 | 21 | 22 | logo 23 | 24 | 25 | 26 | 36 | 37 | 38 | ); 39 | }; 40 | -------------------------------------------------------------------------------- /src/pages/dashboard/Dashboard.page.js: -------------------------------------------------------------------------------- 1 | import React, { useEffect } from "react"; 2 | import { useSelector, useDispatch } from "react-redux"; 3 | import { Container, Row, Col, Button } from "react-bootstrap"; 4 | import { TicketTable } from "../../components/ticket-table/TicketTable.comp"; 5 | import tickets from "../../assets/data/dummy-tickets.json"; 6 | import { PageBreadcrumb } from "../../components/breadcrumb/Breadcrumb.comp"; 7 | import { Link } from "react-router-dom"; 8 | 9 | import { fetchAllTickets } from "../ticket-list/ticketsAction"; 10 | 11 | export const Dashboard = () => { 12 | const dispatch = useDispatch(); 13 | const { tickets } = useSelector((state) => state.tickets); 14 | 15 | useEffect(() => { 16 | if (!tickets.length) { 17 | dispatch(fetchAllTickets()); 18 | } 19 | }, [tickets, dispatch]); 20 | 21 | const pendingTickets = tickets.filter((row) => row.status !== "Closed"); 22 | const totlatTickets = tickets.length; 23 | return ( 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 |
Total tickets: {totlatTickets}
45 |
Pending tickets: {pendingTickets.length}
46 | 47 |
48 | 49 | Recently Added tickets 50 | 51 |
52 | 53 | 54 | 55 | 56 | 57 | 58 |
59 | ); 60 | }; 61 | -------------------------------------------------------------------------------- /src/pages/dashboard/userAction.js: -------------------------------------------------------------------------------- 1 | import { getUserPending, getUserSuccess, getUserFail } from "./userSlice"; 2 | import { fetchUser } from "../../api/userApi"; 3 | 4 | export const getUserProfile = () => async (dispatch) => { 5 | try { 6 | dispatch(getUserPending()); 7 | 8 | const result = await fetchUser(); 9 | 10 | if (result.user && result.user._id) 11 | return dispatch(getUserSuccess(result.user)); 12 | 13 | dispatch(getUserFail("User is not found")); 14 | } catch (error) { 15 | dispatch(getUserFail(error)); 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /src/pages/dashboard/userSlice.js: -------------------------------------------------------------------------------- 1 | import { createSlice } from "@reduxjs/toolkit"; 2 | 3 | const initialState = { 4 | user: {}, 5 | isLoading: false, 6 | error: "", 7 | }; 8 | 9 | const userSlice = createSlice({ 10 | name: "user", 11 | initialState, 12 | reducers: { 13 | getUserPending: (state) => { 14 | state.isLoading = true; 15 | }, 16 | getUserSuccess: (state, { payload }) => { 17 | state.isLoading = false; 18 | state.user = payload; 19 | state.error = ""; 20 | }, 21 | getUserFail: (state, { payload }) => { 22 | state.isLoading = false; 23 | state.error = payload; 24 | }, 25 | }, 26 | }); 27 | 28 | export const { 29 | getUserPending, 30 | getUserSuccess, 31 | getUserFail, 32 | } = userSlice.actions; 33 | 34 | export default userSlice.reducer; 35 | -------------------------------------------------------------------------------- /src/pages/entry/Entry.page.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | 3 | import { Jumbotron } from "react-bootstrap"; 4 | import { LoginForm } from "../../components/login/Login.comp"; 5 | import { ResetPassword } from "../../components/password-reset/PasswordReset.comp"; 6 | 7 | import "./entry.style.css"; 8 | 9 | //Workflow 10 | 11 | // [] Create password reset page 12 | // [] Add request OTP form 13 | // [] Add redux store with Redux-toolkit to handle the network status 14 | // [] sent OTP to email from API (API Already created) 15 | // [] Load form to input OTP and new password 16 | // [] New password must match confirm password, form validation 17 | // [] Connect to API Endpoint (API Already created) 18 | // [] Add reducer through Redux-toolkit to handle the network status and provide the feedback to the user 19 | // [] Send email, OTP and new password to update the password. 20 | 21 | export const Entry = () => { 22 | const [frmLoad, setFrmLoad] = useState("login"); 23 | 24 | const handleOnResetSubmit = e => { 25 | e.preventDefault(); 26 | }; 27 | 28 | const formSwitcher = frmType => { 29 | setFrmLoad(frmType); 30 | }; 31 | 32 | return ( 33 |
34 | 35 | {frmLoad === "login" && } 36 | 37 | {frmLoad === "rest" && ( 38 | 44 | )} 45 | 46 |
47 | ); 48 | }; 49 | -------------------------------------------------------------------------------- /src/pages/entry/entry.style.css: -------------------------------------------------------------------------------- 1 | .entry-page { 2 | height: 100vh; 3 | display: flex; 4 | justify-content: center; 5 | align-items: center; 6 | } 7 | 8 | .form-box { 9 | box-shadow: 0px 0px 15px -5px black; 10 | } 11 | -------------------------------------------------------------------------------- /src/pages/new-ticket/AddTicket.page.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { Container, Row, Col } from "react-bootstrap"; 3 | import { PageBreadcrumb } from "../../components/breadcrumb/Breadcrumb.comp"; 4 | import { AddTicketForm } from "../../components/add-ticket-form/AddTicketForm.comp"; 5 | 6 | export const AddTicket = () => { 7 | return ( 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | ); 22 | }; 23 | -------------------------------------------------------------------------------- /src/pages/password-reset/PasswordOtpForm.page.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import { useSelector } from "react-redux"; 3 | 4 | import { Jumbotron } from "react-bootstrap"; 5 | import { ResetPassword } from "../../components/password-reset/PasswordReset.comp"; 6 | import UpdatePasswordForm from "../../components/password-reset/UpdatePasswordForm.comp"; 7 | 8 | import "./passwordOtpForm.style.css"; 9 | 10 | //Workflow 11 | 12 | // [x] Create password reset page 13 | // [] Add request OTP form 14 | // [] Add redux store with Redux-toolkit to handle the network status 15 | // [] sent OTP to email from API (API Already created) 16 | // [] Load form to input OTP and new password 17 | // [] New password must match confirm password, form validation 18 | // [] Connect to API Endpoint (API Already created) 19 | // [] Add reducer through Redux-toolkit to handle the network status and provide the feedback to the user 20 | // [] Send email, OTP and new password to update the password. 21 | 22 | export const PasswordOtpForm = () => { 23 | const { showUpdatePassForm } = useSelector(state => state.password); 24 | 25 | return ( 26 |
27 | 28 | {showUpdatePassForm ? : } 29 |
30 | Login Now 31 |
32 |
33 |
34 | ); 35 | }; 36 | -------------------------------------------------------------------------------- /src/pages/password-reset/passwordOtpForm.style.css: -------------------------------------------------------------------------------- 1 | .entry-page { 2 | min-height: 100vh; 3 | display: flex; 4 | justify-content: center; 5 | align-items: center; 6 | } 7 | 8 | .form-box { 9 | box-shadow: 0px 0px 15px -5px black; 10 | } 11 | -------------------------------------------------------------------------------- /src/pages/registration/Registration.page.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { Jumbotron } from "react-bootstrap"; 3 | 4 | import RegistrationForm from "../../components/registration-form/RegistrationForm.comp"; 5 | 6 | import "./registration.style.css"; 7 | 8 | export const Registration = () => { 9 | return ( 10 |
11 |
12 | 13 | 14 | 15 |
16 |
17 | ); 18 | }; 19 | -------------------------------------------------------------------------------- /src/pages/registration/registration.style.css: -------------------------------------------------------------------------------- 1 | .registration-page { 2 | display: flex; 3 | justify-content: center; 4 | align-items: center; 5 | } 6 | 7 | .form-box { 8 | box-shadow: 0px 0px 15px -5px black; 9 | } 10 | -------------------------------------------------------------------------------- /src/pages/ticket-list/TicketLists.page.js: -------------------------------------------------------------------------------- 1 | import React, { useEffect } from "react"; 2 | import { useDispatch } from "react-redux"; 3 | import { fetchAllTickets } from "./ticketsAction"; 4 | 5 | import { Container, Row, Col, Button } from "react-bootstrap"; 6 | import { PageBreadcrumb } from "../../components/breadcrumb/Breadcrumb.comp"; 7 | import { SearchForm } from "../../components/search-form/SearchForm.comp"; 8 | import { TicketTable } from "../../components/ticket-table/TicketTable.comp"; 9 | 10 | import { Link } from "react-router-dom"; 11 | 12 | export const TicketLists = () => { 13 | const dispatch = useDispatch(); 14 | 15 | useEffect(() => { 16 | dispatch(fetchAllTickets()); 17 | }, [dispatch]); 18 | 19 | return ( 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 |
37 | 38 | 39 | 40 | 41 | 42 |
43 | ); 44 | }; 45 | -------------------------------------------------------------------------------- /src/pages/ticket-list/ticketsAction.js: -------------------------------------------------------------------------------- 1 | import { 2 | fetchTicketLoading, 3 | fetchTicketSuccess, 4 | fetchTicketFail, 5 | searchTickets, 6 | fetchSingleTicketLoading, 7 | fetchSingleTicketSuccess, 8 | fetchSingleTicketFail, 9 | replyTicketLoading, 10 | replyTicketSuccess, 11 | replyTicketFail, 12 | closeTicketLoading, 13 | closeTicketSuccess, 14 | closeTicketFail, 15 | } from "./ticketsSlice"; 16 | 17 | import { 18 | getAllTickets, 19 | getSingleTicket, 20 | updateReplyTicket, 21 | updateTicketStatusClosed, 22 | } from "../../api/ticketApi"; 23 | 24 | export const fetchAllTickets = () => async (dispatch) => { 25 | dispatch(fetchTicketLoading()); 26 | try { 27 | const result = await getAllTickets(); 28 | result.data.result.length && 29 | dispatch(fetchTicketSuccess(result.data.result)); 30 | } catch (error) { 31 | dispatch(fetchTicketFail(error.message)); 32 | } 33 | }; 34 | 35 | export const filterSerachTicket = (str) => (dispatch) => { 36 | dispatch(searchTickets(str)); 37 | }; 38 | 39 | //Actions for single ticket only 40 | export const fetchSingleTicket = (_id) => async (dispatch) => { 41 | dispatch(fetchSingleTicketLoading()); 42 | try { 43 | const result = await getSingleTicket(_id); 44 | dispatch( 45 | fetchSingleTicketSuccess( 46 | result.data.result.length && result.data.result[0] 47 | ) 48 | ); 49 | } catch (error) { 50 | dispatch(fetchSingleTicketFail(error.message)); 51 | } 52 | }; 53 | 54 | //Actions for replying on single ticket 55 | export const replyOnTicket = (_id, msgObj) => async (dispatch) => { 56 | dispatch(replyTicketLoading()); 57 | try { 58 | const result = await updateReplyTicket(_id, msgObj); 59 | console.log(result); 60 | if (result.status === "error") { 61 | return dispatch(replyTicketFail(result.message)); 62 | } 63 | 64 | dispatch(fetchSingleTicket(_id)); 65 | 66 | dispatch(replyTicketSuccess(result.message)); 67 | } catch (error) { 68 | console.log(error.message); 69 | dispatch(replyTicketFail(error.message)); 70 | } 71 | }; 72 | //Actions for closing ticket 73 | export const closeTicket = (_id) => async (dispatch) => { 74 | dispatch(closeTicketLoading()); 75 | try { 76 | const result = await updateTicketStatusClosed(_id); 77 | if (result.status === "error") { 78 | return dispatch(closeTicketFail(result.message)); 79 | } 80 | 81 | dispatch(fetchSingleTicket(_id)); 82 | 83 | dispatch(closeTicketSuccess("Status Updated successfully")); 84 | } catch (error) { 85 | console.log(error.message); 86 | dispatch(closeTicketFail(error.message)); 87 | } 88 | }; 89 | -------------------------------------------------------------------------------- /src/pages/ticket-list/ticketsSlice.js: -------------------------------------------------------------------------------- 1 | import { createSlice } from "@reduxjs/toolkit"; 2 | 3 | const initialState = { 4 | tickets: [], 5 | isLoading: false, 6 | error: "", 7 | replyTicketError: "", 8 | searchTicketList: [], 9 | selectedTicket: {}, 10 | replyMsg: "", 11 | }; 12 | 13 | const ticketListSlice = createSlice({ 14 | name: "ticketList", 15 | initialState, 16 | reducers: { 17 | fetchTicketLoading: (state) => { 18 | state.isLoading = true; 19 | }, 20 | fetchTicketSuccess: (state, action) => { 21 | state.tickets = action.payload; 22 | state.searchTicketList = action.payload; 23 | state.isLoading = false; 24 | }, 25 | fetchTicketFail: (state, { payload }) => { 26 | state.isLoading = false; 27 | state.error = payload; 28 | }, 29 | searchTickets: (state, { payload }) => { 30 | state.searchTicketList = state.tickets.filter((row) => { 31 | if (!payload) return row; 32 | 33 | return row.subject.toLowerCase().includes(payload.toLowerCase()); 34 | }); 35 | }, 36 | fetchSingleTicketLoading: (state) => { 37 | state.isLoading = true; 38 | }, 39 | fetchSingleTicketSuccess: (state, { payload }) => { 40 | state.selectedTicket = payload; 41 | state.isLoading = false; 42 | state.error = ""; 43 | }, 44 | fetchSingleTicketFail: (state, { payload }) => { 45 | state.isLoading = false; 46 | state.error = payload; 47 | }, 48 | replyTicketLoading: (state) => { 49 | state.isLoading = true; 50 | }, 51 | replyTicketSuccess: (state, { payload }) => { 52 | state.isLoading = false; 53 | state.error = ""; 54 | state.replyMsg = payload; 55 | }, 56 | replyTicketFail: (state, { payload }) => { 57 | state.isLoading = false; 58 | state.replyTicketError = payload; 59 | }, 60 | closeTicketLoading: (state) => { 61 | state.isLoading = true; 62 | }, 63 | closeTicketSuccess: (state, { payload }) => { 64 | state.isLoading = false; 65 | state.error = ""; 66 | state.replyMsg = payload; 67 | }, 68 | closeTicketFail: (state, { payload }) => { 69 | state.isLoading = false; 70 | state.error = payload; 71 | }, 72 | resetResponseMsg: (state) => { 73 | state.isLoading = false; 74 | state.replyTicketError = ""; 75 | state.replyMsg = ""; 76 | }, 77 | }, 78 | }); 79 | 80 | const { reducer, actions } = ticketListSlice; 81 | 82 | export const { 83 | fetchTicketLoading, 84 | fetchTicketSuccess, 85 | fetchTicketFail, 86 | fetchSingleTicketLoading, 87 | fetchSingleTicketSuccess, 88 | fetchSingleTicketFail, 89 | replyTicketLoading, 90 | replyTicketSuccess, 91 | replyTicketFail, 92 | closeTicketLoading, 93 | closeTicketSuccess, 94 | closeTicketFail, 95 | searchTickets, 96 | resetResponseMsg, 97 | } = actions; 98 | 99 | export default reducer; 100 | -------------------------------------------------------------------------------- /src/pages/ticket/Ticket.page.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect } from "react"; 2 | import { useDispatch, useSelector } from "react-redux"; 3 | import { Container, Row, Col, Button, Spinner, Alert } from "react-bootstrap"; 4 | import { PageBreadcrumb } from "../../components/breadcrumb/Breadcrumb.comp"; 5 | import { MessageHistory } from "../../components/message-history/MessageHistory.comp"; 6 | import { UpdateTicket } from "../../components/update-ticket/UpdateTicket.comp"; 7 | import { useParams } from "react-router-dom"; 8 | 9 | import { fetchSingleTicket, closeTicket } from "../ticket-list/ticketsAction"; 10 | import { resetResponseMsg } from "../ticket-list/ticketsSlice"; 11 | 12 | export const Ticket = () => { 13 | const { tId } = useParams(); 14 | const dispatch = useDispatch(); 15 | const { 16 | isLoading, 17 | error, 18 | selectedTicket, 19 | replyMsg, 20 | replyTicketError, 21 | } = useSelector(state => state.tickets); 22 | 23 | useEffect(() => { 24 | dispatch(fetchSingleTicket(tId)); 25 | 26 | return () => { 27 | (replyMsg || replyTicketError) && dispatch(resetResponseMsg()); 28 | }; 29 | }, [tId, dispatch, replyMsg, replyTicketError]); 30 | 31 | return ( 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | {isLoading && } 42 | {error && {error}} 43 | {replyTicketError && ( 44 | {replyTicketError} 45 | )} 46 | {replyMsg && {replyMsg}} 47 | 48 | 49 | 50 | 51 |
Subject: {selectedTicket.subject}
52 |
53 | Ticket Opened:{" "} 54 | {selectedTicket.openAt && 55 | new Date(selectedTicket.openAt).toLocaleString()} 56 |
57 |
Status: {selectedTicket.status}
58 | 59 | 60 | 67 | 68 |
69 | 70 | 71 | {selectedTicket.conversations && ( 72 | 73 | )} 74 | 75 | 76 |
77 | 78 | 79 | 80 | 81 | 82 | 83 |
84 | ); 85 | }; 86 | -------------------------------------------------------------------------------- /src/pages/user-verification/UserVerification.page.js: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useState } from "react"; 2 | import { Jumbotron, Spinner, Alert } from "react-bootstrap"; 3 | import { useParams } from "react-router-dom"; 4 | 5 | import { userRegistrationVerification } from "../../api/userApi"; 6 | 7 | import "./userVerification.style.css"; 8 | 9 | const initialResponse = { 10 | status: "", 11 | message: "", 12 | }; 13 | export const UserVerification = () => { 14 | const { _id, email } = useParams(); 15 | const dt = { _id, email }; 16 | 17 | const [response, setResponse] = useState(initialResponse); 18 | 19 | useEffect(() => { 20 | const apiCall = async () => { 21 | const result = await userRegistrationVerification(dt); 22 | setResponse(result); 23 | }; 24 | 25 | !response.status && apiCall(); 26 | }, [response]); 27 | 28 | //call api and send the _id to verify user 29 | 30 | return ( 31 |
32 |
33 | 34 | {!response.status && } 35 | 36 | {response.status && ( 37 | 40 | {response.message} 41 | 42 | )} 43 | 44 |
45 |
46 | ); 47 | }; 48 | -------------------------------------------------------------------------------- /src/pages/user-verification/userVerification.style.css: -------------------------------------------------------------------------------- 1 | .registration-page { 2 | min-height: 100vh; 3 | display: flex; 4 | justify-content: center; 5 | align-items: center; 6 | } 7 | 8 | .form-box { 9 | box-shadow: 0px 0px 15px -5px black; 10 | } 11 | -------------------------------------------------------------------------------- /src/serviceWorker.js: -------------------------------------------------------------------------------- 1 | // This optional code is used to register a service worker. 2 | // register() is not called by default. 3 | 4 | // This lets the app load faster on subsequent visits in production, and gives 5 | // it offline capabilities. However, it also means that developers (and users) 6 | // will only see deployed updates on subsequent visits to a page, after all the 7 | // existing tabs open on the page have been closed, since previously cached 8 | // resources are updated in the background. 9 | 10 | // To learn more about the benefits of this model and instructions on how to 11 | // opt-in, read https://bit.ly/CRA-PWA 12 | 13 | const isLocalhost = Boolean( 14 | window.location.hostname === 'localhost' || 15 | // [::1] is the IPv6 localhost address. 16 | window.location.hostname === '[::1]' || 17 | // 127.0.0.0/8 are considered localhost for IPv4. 18 | window.location.hostname.match( 19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 20 | ) 21 | ); 22 | 23 | export function register(config) { 24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 25 | // The URL constructor is available in all browsers that support SW. 26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href); 27 | if (publicUrl.origin !== window.location.origin) { 28 | // Our service worker won't work if PUBLIC_URL is on a different origin 29 | // from what our page is served on. This might happen if a CDN is used to 30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 31 | return; 32 | } 33 | 34 | window.addEventListener('load', () => { 35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 36 | 37 | if (isLocalhost) { 38 | // This is running on localhost. Let's check if a service worker still exists or not. 39 | checkValidServiceWorker(swUrl, config); 40 | 41 | // Add some additional logging to localhost, pointing developers to the 42 | // service worker/PWA documentation. 43 | navigator.serviceWorker.ready.then(() => { 44 | console.log( 45 | 'This web app is being served cache-first by a service ' + 46 | 'worker. To learn more, visit https://bit.ly/CRA-PWA' 47 | ); 48 | }); 49 | } else { 50 | // Is not localhost. Just register service worker 51 | registerValidSW(swUrl, config); 52 | } 53 | }); 54 | } 55 | } 56 | 57 | function registerValidSW(swUrl, config) { 58 | navigator.serviceWorker 59 | .register(swUrl) 60 | .then(registration => { 61 | registration.onupdatefound = () => { 62 | const installingWorker = registration.installing; 63 | if (installingWorker == null) { 64 | return; 65 | } 66 | installingWorker.onstatechange = () => { 67 | if (installingWorker.state === 'installed') { 68 | if (navigator.serviceWorker.controller) { 69 | // At this point, the updated precached content has been fetched, 70 | // but the previous service worker will still serve the older 71 | // content until all client tabs are closed. 72 | console.log( 73 | 'New content is available and will be used when all ' + 74 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' 75 | ); 76 | 77 | // Execute callback 78 | if (config && config.onUpdate) { 79 | config.onUpdate(registration); 80 | } 81 | } else { 82 | // At this point, everything has been precached. 83 | // It's the perfect time to display a 84 | // "Content is cached for offline use." message. 85 | console.log('Content is cached for offline use.'); 86 | 87 | // Execute callback 88 | if (config && config.onSuccess) { 89 | config.onSuccess(registration); 90 | } 91 | } 92 | } 93 | }; 94 | }; 95 | }) 96 | .catch(error => { 97 | console.error('Error during service worker registration:', error); 98 | }); 99 | } 100 | 101 | function checkValidServiceWorker(swUrl, config) { 102 | // Check if the service worker can be found. If it can't reload the page. 103 | fetch(swUrl, { 104 | headers: { 'Service-Worker': 'script' }, 105 | }) 106 | .then(response => { 107 | // Ensure service worker exists, and that we really are getting a JS file. 108 | const contentType = response.headers.get('content-type'); 109 | if ( 110 | response.status === 404 || 111 | (contentType != null && contentType.indexOf('javascript') === -1) 112 | ) { 113 | // No service worker found. Probably a different app. Reload the page. 114 | navigator.serviceWorker.ready.then(registration => { 115 | registration.unregister().then(() => { 116 | window.location.reload(); 117 | }); 118 | }); 119 | } else { 120 | // Service worker found. Proceed as normal. 121 | registerValidSW(swUrl, config); 122 | } 123 | }) 124 | .catch(() => { 125 | console.log( 126 | 'No internet connection found. App is running in offline mode.' 127 | ); 128 | }); 129 | } 130 | 131 | export function unregister() { 132 | if ('serviceWorker' in navigator) { 133 | navigator.serviceWorker.ready 134 | .then(registration => { 135 | registration.unregister(); 136 | }) 137 | .catch(error => { 138 | console.error(error.message); 139 | }); 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom/extend-expect'; 6 | -------------------------------------------------------------------------------- /src/store.js: -------------------------------------------------------------------------------- 1 | import { configureStore } from "@reduxjs/toolkit"; 2 | 3 | import ticketsReducer from "./pages/ticket-list/ticketsSlice"; 4 | import loginReducer from "./components/login/loginSlice"; 5 | import userReducer from "./pages/dashboard/userSlice"; 6 | import newTicketReducer from "./components/add-ticket-form/addTicketSlicer"; 7 | import registrationReducer from "./components/registration-form/userRegestrationSlice"; 8 | import passwordReducer from "./components/password-reset/passwordSlice"; 9 | 10 | const store = configureStore({ 11 | reducer: { 12 | tickets: ticketsReducer, 13 | login: loginReducer, 14 | user: userReducer, 15 | openTicket: newTicketReducer, 16 | registration: registrationReducer, 17 | password: passwordReducer, 18 | }, 19 | }); 20 | 21 | export default store; 22 | -------------------------------------------------------------------------------- /src/utils/validation.js: -------------------------------------------------------------------------------- 1 | export const shortText = (str) => { 2 | return str.length >= 3 && str.length <= 100; 3 | }; 4 | --------------------------------------------------------------------------------