diff --git a/src/Lib/Features/getQueuedTaskDetails.js b/src/Lib/Features/getQueuedTaskDetails.js index c4b085b3..da550567 100644 --- a/src/Lib/Features/getQueuedTaskDetails.js +++ b/src/Lib/Features/getQueuedTaskDetails.js @@ -6,11 +6,55 @@ import API from "@/app/actions/api" import ENDPOINTS from "@/config/apiendpoint" import constants from "@/Constants/constants"; +const initialState = { + data: [], +}; + +export const getQueuedTaskDetailsReducer = (state = initialState, action) => { + switch (action.type) { + case constants.GET_QUEUED_TASK_DETAILS: + return { + ...state, + data: action.payload, + }; + + default: + return state; + } +}; export default class GetQueuedTaskDetailsAPI extends API { constructor(taskId, timeout = 2000) { super("GET", timeout, false); this.type = constants.GET_QUEUED_TASK_DETAILS; this.endpoint = `${super.apiEndPointAuto()}/tasks/get_celery_tasks`; + this.taskId = taskId; + } + async call() { + try { + const url = this.taskId + ? `${this.apiEndPoint()}?task_id=${this.taskId}` + : this.apiEndPoint(); + const response = await fetch(url, { + method: this.method, + headers: { + "Content-Type": "application/json", + Authorization: `JWT ${localStorage.getItem("anudesh_access_token")}`, + }, + }); + + if (!response.ok) { + throw new Error(`API call failed with status ${response.status}`); + } + + const data = await response.json(); + return { + type: this.type, + payload: data, + }; + } catch (error) { + console.error("API call failed:", error); + throw error; + } } processResponse(res) { @@ -18,13 +62,16 @@ export default class GetQueuedTaskDetailsAPI extends API { if (res) { this.queuedTaskDetails = res; } + return this.getActionPayload(); } apiEndPoint() { return this.endpoint; } - getBody() {} + getBody() { + return null; + } getHeaders() { this.headers = { @@ -36,7 +83,11 @@ export default class GetQueuedTaskDetailsAPI extends API { return this.headers; } - getPayload() { - return this.queuedTaskDetails + getActionPayload() { + const action = { + type: this.type, + payload: this.queuedTaskDetails, + }; + return action; } } diff --git a/src/Lib/Store.js b/src/Lib/Store.js index ef383f33..5ea3360d 100644 --- a/src/Lib/Store.js +++ b/src/Lib/Store.js @@ -61,6 +61,7 @@ import getMetaAnalyticsData from './Features/Analytics/getMetaAnalyticsData'; import getGuestWorkspaces from './Features/getGuestWorkspaces'; import getAnnotationsTask from './Features/projects/getAnnotationsTask'; import getTaskDetails from './Features/getTaskDetails'; +import {getQueuedTaskDetailsReducer} from './Features/getQueuedTaskDetails'; import GlossarysentenceAPI from './Features/actions/GlossarysentenceAPI'; import AddGlossary from './Features/actions/AddGlossary'; import getDomain from './Features/actions/getDomain'; @@ -120,6 +121,7 @@ const makeStore = () => { domains: domainsReducer, projects: projectsReducer, user: userReducer, + getQueuedTaskDetails:getQueuedTaskDetailsReducer, SendOrganizationUserReports:SendOrganizationUserReports, GetOrganizationUserReports:GetOrganizationUserReports, GetOrganizationDetailedProjectReports:GetOrganizationDetailedProjectReports, diff --git a/src/app/ui/pages/admin/QueuedTasksDetails.jsx b/src/app/ui/pages/admin/QueuedTasksDetails.jsx index 19157027..ba20fdea 100644 --- a/src/app/ui/pages/admin/QueuedTasksDetails.jsx +++ b/src/app/ui/pages/admin/QueuedTasksDetails.jsx @@ -24,8 +24,19 @@ const QueuedTasksDetails = (props) => { }); const [tableData, setTableData] = useState([]) const [queuedTaskData,setQueuedTaskData] = useState([]) + const UserDetail = useSelector((state) => { + return state.getQueuedTaskDetails?.data; + }); + useEffect(() => { + const fetchQueuedTasks = async () => { + const apiInstance = new GetQueuedTaskDetailsAPI(); + const action = await apiInstance.call(); + dispatch(action); + }; + + fetchQueuedTasks(); + }, [dispatch]); - const UserDetail = useSelector((state) => state.getQueuedTaskDetails?.data); const apiLoading = useSelector((state) => state.apiStatus.loading); const SearchQueuedTasks = useSelector( (state) => state.SearchProjectCards?.data @@ -72,7 +83,7 @@ const QueuedTasksDetails = (props) => { const pageSearch = (data) => { return data.filter((el) => { - if (SearchQueuedTasks == "") { + if (!SearchQueuedTasks || SearchQueuedTasks === "") { return el; } else if ( el.name?.toLowerCase().includes(SearchQueuedTasks?.toLowerCase())