feat: add withdraw request functionality and UI components
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import axios from "axios";
|
||||
import { Inertia } from '@inertiajs/inertia'
|
||||
|
||||
export const useWithdrawRequestStore = defineStore('WithdrawRequestStore', {
|
||||
state: () => ({
|
||||
columns: [
|
||||
{
|
||||
key: 'id',
|
||||
title: 'شناسه',
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
key: 'user',
|
||||
title: 'درخواستکننده',
|
||||
slot: 'user',
|
||||
},
|
||||
{
|
||||
key: 'amount',
|
||||
title: 'مبلغ',
|
||||
render: (data) => `${Number(data.amount).toLocaleString('fa-IR')} تومان`,
|
||||
},
|
||||
{
|
||||
key: 'bank_card',
|
||||
title: 'کارت مقصد',
|
||||
slot: 'bank_card',
|
||||
width: 220,
|
||||
},
|
||||
{
|
||||
key: 'status',
|
||||
title: 'وضعیت',
|
||||
slot: 'status',
|
||||
},
|
||||
{
|
||||
key: 'created_at',
|
||||
title: 'تاریخ درخواست',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
key: 'reviewed_by',
|
||||
title: 'بررسیکننده',
|
||||
render: (data) => data.reviewed_by ? `${data.reviewed_by.fullname} - ${data.reviewed_at}` : 'بررسی نشده',
|
||||
},
|
||||
{
|
||||
key: 'actions',
|
||||
title: 'عملیات',
|
||||
hasSort: false,
|
||||
slot: true,
|
||||
},
|
||||
],
|
||||
endpoints: {
|
||||
index: '/admin/withdraw-requests',
|
||||
approve: (id) => `/admin/withdraw-requests/${id}/approve`,
|
||||
reject: (id) => `/admin/withdraw-requests/${id}/reject`,
|
||||
}
|
||||
}),
|
||||
|
||||
getters: {
|
||||
indexPageTitle: () => {
|
||||
return 'درخواستهای برداشت';
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
approve(id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.post(this.endpoints.approve(id))
|
||||
.then(response => {
|
||||
Inertia.get(this.endpoints.index);
|
||||
resolve(response);
|
||||
})
|
||||
.catch(error => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
reject(id, note) {
|
||||
return new Promise((resolve, rejectPromise) => {
|
||||
axios.post(this.endpoints.reject(id), { note })
|
||||
.then(response => {
|
||||
Inertia.get(this.endpoints.index);
|
||||
resolve(response);
|
||||
})
|
||||
.catch(error => {
|
||||
rejectPromise(error);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
search(params) {
|
||||
return Inertia.get(this.endpoints.index, params, {
|
||||
preserveState: false
|
||||
});
|
||||
},
|
||||
|
||||
navigateToPage(page) {
|
||||
return Inertia.get(this.endpoints.index, { page }, { preserveState: true });
|
||||
},
|
||||
|
||||
getStatusSeverity(status) {
|
||||
const statusSeverities = {
|
||||
'در انتظار بررسی': 'warning',
|
||||
'تایید شده': 'success',
|
||||
'رد شده': 'danger',
|
||||
};
|
||||
return statusSeverities[status] || 'secondary';
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user