NeoScan_Physician/app/modules/Dashboard/redux/dashboardActions.ts

38 lines
1.2 KiB
TypeScript

/*
* File: dashboardActions.ts
* Description: Async actions (thunks) for Dashboard state
* Design & Developed by Tech4Biz Solutions
* Copyright (c) Spurrin Innovations. All rights reserved.
*/
import { createAsyncThunk } from '@reduxjs/toolkit';
import { fetchCasesStart, fetchCasesSuccess, fetchCasesFailure } from './dashboardSlice';
import { caseAPI } from '../services/caseAPI';
/**
* Thunk to fetch case queue from API
*/
export const fetchCases = createAsyncThunk(
'dashboard/fetchCases',
async (_, { dispatch, rejectWithValue }) => {
try {
dispatch(fetchCasesStart());
const response = await caseAPI.getCases();
if (response.ok && response.data) {
dispatch(fetchCasesSuccess(response.data));
} else {
dispatch(fetchCasesFailure(response.problem || 'Unknown error'));
return rejectWithValue(response.problem || 'Unknown error');
}
} catch (error: any) {
dispatch(fetchCasesFailure(error.message));
return rejectWithValue(error.message);
}
}
);
/*
* End of File: dashboardActions.ts
* Design & Developed by Tech4Biz Solutions
* Copyright (c) Spurrin Innovations. All rights reserved.
*/