From 0f6efe7ec15e083482d938e6b7eabe15770918ba Mon Sep 17 00:00:00 2001 From: Mohammad Jalali Date: Mon, 23 Oct 2023 16:00:58 +0330 Subject: [PATCH] work on caller history part of widget and making fake data and work on that --- .../ErrorOrEmpty/__tests__/index.test.js | 0 .../CallHistory/ErrorOrEmpty/index.jsx | 33 +++++++ .../HistoryHeader/__tests__/index.test.js | 0 .../CallHistory/HistoryHeader/index.jsx | 25 +++++ .../PreviusOperatorData/index.jsx | 7 +- .../ListItemOfCalls/Topics/index.jsx | 6 +- .../CallHistory/ListItemOfCalls/index.jsx | 7 +- .../LoadingHistory/__tests__/intex.test.js | 0 .../CallHistory/LoadingHistory/index.jsx | 78 +++++++++++++++ .../CallTabPanel/CallHistory/index.jsx | 98 ++++++------------- src/lib/callWidget/hooks/useCallerHistory.jsx | 35 ++++++- 11 files changed, 207 insertions(+), 82 deletions(-) create mode 100644 src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/ErrorOrEmpty/__tests__/index.test.js create mode 100644 src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/ErrorOrEmpty/index.jsx create mode 100644 src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/HistoryHeader/__tests__/index.test.js create mode 100644 src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/HistoryHeader/index.jsx create mode 100644 src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/LoadingHistory/__tests__/intex.test.js create mode 100644 src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/LoadingHistory/index.jsx diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/ErrorOrEmpty/__tests__/index.test.js b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/ErrorOrEmpty/__tests__/index.test.js new file mode 100644 index 0000000..e69de29 diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/ErrorOrEmpty/index.jsx b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/ErrorOrEmpty/index.jsx new file mode 100644 index 0000000..bb0f818 --- /dev/null +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/ErrorOrEmpty/index.jsx @@ -0,0 +1,33 @@ +import {useTranslations} from "next-intl"; +import {Typography} from "@mui/material"; + +const ErrorOrEmpty = ({isErrorOrEmpty}) => { + const t = useTranslations(); + return ( + <> + {isErrorOrEmpty === "error" ? + + {t("CallHistory.call_history_error_fetching")} + + : isErrorOrEmpty === "empty" ? + + {t("CallHistory.call_history_not_found")} + : <> + } + + ) +} + +export default ErrorOrEmpty diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/HistoryHeader/__tests__/index.test.js b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/HistoryHeader/__tests__/index.test.js new file mode 100644 index 0000000..e69de29 diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/HistoryHeader/index.jsx b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/HistoryHeader/index.jsx new file mode 100644 index 0000000..21a3270 --- /dev/null +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/HistoryHeader/index.jsx @@ -0,0 +1,25 @@ +import {useTranslations} from "next-intl"; +import {Stack, Typography} from "@mui/material"; + +const HistoryHeader = ({tab}) => { + const t = useTranslations(); + return ( + + + .... {t("CallHistory.call_history_of")}: + + + {tab.phone_number} .... + + + ) +} + +export default HistoryHeader diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/ListItemOfCalls/PreviusOperatorData/index.jsx b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/ListItemOfCalls/PreviusOperatorData/index.jsx index 2ad8326..9610180 100644 --- a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/ListItemOfCalls/PreviusOperatorData/index.jsx +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/ListItemOfCalls/PreviusOperatorData/index.jsx @@ -2,7 +2,8 @@ import {useTranslations} from "next-intl"; import {Avatar, Box, ListItem, ListItemAvatar, ListItemText, Typography} from "@mui/material"; import HeadsetMicIcon from '@mui/icons-material/HeadsetMic'; -const PreviusOperatorData = ({tab}) => { +const PreviusOperatorData = ({historyItem}) => { + console.log(historyItem) const t = useTranslations(); return ( @@ -14,13 +15,13 @@ const PreviusOperatorData = ({tab}) => { - اشکان خطیبی + {historyItem.operator_name} ({t("CallHistory.operator")}) - } secondary="1379/02/03 13:50"/> + } secondary={historyItem.answer_date}/> ) } diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/ListItemOfCalls/Topics/index.jsx b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/ListItemOfCalls/Topics/index.jsx index b7bc4ed..0f2e832 100644 --- a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/ListItemOfCalls/Topics/index.jsx +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/ListItemOfCalls/Topics/index.jsx @@ -1,7 +1,7 @@ import {useTranslations} from "next-intl"; import {Box, List, ListItem, Typography} from "@mui/material"; -const Topics = ({tab}) => { +const Topics = ({historyItem}) => { const t = useTranslations(); return ( @@ -12,7 +12,7 @@ const Topics = ({tab}) => { {t("CallHistory.topic")}: - موضوع تست + {historyItem.topic} @@ -31,7 +31,7 @@ const Topics = ({tab}) => { textAlign: "end", color: "#837e7e" }}> - زیر موضوع تست با متن طولانی تر از موضوع + {historyItem.sub_topic} diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/ListItemOfCalls/index.jsx b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/ListItemOfCalls/index.jsx index 6dc06e0..7537d12 100644 --- a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/ListItemOfCalls/index.jsx +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/ListItemOfCalls/index.jsx @@ -3,13 +3,14 @@ import {Divider, List} from "@mui/material"; import PreviusOperatorData from "./PreviusOperatorData"; import Topics from "./Topics"; -const ListItemOfCalls = ({lastItem, tab}) => { +const ListItemOfCalls = ({lastItem, historyItem}) => { const t = useTranslations(); + console.log("historyItem", historyItem) return ( <> - - + + {!lastItem && } diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/LoadingHistory/__tests__/intex.test.js b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/LoadingHistory/__tests__/intex.test.js new file mode 100644 index 0000000..e69de29 diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/LoadingHistory/index.jsx b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/LoadingHistory/index.jsx new file mode 100644 index 0000000..c6cd59e --- /dev/null +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/LoadingHistory/index.jsx @@ -0,0 +1,78 @@ +import {useTranslations} from "next-intl"; +import {Box, List, ListItem, ListItemAvatar, ListItemText, Skeleton} from "@mui/material"; + +const LoadingHistory = () => { + const t = useTranslations(); + return ( + <> + + + + + + + + + } secondary={ + + }/> + + + + + + + + + + + + + + + + + + + + + + + ) +} + +export default LoadingHistory diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/index.jsx b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/index.jsx index 27c161f..f8ccb28 100644 --- a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/index.jsx +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallHistory/index.jsx @@ -1,13 +1,17 @@ import {useTranslations} from "next-intl"; -import {Box, Chip, Divider, List, ListItemAvatar, ListItemText, Skeleton, Stack, Typography} from "@mui/material"; -import ListItemOfCalls from "./ListItemOfCalls"; +import {Box, Chip, Divider, Stack} from "@mui/material"; import HeadphonesIcon from '@mui/icons-material/Headphones'; +import LoadingHistory from "./LoadingHistory"; +import HistoryHeader from "./HistoryHeader"; +import ErrorOrEmpty from "./ErrorOrEmpty"; +import useCallerHistory from "@/lib/callWidget/hooks/useCallerHistory"; +import ListItemOfCalls from "./ListItemOfCalls"; +import {useState} from "react"; const CallHistory = ({tab}) => { const t = useTranslations(); - // const {historyList, isLoadingHistoryList, errorHistoryList} = useCallerHistory(tab.id); - const errorHistoryList = false; - const isLoadingHistoryList = true; + const {historyList, isLoadingHistoryList, errorHistoryList} = useCallerHistory(tab.id); + const [showRestOfHistory, setShowRestOfHistory] = useState(false); const handleClick = () => { console.info('You clicked the Chip.'); }; @@ -16,82 +20,36 @@ const CallHistory = ({tab}) => { height: "100%", overflow: "hidden" }}> - - - .... {t("CallHistory.call_history_of")}: - - - {tab.phone_number} .... - - + {errorHistoryList ? ( - - {t("CallHistory.call_history_error_fetching")} - + ) : isLoadingHistoryList ? ( - <> - - - - - - - - } secondary={ - - }/> - - + ) : historyList.length === 0 ? ( - - {t("CallHistory.call_history_not_found")} - + ) : ( - + } - onClick={handleClick} - label="نمایش موارد بیشتر"> + onClick={() => setShowRestOfHistory(true)} + label="نمایش موارد بیشتر" + disabled={showRestOfHistory}> + {showRestOfHistory && ( + <> + {historyList.slice(2).map((historyItem, index) => ( + <> + + + + ))} + ) + } )} diff --git a/src/lib/callWidget/hooks/useCallerHistory.jsx b/src/lib/callWidget/hooks/useCallerHistory.jsx index 62a8ed2..1a334df 100644 --- a/src/lib/callWidget/hooks/useCallerHistory.jsx +++ b/src/lib/callWidget/hooks/useCallerHistory.jsx @@ -21,9 +21,38 @@ const useCallerHistory = (id) => { }); return { - historyList: data, - isLoadingHistoryList: isLoading, - errorHistoryList: !data + historyList: [ + { + id: 1, + operator_name: "اشکان خطیبی", + answer_date: "1379/02/03 13:50", + topic: "موضوع تست", + sub_topic: "زیر موضوع تست با متن طولانی تر از موضوع" + }, + { + id: 2, + operator_name: "مصیب خطیبی", + answer_date: "1385/01/23 23:10", + topic: "موضوع تست2", + sub_topic: "زیر موضوع تست با متن طولانی تر از موضوع2" + }, + { + id: 2, + operator_name: "علی جلالی", + answer_date: "1385/01/01 12:12", + topic: "موضوع تست23", + sub_topic: "زیر 22موضوع تست با متن طولانی تر از موضوع32" + }, + { + id: 2, + operator_name: "حسن محمودی", + answer_date: "1385/01/01 11:22", + topic: "موضوع اول", + sub_topic: "زیر دوم تست با متن طولانی تر از موضوع32" + } + ], + isLoadingHistoryList: false, + errorHistoryList: false } };