rofactored edit and create pages
This commit is contained in:
1 parent
2f13d424e1
commit
4adc153503
79 files changed
+1663
-2333
No files matched your search
@@ -1,20 +1,5 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { BranchForm } from '@/features/branches/components/branchesForm'
|
||||
|
||||
export default function BranchCreatePage() {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div >
|
||||
<div className="mb-6">
|
||||
|
||||
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{t('branches.create.title', 'Şahamça döretmek')}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<BranchForm mode="create" />
|
||||
</div>
|
||||
)
|
||||
return <BranchForm mode="create" />
|
||||
}
|
||||
@@ -1,40 +1,18 @@
|
||||
import { useNavigate, useParams } from "react-router-dom";
|
||||
import { useParams } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { PageSpinner } from "@/components/pageSpinner";
|
||||
import { PageError } from "@/components/pageError";
|
||||
import { BranchForm } from "@/features/branches/components/branchesForm";
|
||||
import { useBranchById } from "@/features/branches/hooks/useBranches";
|
||||
import { Loader2 } from "lucide-react";
|
||||
|
||||
export default function BranchEditPage() {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const navigate = useNavigate();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const numericId = Number(id);
|
||||
const { data, isLoading, isError } = useBranchById(numericId);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="mb-6">
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{isLoading
|
||||
? "..."
|
||||
: `${t("branches.edit.title", "Şahamçany üýtgetmek")}: ${data?.name.tk ?? ""}`}
|
||||
</h1>
|
||||
</div>
|
||||
if (isLoading) return <PageSpinner />;
|
||||
if (isError || !data) return <PageError message={t("common.error", "Maglumat ýüklenilmedi")} />;
|
||||
|
||||
{isLoading ? (
|
||||
<div className="flex items-center justify-center min-h-[400px]">
|
||||
<Loader2 className="animate-spin text-muted-foreground" size={32} />
|
||||
</div>
|
||||
) : isError || !data ? (
|
||||
<div className="flex items-center justify-center min-h-[400px]">
|
||||
<p className="text-sm text-destructive">
|
||||
{t("common.error", "Maglumat ýüklenilmedi. Sahypany täzeleläň.")}
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<BranchForm mode="edit" initialData={data} branchId={numericId} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
return <BranchForm mode="edit" initialData={data} />;
|
||||
}
|
||||
@@ -1,20 +1,5 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { DistrictForm } from '@/features/districts/components/districtsForm'
|
||||
|
||||
export default function DistrictCreatePage() {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div >
|
||||
<div className="mb-6">
|
||||
|
||||
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{t('districts.create.title', 'Etrap döretmek')}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<DistrictForm mode="create" />
|
||||
</div>
|
||||
)
|
||||
return <DistrictForm mode="create" />
|
||||
}
|
||||
@@ -1,46 +1,18 @@
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { PageSpinner } from '@/components/pageSpinner'
|
||||
import { PageError } from '@/components/pageError'
|
||||
import { DistrictForm } from '@/features/districts/components/districtsForm'
|
||||
import { useDistrictById } from '@/features/districts/hooks/useDistricts'
|
||||
|
||||
export default function DistrictEditPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const { t } = useTranslation()
|
||||
|
||||
const numericId = Number(id)
|
||||
const { data, isLoading, isError } = useDistrictById(numericId)
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="mb-6">
|
||||
|
||||
if (isLoading) return <PageSpinner />
|
||||
if (isError || !data) return <PageError message={t('common.notFound', 'Tapylmady')} />
|
||||
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{isLoading
|
||||
? '...'
|
||||
: `${t('districts.edit.title', 'Etrapy üýtgetmek')}: ${data?.name.tk ?? ''}`}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
{isLoading ? (
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
{Array.from({ length: 3 }).map((_, i) => (
|
||||
<div
|
||||
key={i}
|
||||
className="grid grid-cols-[220px_1fr] items-center py-3 px-4 border-b border-border last:border-0"
|
||||
>
|
||||
<div className="h-4 w-24 bg-muted rounded animate-pulse" />
|
||||
<div className="h-8 w-full bg-muted rounded animate-pulse" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : isError || !data ? (
|
||||
<div className="flex items-center justify-center py-20 text-destructive text-sm">
|
||||
{t('common.error', 'Ýalňyşlyk ýüze çykdy')}
|
||||
</div>
|
||||
) : (
|
||||
<DistrictForm mode="edit" initialData={data} districtId={numericId} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
return <DistrictForm mode="edit" initialData={data} />
|
||||
}
|
||||
Reference in new issue
Block a user