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

@@ -1,8 +1,8 @@
import { useState } from 'react'
import { useNavigate, useParams } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import { Pencil, Trash2, CheckCircle2, XCircle } from 'lucide-react'
import { Button } from '@/components/ui/button'
import { useState } from "react";
import { useNavigate, useParams } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { Pencil, Trash2, CheckCircle2, XCircle } from "lucide-react";
import { Button } from "@/components/ui/button";
import {
AlertDialog,
AlertDialogAction,
@@ -12,31 +12,30 @@ import {
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from '@/components/ui/alert-dialog'
import { Skeleton } from '@/components/ui/skeleton'
import { Section, InfoRow, MultiLangRow } from '@/components/viewPageComponents'
import { useBranchById, useDeleteBranch } from '@/features/branches/hooks/useBranches'
} from "@/components/ui/alert-dialog";
import { Skeleton } from "@/components/ui/skeleton";
import { Section, InfoRow, MultiLangRow } from "@/components/viewPageComponents";
import { useBranchById, useDeleteBranch } from "@/features/branches/hooks/useBranches";
export function BranchViewPage() {
const { id } = useParams<{ id: string }>()
const navigate = useNavigate()
const { t } = useTranslation()
const { id } = useParams<{ id: string }>();
const navigate = useNavigate();
const { t, i18n } = useTranslation();
const numericId = Number(id)
const numericId = Number(id);
const { data, isLoading } = useBranchById(numericId)
const deleteMutation = useDeleteBranch()
const [deleteOpen, setDeleteOpen] = useState(false)
const { data, isLoading } = useBranchById(numericId);
const deleteMutation = useDeleteBranch();
const [deleteOpen, setDeleteOpen] = useState(false);
const lang = ((i18n.language?.slice(0, 2) === "tk" ? "tm" : i18n.language?.slice(0, 2)) ?? "tm") as "tm" | "ru" | "en";
return (
<div>
<div className="flex items-start justify-between mb-6">
<div>
<h1 className="text-2xl font-bold text-foreground">
{isLoading
? '...'
: `${t('branches.viewTitle', 'Şahamça giňişleýin')}: ${data?.name.tk ?? ''}`}
{isLoading ? "..." : `${t("branches.viewTitle", "Şahamça giňişleýin")}: ${data?.name[lang] ?? ""}`}
</h1>
</div>
@@ -45,7 +44,7 @@ export function BranchViewPage() {
variant="outline"
size="icon"
onClick={() => navigate(`/settings/location/branches/${numericId}/edit`)}
title={t('common.edit', 'Üýtgetmek')}
title={t("common.edit", "Üýtgetmek")}
>
<Pencil size={15} />
</Button>
@@ -54,7 +53,7 @@ export function BranchViewPage() {
size="icon"
className="text-destructive border-destructive/30 hover:bg-destructive/10"
onClick={() => setDeleteOpen(true)}
title={t('common.delete', 'Öçürmek')}
title={t("common.delete", "Öçürmek")}
>
<Trash2 size={15} />
</Button>
@@ -64,10 +63,7 @@ export function BranchViewPage() {
{isLoading ? (
<div className="bg-card border border-border rounded-xl overflow-hidden">
{Array.from({ length: 6 }).map((_, i) => (
<div
key={i}
className="grid grid-cols-[220px_1fr] items-center py-2.5 px-4 border-b border-border last:border-0"
>
<div key={i} className="grid grid-cols-[220px_1fr] items-center py-2.5 px-4 border-b border-border last:border-0">
<Skeleton className="h-4 w-24" />
<Skeleton className="h-4 w-40" />
</div>
@@ -75,71 +71,61 @@ export function BranchViewPage() {
</div>
) : data ? (
<>
<Section title={t('branches.sections.basic', 'Esasy maglumatlar')}>
<InfoRow label={t('common.id', 'ID')} value={data.id} />
<InfoRow label={t('branches.fields.code', 'Kod')} value={data.code} />
<Section title={t("branches.sections.basic", "Esasy maglumatlar")}>
<InfoRow label={t("common.id", "ID")} value={data.id} />
<InfoRow label={t("branches.fields.uniqueCode", "Unikal belgisi")} value={data.uniqueCode} />
<MultiLangRow label={t('branches.fields.name', 'Ady')} value={data.name} />
<MultiLangRow label={t("branches.fields.name", "Ady")} value={data.name} />
<MultiLangRow label={t('branches.fields.district', 'Etrap')} value={data.districtName} />
<MultiLangRow label={t("branches.fields.district", "Etrap")} value={data.provinceName} />
<InfoRow label={t("branches.fields.region", "Welaýat")} value={data.region} />
<div className="grid grid-cols-[220px_1fr] items-center py-2.5 px-4">
<span className="text-sm text-muted-foreground">
{t('branches.fields.isActive', 'Işjeň')}
</span>
{data.isActive ? (
<CheckCircle2 size={18} className="text-emerald-500" />
) : (
<XCircle size={18} className="text-destructive" />
)}
<span className="text-sm text-muted-foreground">{t("branches.fields.isActive", "Işjeň")}</span>
{data.active ? <CheckCircle2 size={18} className="text-emerald-500" /> : <XCircle size={18} className="text-destructive" />}
</div>
</Section>
<Section title={t('branches.sections.address', 'Salgy we habarlaşmak')}>
<MultiLangRow label={t('branches.fields.address', 'Salgy')} value={data.address} />
<InfoRow label={t('branches.fields.phone', 'Telefon')} value={data.phone} />
<InfoRow label={t('branches.fields.email', 'E-poçta')} value={data.email} />
<Section title={t("branches.sections.address", "Salgy we habarlaşmak")}>
<MultiLangRow label={t("branches.fields.address", "Salgy")} value={data.address} />
<InfoRow label={t("branches.fields.phoneNumbers", "Telefonlar")} value={data.phoneNumbers} />
</Section>
<Section title={t('branches.sections.hours', 'Iş wagty')}>
<InfoRow label={t('branches.fields.workingHours', 'Iş wagty')} value={data.workingHours} />
<InfoRow
label={t('branches.fields.description', 'Bellikler')}
value={data.description ?? undefined}
/>
<Section title={t("branches.sections.billing", "Billing maglumatlary")}>
<InfoRow label={t("branches.fields.billingIbr", "Billing ulanyjy ady")} value={data.billingUsername} />
<InfoRow label={t("branches.fields.billingSber", "Billing ulanyjy ady (SBER)")} value={data.billingSberUsername} />
<InfoRow label={t("branches.fields.billingVisa", "Billing ulanyjy ady (VISA)")} value={data.billingVisaMasterUsername} />
<InfoRow label={t("branches.fields.billingSwift", "Billing ulanyjy ady (SWIFT)")} value={data.billingSwiftUsername} />
</Section>
</>
) : (
<p className="text-muted-foreground text-sm">{t('common.noData', 'Maglumat ýok')}</p>
<p className="text-muted-foreground text-sm">{t("common.noData", "Maglumat ýok")}</p>
)}
<AlertDialog open={deleteOpen} onOpenChange={setDeleteOpen}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>{t('common.confirmDelete', 'Öçürmegi tassyklaň')}</AlertDialogTitle>
<AlertDialogDescription>
{t('branches.deleteConfirm', 'Bu şahamçany öçürmek isleýärsiňizmi?')}
</AlertDialogDescription>
<AlertDialogTitle>{t("common.confirmDelete", "Öçürmegi tassyklaň")}</AlertDialogTitle>
<AlertDialogDescription>{t("branches.deleteConfirm", "Bu şahamçany öçürmek isleýärsiňizmi?")}</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>{t('common.cancel', 'Ýatyr')}</AlertDialogCancel>
<AlertDialogCancel>{t("common.cancel", "Ýatyr")}</AlertDialogCancel>
<AlertDialogAction
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
onClick={() =>
deleteMutation.mutate(numericId, {
onSuccess: () => navigate('/settings/location/branches'),
onSuccess: () => navigate("/settings/location/branches"),
})
}
>
{deleteMutation.isPending
? t('common.deleting', 'Öçürilýär...')
: t('common.delete', 'Öçürmek')}
{deleteMutation.isPending ? t("common.deleting", "Öçürilýär...") : t("common.delete", "Öçürmek")}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
)
);
}
export default BranchViewPage
export default BranchViewPage;