fixed ui, connected role user, branch user permissions user api
This commit is contained in:
1 parent
d230b12d6a
commit
f00d2abcac
20 files changed
+906
-391
No files matched your search
@@ -1,12 +1,16 @@
|
||||
import { useMemo } from "react";
|
||||
import { useMemo, useState } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FormInput } from "@/components/formInput";
|
||||
import { FormActions } from "@/components/formActions";
|
||||
import { BentoGrid, BentoCard } from "@/components/bento";
|
||||
import { InfiniteSelect, type InfiniteSelectOption } from "@/components/infiniteSelect";
|
||||
import type { Card } from "../api/cardTransactionsApi";
|
||||
import { useCreateCardTransaction, useUpdateCardTransaction } from "../hooks/useCardTransactions";
|
||||
import { useInfiniteClients } from "@/features/clients/hooks/useClients";
|
||||
import { useCardTypes } from "@/features/cardTypes/hooks/useCardTypes";
|
||||
import type { LocalizedTitle } from "@/features/cardTypes/api/cardTypesApi";
|
||||
import { cardTransactionFormSchema, DEFAULT_FORM_VALUES, buildPayload } from "../schemas/cardTransaction.schema";
|
||||
import type { CardTransactionFormData } from "../schemas/cardTransaction.schema";
|
||||
|
||||
@@ -45,9 +49,41 @@ function flattenErrors(errors: Record<string, { message?: string } | undefined>)
|
||||
// ─── Component ────────────────────────────────────────────────────────────────
|
||||
|
||||
export function CardTransactionForm({ mode, initialData }: CardTransactionFormProps) {
|
||||
const { t } = useTranslation();
|
||||
const { t, i18n } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const [clientSearch, setClientSearch] = useState("");
|
||||
const clientsQuery = useInfiniteClients(clientSearch);
|
||||
const { data: cardTypesData } = useCardTypes({ page: 1, limit: 25 });
|
||||
|
||||
const lang = (i18n.language === "ru" ? "ru" : i18n.language === "en" ? "en" : "tm") as keyof LocalizedTitle;
|
||||
|
||||
const clientOptions: InfiniteSelectOption[] = useMemo(() => {
|
||||
const opts: InfiniteSelectOption[] = (clientsQuery.data?.pages ?? [])
|
||||
.flatMap((p) => p?.users ?? [])
|
||||
.map((u) => ({
|
||||
value: String(u.id),
|
||||
label: u.name || `${u.firstName || ""} ${u.lastName || ""}`.trim() || u.username || String(u.id),
|
||||
}));
|
||||
|
||||
if (initialData?.userId && !opts.some((o) => o.value === String(initialData.userId))) {
|
||||
opts.unshift({ value: String(initialData.userId), label: String(initialData.userId) });
|
||||
}
|
||||
return opts;
|
||||
}, [clientsQuery.data, initialData]);
|
||||
|
||||
const cardTypeOptions = useMemo(() => {
|
||||
const opts = (cardTypesData?.paymentCards ?? []).map((ct) => ({
|
||||
value: String(ct.id),
|
||||
label: ct.title[lang] || ct.title.tm,
|
||||
}));
|
||||
|
||||
if (initialData?.type && !opts.some((o) => o.value === initialData.type)) {
|
||||
opts.unshift({ value: initialData.type, label: initialData.type });
|
||||
}
|
||||
return opts;
|
||||
}, [cardTypesData, lang, initialData]);
|
||||
|
||||
const {
|
||||
watch,
|
||||
setValue,
|
||||
@@ -132,11 +168,12 @@ export function CardTransactionForm({ mode, initialData }: CardTransactionFormPr
|
||||
|
||||
{/* Type */}
|
||||
<FormInput
|
||||
type="text"
|
||||
type="searchable-select"
|
||||
label={t("Card type", "Kart görnüşi")}
|
||||
value={form.type}
|
||||
onChange={setField("type")}
|
||||
placeholder={t("Card type", "Kart görnüşi")}
|
||||
options={cardTypeOptions}
|
||||
placeholder={t("Select to choose", "Saýlamak üçin basyň")}
|
||||
error={errMsg(errors.type)}
|
||||
required
|
||||
/>
|
||||
@@ -152,15 +189,21 @@ export function CardTransactionForm({ mode, initialData }: CardTransactionFormPr
|
||||
required
|
||||
/>
|
||||
|
||||
{/* User ID */}
|
||||
<FormInput
|
||||
type="number"
|
||||
{/* User (Client) */}
|
||||
<InfiniteSelect
|
||||
label={t("User ID", "Ulanyjy ID")}
|
||||
value={form.userId}
|
||||
onChange={setField("userId")}
|
||||
placeholder={t("User ID", "Ulanyjy ID")}
|
||||
error={errMsg(errors.userId)}
|
||||
required
|
||||
value={form.userId}
|
||||
onChange={(v) => setField("userId")(v)}
|
||||
options={clientOptions}
|
||||
placeholder={t("Select to choose", "Saýlamak üçin basyň")}
|
||||
error={errMsg(errors.userId)}
|
||||
loading={clientsQuery.isLoading}
|
||||
isLoadingMore={clientsQuery.isFetchingNextPage}
|
||||
hasNextPage={!!clientsQuery.hasNextPage}
|
||||
onLoadMore={() => clientsQuery.fetchNextPage()}
|
||||
searchValue={clientSearch}
|
||||
onSearchChange={setClientSearch}
|
||||
/>
|
||||
|
||||
{/* Expiry Month + Year side by side */}
|
||||
|
||||
Reference in new issue
Block a user