mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +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 () => {
|
||||
setIsBulkApproveLoading(true);
|
||||
|
||||
const approveResponse = await RecordingApi.customRequest<
|
||||
BaseApiResponse<Recording[]>
|
||||
>('approvals', {
|
||||
method: 'POST',
|
||||
payload: {
|
||||
action: 'APPROVED',
|
||||
approvable_ids: selectedRowIds,
|
||||
notes: 'Bulk Approved',
|
||||
},
|
||||
});
|
||||
const approveResponse = await RecordingApi.approve(
|
||||
selectedRowIds,
|
||||
'Bulk Approved'
|
||||
);
|
||||
|
||||
if (isResponseSuccess(approveResponse)) {
|
||||
await refreshRecordings();
|
||||
@@ -255,16 +249,10 @@ const RecordingTable = () => {
|
||||
const bulkRejectHandler = async () => {
|
||||
setIsBulkRejectLoading(true);
|
||||
|
||||
const rejectResponse = await RecordingApi.customRequest<
|
||||
BaseApiResponse<Recording[]>
|
||||
>('approvals', {
|
||||
method: 'POST',
|
||||
payload: {
|
||||
action: 'REJECTED',
|
||||
approvable_ids: selectedRowIds,
|
||||
notes: 'Bulk Rejected',
|
||||
},
|
||||
});
|
||||
const rejectResponse = await RecordingApi.reject(
|
||||
selectedRowIds,
|
||||
'Bulk Rejected'
|
||||
);
|
||||
|
||||
if (isResponseSuccess(rejectResponse)) {
|
||||
refreshRecordings();
|
||||
|
||||
@@ -696,16 +696,10 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
const approveHandler = async () => {
|
||||
setIsApproveLoading(true);
|
||||
|
||||
const approveResponse = await RecordingApi.customRequest<
|
||||
BaseApiResponse<Recording[]>
|
||||
>('approvals', {
|
||||
method: 'POST',
|
||||
payload: {
|
||||
action: 'APPROVED',
|
||||
approvable_ids: [initialValues?.id as number],
|
||||
notes: 'Approved via Form',
|
||||
},
|
||||
});
|
||||
const approveResponse = await RecordingApi.approve(
|
||||
initialValues?.id as number,
|
||||
'Approved via Form'
|
||||
);
|
||||
|
||||
if (isResponseSuccess(approveResponse)) {
|
||||
toast.success('Recording berhasil disetujui!');
|
||||
@@ -724,16 +718,10 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
const rejectHandler = async () => {
|
||||
setIsRejectLoading(true);
|
||||
|
||||
const rejectResponse = await RecordingApi.customRequest<
|
||||
BaseApiResponse<Recording[]>
|
||||
>('approvals', {
|
||||
method: 'POST',
|
||||
payload: {
|
||||
action: 'REJECTED',
|
||||
approvable_ids: [initialValues?.id as number],
|
||||
notes: 'Rejected via Form',
|
||||
},
|
||||
});
|
||||
const rejectResponse = await RecordingApi.reject(
|
||||
initialValues?.id as number,
|
||||
'Rejected via Form'
|
||||
);
|
||||
|
||||
if (isResponseSuccess(rejectResponse)) {
|
||||
toast.success('Recording berhasil ditolak!');
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { BaseApiService } from './base';
|
||||
import { BaseApiResponse } from '@/types/api/api-general';
|
||||
import {
|
||||
CreateProjectFlockPayload,
|
||||
ProjectFlock,
|
||||
@@ -20,11 +21,47 @@ export const ProjectFlockApi = new BaseApiService<
|
||||
CreateProjectFlockPayload,
|
||||
UpdateProjectFlockPayload
|
||||
>('/production/project_flocks');
|
||||
export const RecordingApi = new BaseApiService<
|
||||
export class RecordingService extends BaseApiService<
|
||||
Recording,
|
||||
CreateRecordingPayload,
|
||||
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<
|
||||
Chickin,
|
||||
CreateChickinPayload,
|
||||
|
||||
Reference in New Issue
Block a user