From bfdf586b20a6f0a6f3aec6c1076cf8302230294c Mon Sep 17 00:00:00 2001 From: AminGhasempoor Date: Sun, 19 Nov 2023 10:56:21 +0330 Subject: [PATCH 1/3] CFE-16 fixed pending notification and success notification --- .../CallTabPanel/CallActions/index.jsx | 2 +- src/lib/callWidget/contexts/answers.jsx | 37 ++++++++++--------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/index.jsx b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/index.jsx index 082d701..b2dc9de 100644 --- a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/index.jsx +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/index.jsx @@ -21,7 +21,7 @@ function CallActions({tab}) { description }, success: { - notification: {show: false}, + notification: {show: true}, }, }) .then(() => { diff --git a/src/lib/callWidget/contexts/answers.jsx b/src/lib/callWidget/contexts/answers.jsx index 96a150c..ac6d4cc 100644 --- a/src/lib/callWidget/contexts/answers.jsx +++ b/src/lib/callWidget/contexts/answers.jsx @@ -1,5 +1,5 @@ -import { createContext, useEffect, useReducer, useState } from "react"; -import { GET_CATEGORY } from "@/core/data/apiRoutes"; +import {createContext, useEffect, useReducer, useState} from "react"; +import {GET_CATEGORY} from "@/core/data/apiRoutes"; import useRequest from "@/lib/app/hooks/useRequest"; const reducer = (state, action) => { @@ -7,11 +7,11 @@ const reducer = (state, action) => { case "CHANGE_ACTIVE_TAB": return state.map((answer, index) => action.newValue === index - ? { ...answer, active: true } + ? {...answer, active: true} : { - ...answer, - active: false, - } + ...answer, + active: false, + } ); case "CHANGE_LIST": return [...action.newList]; @@ -19,10 +19,10 @@ const reducer = (state, action) => { return state.map((answer, index) => action.tab_id === answer.id ? { - ...answer, - active_category_id: action.category_id, - } - : { ...answer } + ...answer, + active_category_id: action.category_id, + } + : {...answer} ); default: return state; @@ -32,17 +32,17 @@ const reducer = (state, action) => { const submission = (handleCategories, operation) => { switch (operation.type) { case "SET_CATEGORIES": - return { ...handleCategories, categoryLists: operation.categoriesByAPI }; + return {...handleCategories, categoryLists: operation.categoriesByAPI}; case "SET_SUBCATEGORIES": - return { ...handleCategories, subCategoryLists: operation.subCategoriesByAPI }; + return {...handleCategories, subCategoryLists: operation.subCategoriesByAPI}; default: return handleCategories; } }; export const AnswersContext = createContext(); -export const AnswersProvider = ({ children }) => { - const requestServer = useRequest({ auth: true, notification: false }); +export const AnswersProvider = ({children}) => { + const requestServer = useRequest({auth: true, notification: false}); const [openCallDialog, setOpenCallDialog] = useState(false); const [activeTab, setActiveTab] = useState(0); const [handleCategories, operation] = useReducer(submission, { @@ -53,7 +53,7 @@ export const AnswersProvider = ({ children }) => { useEffect(() => { requestServer(GET_CATEGORY, "get") - .then(({ data }) => { + .then(({data}) => { const subCategoriesByAPI = data.data; const categoriesByAPI = subCategoriesByAPI.reduce((accumulator, currentValue) => { if (!accumulator.find((item) => item.category_id === currentValue.category_id)) { @@ -61,10 +61,11 @@ export const AnswersProvider = ({ children }) => { } return accumulator; }, []); - operation({ type: "SET_CATEGORIES", categoriesByAPI }); - operation({ type: "SET_SUBCATEGORIES", subCategoriesByAPI }); + operation({type: "SET_CATEGORIES", categoriesByAPI}); + operation({type: "SET_SUBCATEGORIES", subCategoriesByAPI}); }) - .catch(() => {}); + .catch(() => { + }); }, []); return ( From f2cdf2eb9d18346f1fb65d522f0158958f9e2bee Mon Sep 17 00:00:00 2001 From: AminGhasempoor Date: Sun, 19 Nov 2023 14:23:53 +0330 Subject: [PATCH 2/3] CFE-16 delete description validation --- .../CallTabs/CallTabPanel/CallActions/index.jsx | 5 +---- src/lib/callWidget/contexts/answers.jsx | 8 +++++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/index.jsx b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/index.jsx index b2dc9de..f93ad56 100644 --- a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/index.jsx +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/index.jsx @@ -9,7 +9,7 @@ import {useState} from "react"; import {Stack} from "@mui/material"; function CallActions({tab}) { - const [description, setDescription] = useState('') + const [description, setDescription] = useState() const requestServer = useRequest({auth: true}); const {closeAnswerTab} = useAnswers(); @@ -20,9 +20,6 @@ function CallActions({tab}) { subcategory_id, description }, - success: { - notification: {show: true}, - }, }) .then(() => { closeAnswerTab(tab.id); diff --git a/src/lib/callWidget/contexts/answers.jsx b/src/lib/callWidget/contexts/answers.jsx index ac6d4cc..139ba88 100644 --- a/src/lib/callWidget/contexts/answers.jsx +++ b/src/lib/callWidget/contexts/answers.jsx @@ -49,7 +49,13 @@ export const AnswersProvider = ({children}) => { categoryLists: [], subCategoryLists: [], }); - const [state, dispatch] = useReducer(reducer, []); + const [state, dispatch] = useReducer(reducer, [{ + id: 1, + phone_number: '09134849737', + date: new Date(), + active: true, + active_category_id: 1, + }]); useEffect(() => { requestServer(GET_CATEGORY, "get") From 3d488e622041128bd0a5429371ad400042c37833 Mon Sep 17 00:00:00 2001 From: AminGhasempoor Date: Mon, 20 Nov 2023 11:15:50 +0330 Subject: [PATCH 3/3] CFE-16 description validating --- .../CallTabs/CallTabPanel/CallActions/index.jsx | 16 +++++++++------- src/lib/callWidget/contexts/answers.jsx | 8 +------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/index.jsx b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/index.jsx index f93ad56..837d354 100644 --- a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/index.jsx +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/index.jsx @@ -2,24 +2,26 @@ import CallActionsCategories from "./CallActionCategories"; import CallActionsSubcategories from "./CallActionSubcategories"; import ActionHeader from "./ActionHeader"; import CallActionDescription from "./CallActionDescription"; -import {CALL_ACTION} from "@/core/data/apiRoutes"; import useRequest from "@/lib/app/hooks/useRequest"; import useAnswers from "@/lib/callWidget/hooks/useAnswers"; import {useState} from "react"; import {Stack} from "@mui/material"; +import {CALL_ACTION} from "@/core/data/apiRoutes"; function CallActions({tab}) { - const [description, setDescription] = useState() + const [description, setDescription] = useState("") const requestServer = useRequest({auth: true}); const {closeAnswerTab} = useAnswers(); const handleSubcategoryButton = (category_id, subcategory_id) => { + let data = {} + data['category_id'] = category_id + data['subcategory_id'] = subcategory_id + if (description !== "") + data["description"] = description + requestServer(`${CALL_ACTION}/${tab.id}`, "post", { - data: { - category_id, - subcategory_id, - description - }, + data }) .then(() => { closeAnswerTab(tab.id); diff --git a/src/lib/callWidget/contexts/answers.jsx b/src/lib/callWidget/contexts/answers.jsx index 139ba88..ac6d4cc 100644 --- a/src/lib/callWidget/contexts/answers.jsx +++ b/src/lib/callWidget/contexts/answers.jsx @@ -49,13 +49,7 @@ export const AnswersProvider = ({children}) => { categoryLists: [], subCategoryLists: [], }); - const [state, dispatch] = useReducer(reducer, [{ - id: 1, - phone_number: '09134849737', - date: new Date(), - active: true, - active_category_id: 1, - }]); + const [state, dispatch] = useReducer(reducer, []); useEffect(() => { requestServer(GET_CATEGORY, "get")