Merge branch 'feature/CFE-1_implemention_of_history_in_call_widget' into 'develop'
CFE-1 complete programing part of call history of callwidget just need to work... See merge request witel-front-end/crm-app!29
This commit is contained in:
37
src/lib/callWidget/hooks/useCallerHistory.jsx
Normal file
37
src/lib/callWidget/hooks/useCallerHistory.jsx
Normal file
@@ -0,0 +1,37 @@
|
||||
import useRequest from "@/lib/app/hooks/useRequest";
|
||||
import {useEffect, useState} from "react";
|
||||
import useSWR from "swr";
|
||||
import {GET_CALLER_HISTORY} from "@/core/data/apiRoutes";
|
||||
|
||||
const useCallerHistory = (call_id, phone_number, max_size) => {
|
||||
const requestServer = useRequest({auth: true, notification: false});
|
||||
const [validData, setValidData] = useState([]);
|
||||
|
||||
//swr config
|
||||
const fetcher = (...args) => {
|
||||
return requestServer(args, 'get').then(({data}) => {
|
||||
return data.data;
|
||||
}).catch(() => {
|
||||
})
|
||||
};
|
||||
|
||||
const {data, isLoading} = useSWR(`${GET_CALLER_HISTORY}?phone_number=${phone_number}&size=${max_size}`, fetcher, {
|
||||
revalidateIfStale: false,
|
||||
revalidateOnFocus: false,
|
||||
revalidateOnReconnect: false,
|
||||
keepPreviousData: true
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
data && setValidData(data.filter((item) => item.id != call_id));
|
||||
}, [data, call_id]);
|
||||
|
||||
return {
|
||||
firstItemOfHistory: validData.length === 0 ? false : validData[0],
|
||||
historyList: validData.length < 2 ? false : validData.slice(1),
|
||||
isLoadingHistoryList: true,
|
||||
errorHistoryList: false
|
||||
}
|
||||
};
|
||||
|
||||
export default useCallerHistory;
|
||||
Reference in New Issue
Block a user