Fix form keyboard issues and sticky footers in agent screens
This commit is contained in:
@@ -0,0 +1,239 @@
|
||||
import { baseApi } from '../../../services/api/baseApi';
|
||||
import type {
|
||||
AgentDashboardStats,
|
||||
AgentCustomer,
|
||||
CollectionEntry,
|
||||
CommissionSummary,
|
||||
AgentLoanRequest,
|
||||
AgentRoute,
|
||||
SmsLog,
|
||||
CollectionReceipt,
|
||||
} from '../types/agentTypes';
|
||||
import {
|
||||
MOCK_DASHBOARD_STATS,
|
||||
MOCK_CUSTOMERS,
|
||||
MOCK_TODAY_COLLECTIONS,
|
||||
MOCK_COMMISSION_SUMMARY,
|
||||
MOCK_LOAN_REQUESTS,
|
||||
MOCK_ROUTE,
|
||||
MOCK_SMS_LOGS,
|
||||
} from '../utils/agentMockData';
|
||||
import { generateReceiptNumber } from '../utils/agentFormatters';
|
||||
|
||||
const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
|
||||
|
||||
export const agentApi = baseApi.injectEndpoints({
|
||||
endpoints: (builder) => ({
|
||||
// ── Dashboard ──────────────────────────────────────────
|
||||
getAgentDashboard: builder.query<AgentDashboardStats, void>({
|
||||
queryFn: async () => {
|
||||
await delay(600);
|
||||
return { data: MOCK_DASHBOARD_STATS };
|
||||
},
|
||||
providesTags: ['AgentDashboard'],
|
||||
}),
|
||||
|
||||
// ── Customers ──────────────────────────────────────────
|
||||
getAgentCustomers: builder.query<AgentCustomer[], void>({
|
||||
queryFn: async () => {
|
||||
await delay(500);
|
||||
return { data: MOCK_CUSTOMERS };
|
||||
},
|
||||
providesTags: ['AgentCustomers'],
|
||||
}),
|
||||
|
||||
addAgentCustomer: builder.mutation<AgentCustomer, Partial<AgentCustomer>>({
|
||||
queryFn: async (customer) => {
|
||||
await delay(400);
|
||||
const newCustomer: AgentCustomer = {
|
||||
id: `c${Date.now()}`,
|
||||
name: customer.name ?? '',
|
||||
phone: customer.phone ?? '',
|
||||
email: customer.email,
|
||||
address: customer.address ?? '',
|
||||
city: customer.city ?? '',
|
||||
state: customer.state ?? '',
|
||||
pincode: customer.pincode ?? '',
|
||||
status: 'active',
|
||||
kyc: customer.kyc ?? {
|
||||
aadhaarNumber: '',
|
||||
panNumber: '',
|
||||
aadhaarVerified: false,
|
||||
panVerified: false,
|
||||
status: 'pending',
|
||||
},
|
||||
accounts: [],
|
||||
dueAmount: 0,
|
||||
totalCollected: 0,
|
||||
joinedDate: new Date().toISOString(),
|
||||
};
|
||||
return { data: newCustomer };
|
||||
},
|
||||
invalidatesTags: ['AgentCustomers', 'AgentDashboard'],
|
||||
}),
|
||||
|
||||
updateAgentCustomer: builder.mutation<AgentCustomer, AgentCustomer>({
|
||||
queryFn: async (customer) => {
|
||||
await delay(300);
|
||||
return { data: customer };
|
||||
},
|
||||
invalidatesTags: ['AgentCustomers'],
|
||||
}),
|
||||
|
||||
deleteAgentCustomer: builder.mutation<{ id: string }, string>({
|
||||
queryFn: async (id) => {
|
||||
await delay(300);
|
||||
return { data: { id } };
|
||||
},
|
||||
invalidatesTags: ['AgentCustomers', 'AgentDashboard'],
|
||||
}),
|
||||
|
||||
// ── Collections ────────────────────────────────────────
|
||||
getTodayCollections: builder.query<CollectionEntry[], void>({
|
||||
queryFn: async () => {
|
||||
await delay(500);
|
||||
return { data: MOCK_TODAY_COLLECTIONS };
|
||||
},
|
||||
providesTags: ['AgentCollections'],
|
||||
}),
|
||||
|
||||
submitCollection: builder.mutation<CollectionReceipt, { entryId: string; amount: number; mode: string }>({
|
||||
queryFn: async (params) => {
|
||||
await delay(500);
|
||||
const receipt: CollectionReceipt = {
|
||||
id: `rcp-${Date.now()}`,
|
||||
collectionId: params.entryId,
|
||||
customerName: 'Customer',
|
||||
customerPhone: '9876543000',
|
||||
accountNumber: 'CBS00000000',
|
||||
amount: params.amount,
|
||||
date: new Date().toISOString(),
|
||||
mode: params.mode as any,
|
||||
agentName: 'Rajesh Kumar',
|
||||
agentCode: 'AGT-2024-0147',
|
||||
referenceNumber: generateReceiptNumber(),
|
||||
};
|
||||
return { data: receipt };
|
||||
},
|
||||
invalidatesTags: ['AgentCollections', 'AgentDashboard'],
|
||||
}),
|
||||
|
||||
getCollectionHistory: builder.query<CollectionEntry[], { from?: string; to?: string }>({
|
||||
queryFn: async () => {
|
||||
await delay(400);
|
||||
const history = MOCK_TODAY_COLLECTIONS.map(e => ({ ...e, collectedAt: '2026-05-17T10:00:00Z' }));
|
||||
return { data: history };
|
||||
},
|
||||
}),
|
||||
|
||||
// ── Commission ─────────────────────────────────────────
|
||||
getCommissionSummary: builder.query<CommissionSummary, void>({
|
||||
queryFn: async () => {
|
||||
await delay(500);
|
||||
return { data: MOCK_COMMISSION_SUMMARY };
|
||||
},
|
||||
providesTags: ['AgentCommission'],
|
||||
}),
|
||||
|
||||
// ── Loan Requests ──────────────────────────────────────
|
||||
getAgentLoanRequests: builder.query<AgentLoanRequest[], void>({
|
||||
queryFn: async () => {
|
||||
await delay(500);
|
||||
return { data: MOCK_LOAN_REQUESTS };
|
||||
},
|
||||
providesTags: ['AgentLoans'],
|
||||
}),
|
||||
|
||||
submitAgentLoanRequest: builder.mutation<AgentLoanRequest, Partial<AgentLoanRequest>>({
|
||||
queryFn: async (req) => {
|
||||
await delay(600);
|
||||
const newRequest: AgentLoanRequest = {
|
||||
id: `lr-${Date.now()}`,
|
||||
customerId: req.customerId ?? '',
|
||||
customerName: req.customerName ?? '',
|
||||
customerPhone: req.customerPhone ?? '',
|
||||
category: req.category ?? 'Personal',
|
||||
amount: req.amount ?? 0,
|
||||
tenureMonths: req.tenureMonths ?? 12,
|
||||
purpose: req.purpose ?? '',
|
||||
monthlyIncome: req.monthlyIncome ?? 0,
|
||||
status: 'submitted',
|
||||
appliedDate: new Date().toISOString(),
|
||||
lastUpdated: new Date().toISOString(),
|
||||
documents: req.documents ?? [],
|
||||
timeline: [{ stage: 'Submitted', timestamp: new Date().toISOString(), active: true }],
|
||||
};
|
||||
return { data: newRequest };
|
||||
},
|
||||
invalidatesTags: ['AgentLoans', 'AgentDashboard'],
|
||||
}),
|
||||
|
||||
// ── Route ──────────────────────────────────────────────
|
||||
getAgentRoute: builder.query<AgentRoute, void>({
|
||||
queryFn: async () => {
|
||||
await delay(400);
|
||||
return { data: MOCK_ROUTE };
|
||||
},
|
||||
}),
|
||||
|
||||
// ── SMS ────────────────────────────────────────────────
|
||||
getSmsLogs: builder.query<SmsLog[], void>({
|
||||
queryFn: async () => {
|
||||
await delay(400);
|
||||
return { data: MOCK_SMS_LOGS };
|
||||
},
|
||||
providesTags: ['AgentSms'],
|
||||
}),
|
||||
|
||||
sendSms: builder.mutation<SmsLog, { customerId: string; type: string; message: string }>({
|
||||
queryFn: async (params) => {
|
||||
await delay(500);
|
||||
const log: SmsLog = {
|
||||
id: `sms-${Date.now()}`,
|
||||
customerId: params.customerId,
|
||||
customerName: 'Customer',
|
||||
customerPhone: '9876543000',
|
||||
type: params.type as any,
|
||||
message: params.message,
|
||||
status: 'sent',
|
||||
sentAt: new Date().toISOString(),
|
||||
retryCount: 0,
|
||||
};
|
||||
return { data: log };
|
||||
},
|
||||
invalidatesTags: ['AgentSms'],
|
||||
}),
|
||||
|
||||
// ── Account Opening ────────────────────────────────────
|
||||
submitAccountOpening: builder.mutation<{ accountId: string; accountNumber: string }, any>({
|
||||
queryFn: async () => {
|
||||
await delay(800);
|
||||
return {
|
||||
data: {
|
||||
accountId: `acc-${Date.now()}`,
|
||||
accountNumber: `CBS${Date.now().toString().slice(-8)}`,
|
||||
},
|
||||
};
|
||||
},
|
||||
invalidatesTags: ['AgentCustomers', 'AgentDashboard'],
|
||||
}),
|
||||
}),
|
||||
});
|
||||
|
||||
export const {
|
||||
useGetAgentDashboardQuery,
|
||||
useGetAgentCustomersQuery,
|
||||
useAddAgentCustomerMutation,
|
||||
useUpdateAgentCustomerMutation,
|
||||
useDeleteAgentCustomerMutation,
|
||||
useGetTodayCollectionsQuery,
|
||||
useSubmitCollectionMutation,
|
||||
useGetCollectionHistoryQuery,
|
||||
useGetCommissionSummaryQuery,
|
||||
useGetAgentLoanRequestsQuery,
|
||||
useSubmitAgentLoanRequestMutation,
|
||||
useGetAgentRouteQuery,
|
||||
useGetSmsLogsQuery,
|
||||
useSendSmsMutation,
|
||||
useSubmitAccountOpeningMutation,
|
||||
} = agentApi;
|
||||
Reference in New Issue
Block a user