mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 23:35:45 +00:00
refactor(FE-174): enhance RecordingApi by adding approve and reject methods for better approval handling
This commit is contained in:
@@ -226,16 +226,10 @@ const RecordingTable = () => {
|
|||||||
const bulkApproveHandler = async () => {
|
const bulkApproveHandler = async () => {
|
||||||
setIsBulkApproveLoading(true);
|
setIsBulkApproveLoading(true);
|
||||||
|
|
||||||
const approveResponse = await RecordingApi.customRequest<
|
const approveResponse = await RecordingApi.approve(
|
||||||
BaseApiResponse<Recording[]>
|
selectedRowIds,
|
||||||
>('approvals', {
|
'Bulk Approved'
|
||||||
method: 'POST',
|
);
|
||||||
payload: {
|
|
||||||
action: 'APPROVED',
|
|
||||||
approvable_ids: selectedRowIds,
|
|
||||||
notes: 'Bulk Approved',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (isResponseSuccess(approveResponse)) {
|
if (isResponseSuccess(approveResponse)) {
|
||||||
await refreshRecordings();
|
await refreshRecordings();
|
||||||
@@ -255,16 +249,10 @@ const RecordingTable = () => {
|
|||||||
const bulkRejectHandler = async () => {
|
const bulkRejectHandler = async () => {
|
||||||
setIsBulkRejectLoading(true);
|
setIsBulkRejectLoading(true);
|
||||||
|
|
||||||
const rejectResponse = await RecordingApi.customRequest<
|
const rejectResponse = await RecordingApi.reject(
|
||||||
BaseApiResponse<Recording[]>
|
selectedRowIds,
|
||||||
>('approvals', {
|
'Bulk Rejected'
|
||||||
method: 'POST',
|
);
|
||||||
payload: {
|
|
||||||
action: 'REJECTED',
|
|
||||||
approvable_ids: selectedRowIds,
|
|
||||||
notes: 'Bulk Rejected',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (isResponseSuccess(rejectResponse)) {
|
if (isResponseSuccess(rejectResponse)) {
|
||||||
refreshRecordings();
|
refreshRecordings();
|
||||||
|
|||||||
@@ -696,16 +696,10 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
const approveHandler = async () => {
|
const approveHandler = async () => {
|
||||||
setIsApproveLoading(true);
|
setIsApproveLoading(true);
|
||||||
|
|
||||||
const approveResponse = await RecordingApi.customRequest<
|
const approveResponse = await RecordingApi.approve(
|
||||||
BaseApiResponse<Recording[]>
|
initialValues?.id as number,
|
||||||
>('approvals', {
|
'Approved via Form'
|
||||||
method: 'POST',
|
);
|
||||||
payload: {
|
|
||||||
action: 'APPROVED',
|
|
||||||
approvable_ids: [initialValues?.id as number],
|
|
||||||
notes: 'Approved via Form',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (isResponseSuccess(approveResponse)) {
|
if (isResponseSuccess(approveResponse)) {
|
||||||
toast.success('Recording berhasil disetujui!');
|
toast.success('Recording berhasil disetujui!');
|
||||||
@@ -724,16 +718,10 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
const rejectHandler = async () => {
|
const rejectHandler = async () => {
|
||||||
setIsRejectLoading(true);
|
setIsRejectLoading(true);
|
||||||
|
|
||||||
const rejectResponse = await RecordingApi.customRequest<
|
const rejectResponse = await RecordingApi.reject(
|
||||||
BaseApiResponse<Recording[]>
|
initialValues?.id as number,
|
||||||
>('approvals', {
|
'Rejected via Form'
|
||||||
method: 'POST',
|
);
|
||||||
payload: {
|
|
||||||
action: 'REJECTED',
|
|
||||||
approvable_ids: [initialValues?.id as number],
|
|
||||||
notes: 'Rejected via Form',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (isResponseSuccess(rejectResponse)) {
|
if (isResponseSuccess(rejectResponse)) {
|
||||||
toast.success('Recording berhasil ditolak!');
|
toast.success('Recording berhasil ditolak!');
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { BaseApiService } from './base';
|
import { BaseApiService } from './base';
|
||||||
|
import { BaseApiResponse } from '@/types/api/api-general';
|
||||||
import {
|
import {
|
||||||
CreateProjectFlockPayload,
|
CreateProjectFlockPayload,
|
||||||
ProjectFlock,
|
ProjectFlock,
|
||||||
@@ -20,11 +21,47 @@ export const ProjectFlockApi = new BaseApiService<
|
|||||||
CreateProjectFlockPayload,
|
CreateProjectFlockPayload,
|
||||||
UpdateProjectFlockPayload
|
UpdateProjectFlockPayload
|
||||||
>('/production/project_flocks');
|
>('/production/project_flocks');
|
||||||
export const RecordingApi = new BaseApiService<
|
export class RecordingService extends BaseApiService<
|
||||||
Recording,
|
Recording,
|
||||||
CreateRecordingPayload,
|
CreateRecordingPayload,
|
||||||
UpdateRecordingPayload
|
UpdateRecordingPayload
|
||||||
>('/production/recordings');
|
> {
|
||||||
|
constructor(basePath: string = '') {
|
||||||
|
super(basePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
async approve(
|
||||||
|
idOrIds: number | number[],
|
||||||
|
notes: string = 'Approved via Form'
|
||||||
|
): Promise<BaseApiResponse<Recording[]> | undefined> {
|
||||||
|
const approvable_ids = Array.isArray(idOrIds) ? idOrIds : [idOrIds];
|
||||||
|
return await this.customRequest<BaseApiResponse<Recording[]>>('approvals', {
|
||||||
|
method: 'POST',
|
||||||
|
payload: {
|
||||||
|
action: 'APPROVED',
|
||||||
|
approvable_ids,
|
||||||
|
notes,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async reject(
|
||||||
|
idOrIds: number | number[],
|
||||||
|
notes: string = 'Rejected via Form'
|
||||||
|
): Promise<BaseApiResponse<Recording[]> | undefined> {
|
||||||
|
const approvable_ids = Array.isArray(idOrIds) ? idOrIds : [idOrIds];
|
||||||
|
return await this.customRequest<BaseApiResponse<Recording[]>>('approvals', {
|
||||||
|
method: 'POST',
|
||||||
|
payload: {
|
||||||
|
action: 'REJECTED',
|
||||||
|
approvable_ids,
|
||||||
|
notes,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const RecordingApi = new RecordingService('/production/recordings');
|
||||||
export const ChickinApi = new BaseApiService<
|
export const ChickinApi = new BaseApiService<
|
||||||
Chickin,
|
Chickin,
|
||||||
CreateChickinPayload,
|
CreateChickinPayload,
|
||||||
|
|||||||
Reference in New Issue
Block a user