added role func, fixed some ui
This commit is contained in:
1 parent
cc5b5fca24
commit
7445e09d5f
22 files changed
+1074
-622
No files matched your search
@@ -9,6 +9,7 @@ import { InfiniteSelect, type InfiniteSelectOption } from "@/components/infinite
|
||||
import type { Card } from "../api/cardTransactionsApi";
|
||||
import { useCreateCardTransaction, useUpdateCardTransaction } from "../hooks/useCardTransactions";
|
||||
import { useInfiniteClients } from "@/features/clients/hooks/useClients";
|
||||
import { useWebSelfLock } from "@/features/shared/hooks/useWebSelfLock";
|
||||
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";
|
||||
@@ -41,8 +42,10 @@ export function CardTransactionForm({ mode, initialData }: CardTransactionFormPr
|
||||
const { t, i18n } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const { locked: userLocked, userId: selfUserId, userName } = useWebSelfLock(true);
|
||||
|
||||
const [clientSearch, setClientSearch] = useState("");
|
||||
const clientsQuery = useInfiniteClients(clientSearch);
|
||||
const clientsQuery = useInfiniteClients(clientSearch, !userLocked);
|
||||
const { data: cardTypesData } = useCardTypes({ page: 1, limit: 25 });
|
||||
|
||||
const lang = (i18n.language === "ru" ? "ru" : i18n.language === "en" ? "en" : "tm") as keyof LocalizedTitle;
|
||||
@@ -53,13 +56,18 @@ export function CardTransactionForm({ mode, initialData }: CardTransactionFormPr
|
||||
.map((u) => ({
|
||||
value: String(u.id),
|
||||
label: u.name || `${u.firstName || ""} ${u.lastName || ""}`.trim() || u.username || String(u.id),
|
||||
}));
|
||||
}))
|
||||
.filter((o) => !userLocked || o.value === selfUserId);
|
||||
|
||||
if (selfUserId && !opts.some((o) => o.value === selfUserId)) {
|
||||
opts.unshift({ value: selfUserId, label: userName });
|
||||
}
|
||||
|
||||
if (initialData?.user?.id && !opts.some((o) => o.value === String(initialData.user!.id))) {
|
||||
opts.unshift({ value: String(initialData.user!.id), label: initialData.user!.name || String(initialData.user!.id) });
|
||||
}
|
||||
return opts;
|
||||
}, [clientsQuery.data, initialData]);
|
||||
}, [clientsQuery.data, initialData, userLocked, selfUserId, userName]);
|
||||
|
||||
const cardTypeOptions = useMemo(() => {
|
||||
const opts = (cardTypesData?.paymentCards ?? []).map((ct) => ({
|
||||
@@ -89,9 +97,9 @@ export function CardTransactionForm({ mode, initialData }: CardTransactionFormPr
|
||||
type: initialData.type,
|
||||
month: initialData.month,
|
||||
year: initialData.year,
|
||||
userId: String(initialData.user?.id ?? ""),
|
||||
userId: userLocked ? selfUserId : String(initialData.user?.id ?? ""),
|
||||
}
|
||||
: DEFAULT_FORM_VALUES,
|
||||
: { ...DEFAULT_FORM_VALUES, userId: selfUserId },
|
||||
});
|
||||
|
||||
const form = watch();
|
||||
@@ -187,6 +195,7 @@ export function CardTransactionForm({ mode, initialData }: CardTransactionFormPr
|
||||
options={clientOptions}
|
||||
placeholder={t("Select to choose", "Saýlamak üçin basyň")}
|
||||
error={errMsg(errors.userId)}
|
||||
disabled={userLocked}
|
||||
loading={clientsQuery.isLoading}
|
||||
isLoadingMore={clientsQuery.isFetchingNextPage}
|
||||
hasNextPage={!!clientsQuery.hasNextPage}
|
||||
|
||||
Reference in new issue
Block a user