added payment setting page and quota
This commit is contained in:
34
src/features/paymentSettings/api/paymentSettingsApi.ts
Normal file
34
src/features/paymentSettings/api/paymentSettingsApi.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import apiClient from "@/lib/api/client";
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
|
||||
export interface PaymentSettings {
|
||||
bankFeeTmt: number;
|
||||
gbusFeeTmt: number;
|
||||
sberBankFeeTmt: number;
|
||||
tvebFeeUsd: number;
|
||||
maxAmountUsd: number;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface PaymentSettingsPayload {
|
||||
bankFeeTmt: number;
|
||||
gbusFeeTmt: number;
|
||||
sberBankFeeTmt: number;
|
||||
tvebFeeUsd: number;
|
||||
maxAmountUsd: number;
|
||||
}
|
||||
|
||||
// ─── API ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
export const paymentSettingsApi = {
|
||||
async get(): Promise<PaymentSettings> {
|
||||
const { data } = await apiClient.get<PaymentSettings>("/payment-settings");
|
||||
return data;
|
||||
},
|
||||
|
||||
async update(payload: PaymentSettingsPayload): Promise<PaymentSettings> {
|
||||
const { data } = await apiClient.put<PaymentSettings>("/payment-settings", payload);
|
||||
return data;
|
||||
},
|
||||
};
|
||||
33
src/features/paymentSettings/hooks/usePaymentSettings.ts
Normal file
33
src/features/paymentSettings/hooks/usePaymentSettings.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { toast } from "sonner";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { paymentSettingsApi, type PaymentSettingsPayload } from "../api/paymentSettingsApi";
|
||||
|
||||
// ─── Keys ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
export const PAYMENT_SETTINGS_KEY = ["payment-settings"] as const;
|
||||
|
||||
// ─── Hooks ────────────────────────────────────────────────────────────────────
|
||||
|
||||
export function usePaymentSettings() {
|
||||
return useQuery({
|
||||
queryKey: PAYMENT_SETTINGS_KEY,
|
||||
queryFn: () => paymentSettingsApi.get(),
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdatePaymentSettings() {
|
||||
const qc = useQueryClient();
|
||||
const { t } = useTranslation();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (payload: PaymentSettingsPayload) => paymentSettingsApi.update(payload),
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: PAYMENT_SETTINGS_KEY });
|
||||
toast.success(t("paymentSettings.updateSuccess", "Sazlamalar üýtgedildi"));
|
||||
},
|
||||
onError: () => {
|
||||
toast.error(t("paymentSettings.updateError", "Ýalňyşlyk ýüze çykdy"));
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -14,15 +14,15 @@ export interface AddRoleUserPayload {
|
||||
}
|
||||
|
||||
export interface AddPermissionRolePayload {
|
||||
permissionId: number;
|
||||
permissionIds: number[];
|
||||
roleId: number;
|
||||
}
|
||||
|
||||
export interface AddPermissionUserPayload {
|
||||
permissionId: number;
|
||||
userId: number;
|
||||
effect?: string;
|
||||
}
|
||||
// export interface AddPermissionUserPayload {
|
||||
// permissionId: number;
|
||||
// userId: number;
|
||||
// effect?: string;
|
||||
// }
|
||||
|
||||
// Re-export so shared hooks can import from one place
|
||||
export type { BranchListParams, BranchListResponse };
|
||||
@@ -73,24 +73,24 @@ export async function postRoleUser(payload: AddRoleUserPayload): Promise<void> {
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /permission-roles
|
||||
* Assigns a permission to a role.
|
||||
* POST /permission-roles/bulk
|
||||
* Assigns permissions to a role.
|
||||
*/
|
||||
export async function postPermissionRole(payload: AddPermissionRolePayload): Promise<void> {
|
||||
await apiClient.post("/permission-roles", payload);
|
||||
await apiClient.post("/permission-roles/bulk", payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /permission-users
|
||||
* Assigns a permission to a user.
|
||||
*/
|
||||
export async function postPermissionUser(payload: AddPermissionUserPayload): Promise<void> {
|
||||
await apiClient.post("/permission-users", {
|
||||
permissionId: payload.permissionId,
|
||||
userId: payload.userId,
|
||||
effect: payload.effect ?? "allow",
|
||||
});
|
||||
}
|
||||
// /**
|
||||
// * POST /permission-users
|
||||
// * Assigns a permission to a user.
|
||||
// */
|
||||
// export async function postPermissionUser(payload: AddPermissionUserPayload): Promise<void> {
|
||||
// await apiClient.post("/permission-users", {
|
||||
// permissionId: payload.permissionId,
|
||||
// userId: payload.userId,
|
||||
// effect: payload.effect ?? "allow",
|
||||
// });
|
||||
// }
|
||||
|
||||
/**
|
||||
* Proxy for branch list fetching — kept here so shared hooks
|
||||
|
||||
@@ -15,7 +15,7 @@ import { useInfiniteUsers } from "@/features/allUsers/hooks/useAllUsers";
|
||||
import { useInfiniteRoles } from "@/features/roles/hooks/useRoles";
|
||||
import { useInfinitePermissions } from "@/features/permissions/hooks/usePermissions";
|
||||
import { useInfiniteBranches } from "@/features/shared/hooks/useSharedBranchUsers";
|
||||
import { useAssignRoleToUser, useAssignPermissionToUser, useAssignBranchToUser } from "@/features/shared/hooks/useSharedUserAssignments";
|
||||
import { useAssignRoleToUser, useAssignPermissionToRole, useAssignBranchToUser } from "@/features/shared/hooks/useSharedUserAssignments";
|
||||
import type { LocalizedText } from "@/features/branches/api/branchesApi";
|
||||
|
||||
export type AssignDialogKind = "role" | "permission" | "branch";
|
||||
@@ -25,6 +25,8 @@ export interface AssignDialogProps {
|
||||
onClose: () => void;
|
||||
targetUserId?: number;
|
||||
targetUserName?: string;
|
||||
targetRoleId?: number;
|
||||
targetRoleName?: string;
|
||||
onAssigned?: () => void;
|
||||
}
|
||||
|
||||
@@ -41,21 +43,28 @@ const ASSIGN_DIALOG_FIELD_LABELS: Record<AssignDialogKind, string> = {
|
||||
};
|
||||
|
||||
/**
|
||||
* Dialog for assigning a role, permission, or branch to a user (staff).
|
||||
* Permissions are assigned directly to users via POST /permission-users.
|
||||
* Dialog for assigning a role / branch to a staff user, or assigning a permission to a role.
|
||||
* Permissions are assigned to roles via POST /permission-roles/bulk: { permissionIds: [...], roleId }.
|
||||
*/
|
||||
export function AssignDialog({ kind, onClose, targetUserId, targetUserName, onAssigned }: AssignDialogProps) {
|
||||
export function AssignDialog({ kind, onClose, targetUserId, targetUserName, targetRoleId, targetRoleName, onAssigned }: AssignDialogProps) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const lang = (i18n.language === "ru" ? "ru" : i18n.language === "en" ? "en" : "tm") as keyof LocalizedText;
|
||||
|
||||
const isPermission = kind === "permission";
|
||||
|
||||
const [targetSearch, setTargetSearch] = useState("");
|
||||
const [targetValue, setTargetValue] = useState<string>(() => (targetUserId ? String(targetUserId) : ""));
|
||||
const [targetValue, setTargetValue] = useState<string>(() => {
|
||||
if (isPermission && targetRoleId) return String(targetRoleId);
|
||||
if (!isPermission && targetUserId) return String(targetUserId);
|
||||
return "";
|
||||
});
|
||||
const [resourceSearch, setResourceSearch] = useState("");
|
||||
const [resourceValue, setResourceValue] = useState("");
|
||||
const [error, setError] = useState<string | undefined>();
|
||||
|
||||
// Target query: admin users list (GET /users)
|
||||
const staffQuery = useInfiniteUsers(targetSearch);
|
||||
// Target query: admin users list for role/branch; roles list for permission
|
||||
const staffQuery = useInfiniteUsers(targetSearch, !isPermission);
|
||||
const targetRolesQuery = useInfiniteRoles(targetSearch, isPermission);
|
||||
|
||||
// Resource queries
|
||||
const rolesQuery = useInfiniteRoles(resourceSearch, kind === "role");
|
||||
@@ -63,11 +72,25 @@ export function AssignDialog({ kind, onClose, targetUserId, targetUserName, onAs
|
||||
const branchesQuery = useInfiniteBranches(resourceSearch, kind === "branch");
|
||||
|
||||
const roleMutation = useAssignRoleToUser();
|
||||
const permissionMutation = useAssignPermissionToUser();
|
||||
const permissionRoleMutation = useAssignPermissionToRole();
|
||||
const branchMutation = useAssignBranchToUser();
|
||||
const isPending = roleMutation.isPending || permissionMutation.isPending || branchMutation.isPending;
|
||||
const isPending = roleMutation.isPending || permissionRoleMutation.isPending || branchMutation.isPending;
|
||||
|
||||
const targetOptions: InfiniteSelectOption[] = useMemo(() => {
|
||||
if (isPermission) {
|
||||
const opts: InfiniteSelectOption[] = (targetRolesQuery.data?.pages ?? [])
|
||||
.flatMap((p) => p?.roles ?? [])
|
||||
.map((r) => ({ value: String(r.id), label: r.name || r.code || String(r.id) }));
|
||||
|
||||
if (targetRoleId) {
|
||||
const valStr = String(targetRoleId);
|
||||
if (!opts.some((o) => o.value === valStr)) {
|
||||
opts.unshift({ value: valStr, label: targetRoleName || valStr });
|
||||
}
|
||||
}
|
||||
return opts;
|
||||
}
|
||||
|
||||
const opts: InfiniteSelectOption[] = (staffQuery.data?.pages ?? [])
|
||||
.flatMap((p) => p?.users ?? [])
|
||||
.map((u) => ({
|
||||
@@ -82,13 +105,16 @@ export function AssignDialog({ kind, onClose, targetUserId, targetUserName, onAs
|
||||
}
|
||||
}
|
||||
return opts;
|
||||
}, [staffQuery.data, targetUserId, targetUserName]);
|
||||
}, [isPermission, targetRolesQuery.data, targetRoleId, targetRoleName, staffQuery.data, targetUserId, targetUserName]);
|
||||
|
||||
const targetLabel = t("profile.assign.userLabel", "Ulanyjy");
|
||||
const targetLoading = staffQuery.isLoading;
|
||||
const targetLoadingMore = staffQuery.isFetchingNextPage;
|
||||
const targetHasNextPage = !!staffQuery.hasNextPage;
|
||||
const loadMoreTargets = () => staffQuery.fetchNextPage();
|
||||
const targetLabel = isPermission ? t("users.fields.role", "Rol") : t("profile.assign.userLabel", "Ulanyjy");
|
||||
const targetLoading = isPermission ? targetRolesQuery.isLoading : staffQuery.isLoading;
|
||||
const targetLoadingMore = isPermission ? targetRolesQuery.isFetchingNextPage : staffQuery.isFetchingNextPage;
|
||||
const targetHasNextPage = isPermission ? !!targetRolesQuery.hasNextPage : !!staffQuery.hasNextPage;
|
||||
const loadMoreTargets = () => {
|
||||
if (isPermission) targetRolesQuery.fetchNextPage();
|
||||
else staffQuery.fetchNextPage();
|
||||
};
|
||||
|
||||
const resourceOptions: InfiniteSelectOption[] = useMemo(() => {
|
||||
if (kind === "role") {
|
||||
@@ -132,7 +158,7 @@ export function AssignDialog({ kind, onClose, targetUserId, targetUserName, onAs
|
||||
}
|
||||
setError(undefined);
|
||||
|
||||
const userId = Number(targetValue);
|
||||
const firstId = Number(targetValue);
|
||||
const secondId = Number(resourceValue);
|
||||
const onSuccess = () => {
|
||||
setResourceValue("");
|
||||
@@ -141,11 +167,13 @@ export function AssignDialog({ kind, onClose, targetUserId, targetUserName, onAs
|
||||
};
|
||||
|
||||
if (kind === "role") {
|
||||
roleMutation.mutate({ userId, roleId: secondId }, { onSuccess });
|
||||
roleMutation.mutate({ userId: firstId, roleId: secondId }, { onSuccess });
|
||||
} else if (kind === "permission") {
|
||||
permissionMutation.mutate({ userId, permissionId: secondId, effect: "allow" }, { onSuccess });
|
||||
// Usere permission berilýän ýeri comment-e alyndy: permission user-e däl, role-a assign edilýär ({ permissionIds: [id], roleId })
|
||||
// permissionMutation.mutate({ userId: firstId, permissionId: secondId, effect: "allow" }, { onSuccess });
|
||||
permissionRoleMutation.mutate({ roleId: firstId, permissionIds: [secondId] }, { onSuccess });
|
||||
} else {
|
||||
branchMutation.mutate({ userId, branchId: secondId }, { onSuccess });
|
||||
branchMutation.mutate({ userId: firstId, branchId: secondId }, { onSuccess });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -5,11 +5,11 @@ import {
|
||||
postBranchUser,
|
||||
postRoleUser,
|
||||
postPermissionRole,
|
||||
postPermissionUser,
|
||||
// postPermissionUser,
|
||||
type AddBranchUserPayload,
|
||||
type AddRoleUserPayload,
|
||||
type AddPermissionRolePayload,
|
||||
type AddPermissionUserPayload,
|
||||
// type AddPermissionUserPayload,
|
||||
} from "../api/sharedApi";
|
||||
|
||||
// ─── Query Keys ───────────────────────────────────────────────────────────────
|
||||
@@ -67,23 +67,24 @@ export function useAssignPermissionToRole() {
|
||||
});
|
||||
}
|
||||
|
||||
// ─── useAssignPermissionToUser ────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* POST /permission-users — assigns a permission to the given staff user and refreshes the caches.
|
||||
*/
|
||||
export function useAssignPermissionToUser() {
|
||||
const { t } = useTranslation();
|
||||
const invalidateProfile = useInvalidateProfile();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (payload: AddPermissionUserPayload) => postPermissionUser(payload),
|
||||
onSuccess: () => {
|
||||
invalidateProfile();
|
||||
toast.success(t("profile.assign.success", "Üstünlikli birikdirildi"));
|
||||
},
|
||||
});
|
||||
}
|
||||
// // ─── useAssignPermissionToUser ────────────────────────────────────────────────
|
||||
//
|
||||
// /**
|
||||
// * POST /permission-users — assigns a permission to the given staff user and refreshes the caches.
|
||||
// * Commented out: permissions are assigned to roles, not users.
|
||||
// */
|
||||
// export function useAssignPermissionToUser() {
|
||||
// const { t } = useTranslation();
|
||||
// const invalidateProfile = useInvalidateProfile();
|
||||
//
|
||||
// return useMutation({
|
||||
// mutationFn: (payload: AddPermissionUserPayload) => postPermissionUser(payload),
|
||||
// onSuccess: () => {
|
||||
// invalidateProfile();
|
||||
// toast.success(t("profile.assign.success", "Üstünlikli birikdirildi"));
|
||||
// },
|
||||
// });
|
||||
// }
|
||||
|
||||
// ─── useAssignBranchToUser ────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@@ -9,6 +9,22 @@ import { postFile, buildFileUrl } from "@/features/shared/api/sharedApi";
|
||||
export type IntlPaymentStatus = "pending" | "approved" | "rejected";
|
||||
export type CurrencyType = "visa" | "mastercard";
|
||||
|
||||
// ─── Quote / Pay types ────────────────────────────────────────────────────────
|
||||
|
||||
export interface QuoteResponse {
|
||||
type: string;
|
||||
exchangeRateUsd: number;
|
||||
bankFeeTmt: number;
|
||||
gbusFeeTmt: number;
|
||||
maxAmountTmt: number;
|
||||
payableToday: boolean;
|
||||
}
|
||||
|
||||
export interface PayPayload {
|
||||
amountTmt: number;
|
||||
paymentPeriod: string; // "YYYY-MM-DD"
|
||||
}
|
||||
|
||||
/** Kabul ediji + Upgradyý resminamalar (15 sany) — hem UI hem Payload ortak */
|
||||
export interface IntlPaymentDocs {
|
||||
doc_sberbank_account: string | null;
|
||||
@@ -360,4 +376,13 @@ export const intlPaymentApi = {
|
||||
async delete(id: string): Promise<void> {
|
||||
await apiClient.delete(`/visa-master-payment-orders/${id}`);
|
||||
},
|
||||
|
||||
async quote(id: string): Promise<QuoteResponse> {
|
||||
const { data } = await apiClient.get<QuoteResponse>(`/visa-master-payment-orders/${id}/quote`);
|
||||
return data;
|
||||
},
|
||||
|
||||
async pay(id: string, payload: PayPayload): Promise<void> {
|
||||
await apiClient.post(`/visa-master-payment-orders/${id}/pay`, payload);
|
||||
},
|
||||
};
|
||||
|
||||
240
src/features/visaMasterPayments/components/PayDialog.tsx
Normal file
240
src/features/visaMasterPayments/components/PayDialog.tsx
Normal file
@@ -0,0 +1,240 @@
|
||||
import { useState, useEffect, useMemo } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { AlertCircle, Loader2 } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
import { useQuoteIntlPayment, usePayIntlPayment } from "../hooks/useVisaMasterPayments";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
// ─── Months ───────────────────────────────────────────────────────────────────
|
||||
|
||||
const MONTHS = [
|
||||
{ value: "01", label: "Ýanwar" },
|
||||
{ value: "02", label: "Fewral" },
|
||||
{ value: "03", label: "Mart" },
|
||||
{ value: "04", label: "Aprel" },
|
||||
{ value: "05", label: "Maý" },
|
||||
{ value: "06", label: "Iýun" },
|
||||
{ value: "07", label: "Iýul" },
|
||||
{ value: "08", label: "Awgust" },
|
||||
{ value: "09", label: "Sentýabr" },
|
||||
{ value: "10", label: "Oktýabr" },
|
||||
{ value: "11", label: "Noýabr" },
|
||||
{ value: "12", label: "Dekabr" },
|
||||
];
|
||||
|
||||
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
||||
|
||||
function currentMonthValue(): string {
|
||||
const d = new Date();
|
||||
return String(d.getMonth() + 1).padStart(2, "0");
|
||||
}
|
||||
|
||||
function currentYear(): number {
|
||||
return new Date().getFullYear();
|
||||
}
|
||||
|
||||
/** Build last-day-of-month date string YYYY-MM-DD */
|
||||
function buildPaymentPeriod(monthValue: string): string {
|
||||
const year = currentYear();
|
||||
const month = parseInt(monthValue, 10);
|
||||
const lastDay = new Date(year, month, 0).getDate();
|
||||
return `${year}-${monthValue}-${String(lastDay).padStart(2, "0")}`;
|
||||
}
|
||||
|
||||
// ─── Dialog ───────────────────────────────────────────────────────────────────
|
||||
|
||||
interface PayDialogProps {
|
||||
id: string;
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
}
|
||||
|
||||
export function PayDialog({ id, open, onOpenChange }: PayDialogProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const [selectedMonth, setSelectedMonth] = useState<string>(currentMonthValue());
|
||||
const [amountStr, setAmountStr] = useState<string>("");
|
||||
|
||||
// Reset when dialog opens
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
setSelectedMonth(currentMonthValue());
|
||||
setAmountStr("");
|
||||
}
|
||||
}, [open]);
|
||||
|
||||
const { data: quote, isLoading: quoteLoading } = useQuoteIntlPayment(open ? id : "");
|
||||
const { mutate: pay, isPending: isPaying } = usePayIntlPayment();
|
||||
|
||||
// Live-calculated fields
|
||||
const amountTmt = parseFloat(amountStr) || 0;
|
||||
|
||||
const usdEquivalent = useMemo(() => {
|
||||
if (!quote || amountTmt <= 0) return "";
|
||||
const val = amountTmt / quote.exchangeRateUsd;
|
||||
return val.toFixed(2);
|
||||
}, [amountTmt, quote]);
|
||||
|
||||
const totalTmt = useMemo(() => {
|
||||
if (!quote || amountTmt <= 0) return "";
|
||||
const val = amountTmt + quote.bankFeeTmt + quote.gbusFeeTmt;
|
||||
return val.toFixed(2);
|
||||
}, [amountTmt, quote]);
|
||||
|
||||
const isMonthCorrect = selectedMonth === currentMonthValue();
|
||||
|
||||
function handleSubmit() {
|
||||
if (!amountTmt || amountTmt <= 0) {
|
||||
toast.error(t("intlPayment.pay.amountRequired", "Töleg möçberini giriziň"));
|
||||
return;
|
||||
}
|
||||
if (quote && amountTmt > quote.maxAmountTmt) {
|
||||
toast.error(t("intlPayment.pay.amountExceedsMax", "Möçber iň ýokary möçberden geçýär"));
|
||||
return;
|
||||
}
|
||||
const paymentPeriod = buildPaymentPeriod(selectedMonth);
|
||||
pay({ id, payload: { amountTmt, paymentPeriod } }, { onSuccess: () => onOpenChange(false) });
|
||||
}
|
||||
|
||||
if (!open) return null;
|
||||
|
||||
return (
|
||||
/* Overlay */
|
||||
<div
|
||||
className="fixed inset-0 z-50 flex items-center justify-center"
|
||||
onClick={(e) => {
|
||||
if (e.target === e.currentTarget) onOpenChange(false);
|
||||
}}
|
||||
>
|
||||
{/* Backdrop */}
|
||||
<div className="absolute inset-0 bg-black/40 backdrop-blur-sm" />
|
||||
|
||||
{/* Panel */}
|
||||
<div className="relative z-10 w-full max-w-lg mx-4 bg-white rounded-2xl shadow-2xl overflow-hidden">
|
||||
{/* Header */}
|
||||
<div className="px-6 pt-6 pb-4 border-b border-gray-100">
|
||||
<h2 className="text-base font-bold uppercase tracking-widest text-gray-800">{t("intlPayment.pay.title", "Töleg")}</h2>
|
||||
</div>
|
||||
|
||||
{/* Body */}
|
||||
<div className="px-6 py-5 space-y-5">
|
||||
{/* Instruction */}
|
||||
<p className="text-sm text-gray-600">{t("intlPayment.pay.instruction", 'Ýerine ýetirmek üçin "dowam et" düwmä basyň.')}</p>
|
||||
|
||||
{/* Quote info */}
|
||||
{quoteLoading ? (
|
||||
<div className="flex items-center gap-2 text-sm text-gray-400">
|
||||
<Loader2 size={14} className="animate-spin" />
|
||||
{t("common.loading", "Ýüklenýär...")}
|
||||
</div>
|
||||
) : quote ? (
|
||||
<div className="text-xs font-semibold uppercase tracking-wide text-gray-700 space-y-0.5">
|
||||
<p>1 USD = {quote.exchangeRateUsd} TMT</p>
|
||||
<p>
|
||||
{t("intlPayment.pay.bankFee", "BANKYŇ TUTUMY")}: {quote.bankFeeTmt} TMT
|
||||
</p>
|
||||
<p>
|
||||
{t("intlPayment.pay.gbusFee", "GBÜS TUTUMY")}: {quote.gbusFeeTmt} TMT
|
||||
</p>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{/* Töleg aý */}
|
||||
<div className="flex items-start gap-6">
|
||||
<label className="min-w-[120px] pt-2.5 text-sm text-gray-600">{t("intlPayment.pay.month", "Töleg aý")}</label>
|
||||
<div className="flex-1">
|
||||
<Select value={selectedMonth} onValueChange={setSelectedMonth}>
|
||||
<SelectTrigger className="w-full h-10 border-gray-200 rounded-lg text-sm focus:ring-1 focus:ring-primary focus:border-primary">
|
||||
<SelectValue placeholder={t("intlPayment.pay.selectMonth", "Aý saýlaň")} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{MONTHS.map((m) => (
|
||||
<SelectItem key={m.value} value={m.value}>
|
||||
{m.label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Töleg möçberi */}
|
||||
<div className="flex items-start gap-6">
|
||||
<label className="min-w-[120px] pt-2.5 text-sm text-gray-600">
|
||||
<span className="text-red-500 mr-1">*</span>
|
||||
{t("intlPayment.pay.amount", "Töleg möçberi (TMT)")}
|
||||
</label>
|
||||
<div className="flex-1">
|
||||
<input
|
||||
type="number"
|
||||
min={0}
|
||||
max={quote?.maxAmountTmt}
|
||||
value={amountStr}
|
||||
onChange={(e) => setAmountStr(e.target.value)}
|
||||
className="w-full h-10 px-3 border-2 border-primary rounded-lg text-sm outline-none focus:ring-1 focus:ring-primary/40"
|
||||
placeholder="0"
|
||||
/>
|
||||
{quote && (
|
||||
<p className="mt-1 text-xs text-gray-400 italic">
|
||||
{t("intlPayment.pay.maxAmount", "Iň ýokary möçberi")}: {quote.maxAmountTmt} TMT
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* USD ekwalendi */}
|
||||
<div className="flex items-start gap-6">
|
||||
<label className="min-w-[120px] pt-2.5 text-sm text-gray-600">{t("intlPayment.pay.usdEquiv", "USD ekwalendi")}</label>
|
||||
<div className="flex-1">
|
||||
<input
|
||||
readOnly
|
||||
value={usdEquivalent}
|
||||
placeholder="0"
|
||||
className="w-full h-10 px-3 border border-gray-200 rounded-lg text-sm text-gray-400 bg-gray-50 outline-none"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Jemi */}
|
||||
<div className="flex items-start gap-6">
|
||||
<label className="min-w-[120px] pt-2.5 text-sm text-gray-600">{t("intlPayment.pay.total", "Jemi (TMT)")}</label>
|
||||
<div className="flex-1">
|
||||
<input
|
||||
readOnly
|
||||
value={totalTmt}
|
||||
placeholder="0"
|
||||
className="w-full h-10 px-3 border border-gray-200 rounded-lg text-sm text-gray-400 bg-gray-50 outline-none"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Wrong month warning */}
|
||||
{!isMonthCorrect && (
|
||||
<div className="flex items-center gap-2 bg-amber-50 border border-amber-200 rounded-lg px-4 py-2.5 text-sm text-amber-700">
|
||||
<AlertCircle size={14} className="shrink-0" />
|
||||
{t("intlPayment.pay.wrongMonth", "Dogry töleg aýyny saýlamagyňyzy haýyş edýäris!!!!")}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Footer */}
|
||||
<div className="px-6 pb-6 flex items-center justify-end gap-3">
|
||||
<Button type="button" variant="outline" onClick={() => onOpenChange(false)} disabled={isPaying}>
|
||||
{t("intlPayment.pay.cancel", "Ýatyr")}
|
||||
</Button>
|
||||
<Button type="button" onClick={handleSubmit} disabled={isPaying || quoteLoading}>
|
||||
{isPaying ? (
|
||||
<span className="flex items-center gap-2">
|
||||
<Loader2 size={14} className="animate-spin" />
|
||||
{t("common.saving", "Saklanýar...")}
|
||||
</span>
|
||||
) : (
|
||||
t("intlPayment.pay.confirm", "Dowam et")
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
type IntlPaymentListParams,
|
||||
type IntlPaymentCreatePayload,
|
||||
type IntlPaymentUpdatePayload,
|
||||
type PayPayload,
|
||||
} from "../api/visaMasterPaymentsApi";
|
||||
|
||||
export const INTL_PAYMENT_KEYS = {
|
||||
@@ -72,3 +73,24 @@ export function useDeleteIntlPayment() {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useQuoteIntlPayment(id: string) {
|
||||
return useQuery({
|
||||
queryKey: [...INTL_PAYMENT_KEYS.detail(id), "quote"] as const,
|
||||
queryFn: () => intlPaymentApi.quote(id),
|
||||
enabled: !!id,
|
||||
staleTime: 30_000,
|
||||
});
|
||||
}
|
||||
|
||||
export function usePayIntlPayment() {
|
||||
const qc = useQueryClient();
|
||||
const { t } = useTranslation();
|
||||
return useMutation({
|
||||
mutationFn: ({ id, payload }: { id: string; payload: PayPayload }) => intlPaymentApi.pay(id, payload),
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: INTL_PAYMENT_KEYS.lists() });
|
||||
toast.success(t("intlPayment.paySuccess", "Töleg üstünlikli amala aşyryldy"));
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user