started connect with api

This commit is contained in:
Jelaletdin12 committed 2026-08-11 22:48:25 +05:00
1 parent 0ca218505d
commit 6da59f42d9
112 files changed
+7091 -6989

No files matched your search

@@ -5,7 +5,7 @@ import { useTranslation } from "react-i18next";
import { FormInput } from "@/components/formInput";
import { FormActions } from "@/components/formActions";
import { BentoGrid, BentoCard } from "@/components/bento";
import type { CardTransaction } from "../api/cardTransactionsApi";
import type { Card } from "../api/cardTransactionsApi";
import { useCreateCardTransaction, useUpdateCardTransaction } from "../hooks/useCardTransactions";
import { cardTransactionFormSchema, DEFAULT_FORM_VALUES, buildPayload } from "../schemas/cardTransaction.schema";
import type { CardTransactionFormData } from "../schemas/cardTransaction.schema";
@@ -14,19 +14,11 @@ import type { CardTransactionFormData } from "../schemas/cardTransaction.schema"
interface CardTransactionFormProps {
mode: "create" | "edit";
initialData?: CardTransaction;
initialData?: Card;
}
// ─── Constants ────────────────────────────────────────────────────────────────
const PASSPORT_SERIES_OPTIONS = [
{ value: "I-LB", label: "I-LB" },
{ value: "II-LB", label: "II-LB" },
{ value: "III-LB", label: "III-LB" },
{ value: "A", label: "A" },
{ value: "B", label: "B" },
];
const MONTH_OPTIONS = Array.from({ length: 12 }, (_, i) => {
const val = String(i + 1).padStart(2, "0");
return { value: val, label: val };
@@ -64,7 +56,17 @@ export function CardTransactionForm({ mode, initialData }: CardTransactionFormPr
clearErrors,
setError,
} = useForm<CardTransactionFormData>({
defaultValues: initialData ? { ...DEFAULT_FORM_VALUES, ...initialData } : DEFAULT_FORM_VALUES,
defaultValues: initialData
? {
...DEFAULT_FORM_VALUES,
number: initialData.number,
name: initialData.name,
type: initialData.type,
month: initialData.month,
year: initialData.year,
userId: String(initialData.userId),
}
: DEFAULT_FORM_VALUES,
});
const form = watch();
@@ -112,33 +114,30 @@ export function CardTransactionForm({ mode, initialData }: CardTransactionFormPr
return (
<div className="flex flex-col gap-5">
<h1 className="text-xl font-semibold text-foreground">
{mode === "create"
? t("cardTransaction.createTitle", "Kart herekedi dörediň")
: t("cardTransaction.editTitle", "Kart herekedi üýtgetmek")}
{mode === "create" ? t("cardTransaction.createTitle", "Kart dörediň") : t("cardTransaction.editTitle", "Karty üýtgetmek")}
</h1>
<BentoGrid cols={1}>
<BentoCard>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
{/* Passport Series */}
{/* Name */}
<FormInput
type="searchable-select"
label={t("Passport series", "Pasport seriýasy")}
value={form.passport_series}
onChange={setField("passport_series")}
options={PASSPORT_SERIES_OPTIONS}
placeholder={t("Select to choose", "Saýlamak üçin basyň")}
error={errMsg(errors.passport_series)}
type="text"
label={t("Card name", "Kartyň ady")}
value={form.name}
onChange={setField("name")}
placeholder={t("Card name", "Kartyň ady")}
error={errMsg(errors.name)}
required
/>
{/* Passport Number */}
{/* Type */}
<FormInput
type="text"
label={t("Passport number", "Pasport belgisi")}
value={form.passport_number}
onChange={setField("passport_number")}
placeholder={t("Passport number", "Pasport belgisi")}
error={errMsg(errors.passport_number)}
label={t("Card type", "Kart görnüşi")}
value={form.type}
onChange={setField("type")}
placeholder={t("Card type", "Kart görnüşi")}
error={errMsg(errors.type)}
required
/>
@@ -146,10 +145,21 @@ export function CardTransactionForm({ mode, initialData }: CardTransactionFormPr
<FormInput
type="text"
label={t("Card number", "Kart belgisi")}
value={form.card_number}
onChange={setField("card_number")}
value={form.number}
onChange={setField("number")}
placeholder={t("Card number", "Kart belgisi")}
error={errMsg(errors.card_number)}
error={errMsg(errors.number)}
required
/>
{/* User ID */}
<FormInput
type="number"
label={t("User ID", "Ulanyjy ID")}
value={form.userId}
onChange={setField("userId")}
placeholder={t("User ID", "Ulanyjy ID")}
error={errMsg(errors.userId)}
required
/>
@@ -157,23 +167,23 @@ export function CardTransactionForm({ mode, initialData }: CardTransactionFormPr
<div className="grid grid-cols-2 gap-3">
<FormInput
type="select"
label={t("Card expiry month", "Kart Möhleti (aý)")}
value={form.card_expiry_month}
onChange={setField("card_expiry_month")}
label={t("Card expiry month", "Kart möhleti (aý)")}
value={form.month}
onChange={setField("month")}
options={MONTH_OPTIONS}
placeholder={t("Select to choose", "Saýlamak üçin basyň")}
error={errMsg(errors.card_expiry_month)}
error={errMsg(errors.month)}
required
/>
<FormInput
type="select"
label={t("Card expiry year", "Kart Möhleti (ýyl)")}
value={form.card_expiry_year}
onChange={setField("card_expiry_year")}
label={t("Card expiry year", "Kart möhleti (ýyl)")}
value={form.year}
onChange={setField("year")}
options={YEAR_OPTIONS}
placeholder={t("Select to choose", "Saýlamak üçin basyň")}
error={errMsg(errors.card_expiry_year)}
error={errMsg(errors.year)}
required
/>
</div>
@@ -183,12 +193,9 @@ export function CardTransactionForm({ mode, initialData }: CardTransactionFormPr
isPending={isPending}
onSubmit={handleSubmit}
onCancel={handleCancel}
cancelVariant="ghost"
cancelLabel={t("Cancel", "Ýatyr")}
loadingLabel={t("Saving...", "Saklanýar...")}
submitLabel={
mode === "create" ? t("Create card transaction", "Kart herekedi dörediň") : t("Save changes", "Üýtgetmeleri sakla")
}
submitLabel={mode === "create" ? t("Create card", "Kart dörediň") : t("Save changes", "Üýtgetmeleri sakla")}
/>
</BentoCard>
</BentoGrid>