Compare commits

..

6 Commits

Author SHA1 Message Date
Samandar Turgunboyev
f1498c4828 create-at added all table 2026-01-30 11:45:06 +05:00
Samandar Turgunboyev
2dd4bccfcb film detail update 2026-01-26 17:04:33 +05:00
Samandar Turgunboyev
80df127d6e film detail update 2026-01-26 16:54:06 +05:00
Samandar Turgunboyev
88dc5470d9 task update 2026-01-26 16:40:07 +05:00
Samandar Turgunboyev
30f842c53d bug fix 2025-12-13 12:50:53 +05:00
Samandar Turgunboyev
18e43f0eb8 delete super admin 2025-12-12 16:39:32 +05:00
38 changed files with 503 additions and 166 deletions

32
package-lock.json generated
View File

@@ -43,7 +43,8 @@
"sonner": "^2.0.7",
"tailwind-merge": "^3.3.1",
"tailwindcss": "^4.1.13",
"zod": "^4.1.13"
"zod": "^4.1.13",
"zustand": "^5.0.9"
},
"devDependencies": {
"@eslint/js": "^9.25.0",
@@ -6156,6 +6157,35 @@
"funding": {
"url": "https://github.com/sponsors/colinhacks"
}
},
"node_modules/zustand": {
"version": "5.0.9",
"resolved": "https://registry.npmjs.org/zustand/-/zustand-5.0.9.tgz",
"integrity": "sha512-ALBtUj0AfjJt3uNRQoL1tL2tMvj6Gp/6e39dnfT6uzpelGru8v1tPOGBzayOWbPJvujM8JojDk3E1LxeFisBNg==",
"license": "MIT",
"engines": {
"node": ">=12.20.0"
},
"peerDependencies": {
"@types/react": ">=18.0.0",
"immer": ">=9.0.6",
"react": ">=18.0.0",
"use-sync-external-store": ">=1.2.0"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"immer": {
"optional": true
},
"react": {
"optional": true
},
"use-sync-external-store": {
"optional": true
}
}
}
}
}

View File

@@ -47,7 +47,8 @@
"sonner": "^2.0.7",
"tailwind-merge": "^3.3.1",
"tailwindcss": "^4.1.13",
"zod": "^4.1.13"
"zod": "^4.1.13",
"zustand": "^5.0.9"
},
"devDependencies": {
"@eslint/js": "^9.25.0",

View File

@@ -1,8 +1,26 @@
import { user_api } from "@/shared/config/api/user/api";
import { userStore } from "@/shared/hooks/user";
import { SidebarProvider, SidebarTrigger } from "@/shared/ui/sidebar";
import { AppSidebar } from "@/widgets/sidebar-layout";
import React from "react";
import { useQuery } from "@tanstack/react-query";
import React, { useEffect } from "react";
const SidebarLayout = ({ children }: { children: React.ReactNode }) => {
const { data } = useQuery({
queryKey: ["get_me"],
queryFn: () => user_api.getMe(),
select(data) {
return data.data.data;
},
});
const { addUser } = userStore();
useEffect(() => {
if (data) {
addUser(data);
}
}, [data]);
return (
<SidebarProvider>
<AppSidebar />

View File

@@ -212,7 +212,7 @@ export default function AddDistrict({ initialValues, setDialogOpen }: Props) {
: "opacity-0",
)}
/>
{u.first_name} {u.last_name} {u.region.name}
{u.first_name} {u.last_name} {u.region?.name}
</CommandItem>
))}
</CommandGroup>

View File

@@ -1,4 +1,6 @@
import type { DistrictListData } from "@/features/districts/lib/data";
import { userStore } from "@/shared/hooks/user";
import formatDate from "@/shared/lib/formatDate";
import { Button } from "@/shared/ui/button";
import {
Table,
@@ -30,6 +32,8 @@ const TableDistrict = ({
setEditingDistrict,
currentPage,
}: Props) => {
const { user } = userStore();
return (
<div className="flex-1 overflow-auto">
{isLoading && (
@@ -55,6 +59,7 @@ const TableDistrict = ({
<TableHead>ID</TableHead>
<TableHead>Tuman nomi</TableHead>
<TableHead>Kim qoshgan</TableHead>
<TableHead>Qo'shgan sanasi</TableHead>
<TableHead className="text-right">Harakatlar</TableHead>
</TableRow>
</TableHeader>
@@ -67,6 +72,9 @@ const TableDistrict = ({
<TableCell>
{d.user.first_name} {d.user.last_name}
</TableCell>
<TableCell>
{formatDate.format(d.created_at, "DD-MM-YYYY")}
</TableCell>
<TableCell className="flex gap-2 justify-end">
<Button
variant="outline"
@@ -79,15 +87,17 @@ const TableDistrict = ({
>
<Edit className="w-4 h-4" />
</Button>
<Button
variant="destructive"
size="sm"
onClick={() => handleDelete(d)}
className="cursor-pointer"
>
<Trash className="w-4 h-4" />
</Button>
{user?.is_superuser && (
<Button
variant="destructive"
size="sm"
onClick={() => handleDelete(d)}
disabled={!user?.is_superuser}
className="cursor-pointer"
>
<Trash className="w-4 h-4" />
</Button>
)}
</TableCell>
</TableRow>
))}

View File

@@ -37,4 +37,11 @@ export const doctor_api = {
const res = await httpClient.delete(`${API_URLS.DOCTOR}${id}/delete/`);
return res;
},
async export() {
const res = await httpClient.get(`${API_URLS.DOCTOR_EXPORT}`, {
responseType: "blob",
});
return res;
},
};

View File

@@ -455,7 +455,7 @@ const AddedDoctor = ({ initialValues, setDialogOpen }: Props) => {
: "opacity-0",
)}
/>
{u.first_name} {u.last_name} {u.region.name}
{u.first_name} {u.last_name} {u.region?.name}
</CommandItem>
))}
</CommandGroup>

View File

@@ -1,3 +1,4 @@
import { doctor_api } from "@/features/doctors/lib/api";
import type { DoctorListResData } from "@/features/doctors/lib/data";
import AddedDoctor from "@/features/doctors/ui/AddedDoctor";
import { Button } from "@/shared/ui/button";
@@ -9,8 +10,11 @@ import {
DialogTrigger,
} from "@/shared/ui/dialog";
import { Input } from "@/shared/ui/input";
import { Plus } from "lucide-react";
import { useMutation } from "@tanstack/react-query";
import type { AxiosError } from "axios";
import { CloudDownload, Loader2, Plus } from "lucide-react";
import type { Dispatch, SetStateAction } from "react";
import { toast } from "sonner";
interface Props {
searchName: string;
@@ -49,6 +53,45 @@ const FilterDoctor = ({
setEditingPlan,
editingPlan,
}: Props) => {
const { mutate, isPending } = useMutation({
mutationFn: async () => {
const res = await doctor_api.export();
return res.data;
},
onSuccess: (data: Blob) => {
// Blob URL yaratish
const url = window.URL.createObjectURL(
new Blob([data], {
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
}),
);
// <a> elementi orqali yuklab olish
const link = document.createElement("a");
link.href = url;
link.setAttribute("download", "doctor_export.xlsx"); // Fayl nomi
document.body.appendChild(link);
link.click();
link.remove();
// Blob URL-ni ozod qilish
window.URL.revokeObjectURL(url);
toast.success("Excel muvaffaqiyatli yuklab olindi", {
position: "top-center",
richColors: true,
});
},
onError: (err: AxiosError) => {
const errMessage = err.response?.data as { message: string };
const messageText = errMessage.message;
toast.error(messageText || "Xatolik yuz berdi", {
richColors: true,
position: "top-center",
});
},
});
return (
<div className="flex justify-end gap-2 w-full">
<Input
@@ -87,6 +130,17 @@ const FilterDoctor = ({
onChange={(e) => setSearchUser(e.target.value)}
className="w-full md:w-48"
/>
<Button
variant="default"
className="bg-blue-500 cursor-pointer hover:bg-blue-500"
onClick={() => mutate()}
disabled={isPending}
>
<CloudDownload className="!h-5 !w-5" /> Excel formatda yuklash
{isPending && <Loader2 className="animate-spin" />}
</Button>
<Dialog open={dialogOpen} onOpenChange={setDialogOpen}>
<DialogTrigger asChild>
<Button

View File

@@ -1,4 +1,6 @@
import type { DoctorListResData } from "@/features/doctors/lib/data";
import { userStore } from "@/shared/hooks/user";
import formatDate from "@/shared/lib/formatDate";
import formatPhone from "@/shared/lib/formatPhone";
import { Badge } from "@/shared/ui/badge";
import { Button } from "@/shared/ui/button";
@@ -36,6 +38,7 @@ const TableDoctor = ({
handleDelete,
isFetching,
}: Props) => {
const { user: getme } = userStore();
return (
<div className="flex-1 overflow-auto">
{(isLoading || isFetching) && (
@@ -66,6 +69,7 @@ const TableDoctor = ({
<TableHead>Ish joyi</TableHead>
<TableHead>Sohasi</TableHead>
<TableHead>Kim qo'shgan</TableHead>
<TableHead>Qo'shgan sanasi</TableHead>
<TableHead className="text-right">Amallar</TableHead>
</TableRow>
</TableHeader>
@@ -89,6 +93,9 @@ const TableDoctor = ({
<TableCell>
{item.user.first_name} {item.user.last_name}
</TableCell>
<TableCell>
{formatDate.format(item.created_at, "DD-MM-YYYY")}
</TableCell>
<TableCell className="text-right flex gap-2 justify-end">
<Button
variant="outline"
@@ -112,14 +119,17 @@ const TableDoctor = ({
>
<Pencil size={18} />
</Button>
<Button
variant="destructive"
size="icon"
className="cursor-pointer"
onClick={() => handleDelete(item)}
>
<Trash2 size={18} />
</Button>
{getme?.is_superuser && (
<Button
variant="destructive"
size="icon"
disabled={!getme?.is_superuser}
className="cursor-pointer"
onClick={() => handleDelete(item)}
>
<Trash2 size={18} />
</Button>
)}
</TableCell>
</TableRow>
))

View File

@@ -1,4 +1,5 @@
import type { LocationListDataRes } from "@/features/location/lib/data";
import { userStore } from "@/shared/hooks/user";
import formatDate from "@/shared/lib/formatDate";
import { Button } from "@/shared/ui/button";
import {
@@ -25,6 +26,7 @@ const LocationTable = ({
setDetailDialog,
handleDelete,
}: Props) => {
const { user: getme } = userStore();
return (
<div className="flex-1 overflow-auto">
<Table>
@@ -72,14 +74,17 @@ const LocationTable = ({
>
<Eye size={18} />
</Button>
<Button
variant="destructive"
size="icon"
className="cursor-pointer"
onClick={() => handleDelete(item)}
>
<Trash2 size={18} />
</Button>
{getme?.is_superuser && (
<Button
variant="destructive"
size="icon"
className="cursor-pointer"
disabled={!getme?.is_superuser}
onClick={() => handleDelete(item)}
>
<Trash2 size={18} />
</Button>
)}
</TableCell>
</TableRow>
))}

View File

@@ -1,4 +1,5 @@
import type { LocationListDataRes } from "@/features/location/lib/data";
import { userStore } from "@/shared/hooks/user";
import formatDate from "@/shared/lib/formatDate";
import { Button } from "@/shared/ui/button";
import {
@@ -25,6 +26,7 @@ const UserLocationTable = ({
setDetailDialog,
handleDelete,
}: Props) => {
const { user: getme } = userStore();
return (
<div className="flex-1 overflow-auto">
<Table>
@@ -72,14 +74,17 @@ const UserLocationTable = ({
>
<Eye size={18} />
</Button>
<Button
variant="destructive"
size="icon"
className="cursor-pointer"
onClick={() => handleDelete(item)}
>
<Trash2 size={18} />
</Button>
{getme?.is_superuser && (
<Button
variant="destructive"
size="icon"
disabled={!getme?.is_superuser}
className="cursor-pointer"
onClick={() => handleDelete(item)}
>
<Trash2 size={18} />
</Button>
)}
</TableCell>
</TableRow>
))}

View File

@@ -332,7 +332,7 @@ export default function AddedObject({ initialValues, setDialogOpen }: Props) {
: "opacity-0",
)}
/>
{u.first_name} {u.last_name} {u.region.name}
{u.first_name} {u.last_name} {u.region?.name}
</CommandItem>
))}
</CommandGroup>

View File

@@ -1,4 +1,6 @@
import type { ObjectListData } from "@/features/objects/lib/data";
import { userStore } from "@/shared/hooks/user";
import formatDate from "@/shared/lib/formatDate";
import { Badge } from "@/shared/ui/badge";
import { Button } from "@/shared/ui/button";
import {
@@ -33,6 +35,7 @@ const ObjectTable = ({
isError,
isLoading,
}: Props) => {
const { user: getme } = userStore();
return (
<div className="flex-1 overflow-auto">
{isLoading && (
@@ -58,6 +61,7 @@ const ObjectTable = ({
<TableHead>Obyekt nomi</TableHead>
<TableHead>Tuman</TableHead>
<TableHead>Foydalanuvchi</TableHead>
<TableHead>Qo'shilgan sanasi</TableHead>
<TableHead className="text-right">Amallar</TableHead>
</TableRow>
</TableHeader>
@@ -73,6 +77,9 @@ const ObjectTable = ({
<TableCell>
{item.user.first_name} {item.user.last_name}
</TableCell>
<TableCell>
{formatDate.format(item.created_at, "DD-MM-YYYY")}
</TableCell>
<TableCell className="text-right flex gap-2 justify-end">
<Button
variant="outline"
@@ -96,14 +103,17 @@ const ObjectTable = ({
>
<Pencil size={18} />
</Button>
<Button
variant="destructive"
size="icon"
className="cursor-pointer"
onClick={() => handleDelete(item)}
>
<Trash2 size={18} />
</Button>
{getme?.is_superuser && (
<Button
variant="destructive"
size="icon"
className="cursor-pointer"
disabled={!getme?.is_superuser}
onClick={() => handleDelete(item)}
>
<Trash2 size={18} />
</Button>
)}
</TableCell>
</TableRow>
))

View File

@@ -5,6 +5,8 @@ import {
} from "@/features/pharm/lib/data";
import AddedPharm from "@/features/pharm/ui/AddedPharm";
import DeletePharm from "@/features/pharm/ui/DeletePharm";
import { userStore } from "@/shared/hooks/user";
import formatDate from "@/shared/lib/formatDate";
import { Button } from "@/shared/ui/button";
import {
Dialog,
@@ -28,6 +30,7 @@ import { Edit, Loader2, Plus, Trash } from "lucide-react";
import { useState } from "react";
const PharmList = () => {
const { user: getme } = userStore();
const [currentPage, setCurrentPage] = useState(1);
const [nameFilter, setNameFilter] = useState<string>("");
const limit = 20;
@@ -119,6 +122,7 @@ const PharmList = () => {
<TableRow className="text-center">
<TableHead className="text-start">ID</TableHead>
<TableHead className="text-start">Nomi</TableHead>
<TableHead className="text-start">Qo'shilgan sanasi</TableHead>
<TableHead className="text-end">Amallar</TableHead>
</TableRow>
</TableHeader>
@@ -128,6 +132,9 @@ const PharmList = () => {
<TableRow key={plan.id} className="text-start">
<TableCell>{plan.id}</TableCell>
<TableCell>{plan.name}</TableCell>
<TableCell>
{formatDate.format(plan.created_at, "DD-MM-YYYY")}
</TableCell>
<TableCell className="flex gap-2 justify-end">
<Button
variant="outline"
@@ -140,14 +147,17 @@ const PharmList = () => {
>
<Edit className="h-4 w-4" />
</Button>
<Button
variant="destructive"
size="sm"
className="cursor-pointer"
onClick={() => handleDelete(plan)}
>
<Trash className="h-4 w-4" />
</Button>
{getme?.is_superuser && (
<Button
variant="destructive"
size="sm"
disabled={!getme.is_superuser}
className="cursor-pointer"
onClick={() => handleDelete(plan)}
>
<Trash className="h-4 w-4" />
</Button>
)}
</TableCell>
</TableRow>
))

View File

@@ -38,4 +38,11 @@ export const pharmacies_api = {
const res = await httpClient.delete(`${API_URLS.PHARMACIES}${id}/delete/`);
return res;
},
async export() {
const res = await httpClient.get(`${API_URLS.PHARMACIES_EXPORT}`, {
responseType: "blob",
});
return res;
},
};

View File

@@ -123,9 +123,9 @@ export interface PharmaciesListData {
export interface CreatePharmaciesReq {
name: string;
inn: string;
inn?: string;
owner_phone: string;
responsible_phone: string;
responsible_phone?: string;
district_id: number;
place_id: number;
user_id: number;
@@ -136,9 +136,9 @@ export interface CreatePharmaciesReq {
export interface UpdatePharmaciesReq {
name: string;
inn: string;
inn?: string;
owner_phone: string;
responsible_phone: string;
responsible_phone?: string;
longitude: number;
latitude: number;
extra_location: { longitude: number; latitude: number };

View File

@@ -2,9 +2,9 @@ import z from "zod";
export const PharmForm = z.object({
name: z.string().min(1, { message: "Majburiy maydon" }),
inn: z.string().min(1, { message: "Majburiy maydon" }),
inn: z.string().optional(),
phone_number: z.string().min(1, { message: "Majburiy maydon" }),
additional_phone: z.string().min(1, { message: "Majburiy maydon" }),
additional_phone: z.string().optional(),
district: z.string().min(1, { message: "Majburiy maydon" }),
user: z.string().min(1, { message: "Majburiy maydon" }),
object: z.string().min(1, { message: "Majburiy maydon" }),

View File

@@ -249,36 +249,31 @@ const AddedPharmacies = ({ initialValues, setDialogOpen }: Props) => {
});
function onSubmit(values: z.infer<typeof PharmForm>) {
const baseBody = {
extra_location: {
latitude: Number(values.lat),
longitude: Number(values.long),
},
latitude: Number(values.lat),
longitude: Number(values.long),
name: values.name,
owner_phone: onlyNumber(values.phone_number),
...(values.additional_phone && {
responsible_phone: onlyNumber(values.additional_phone),
}),
...(values.inn && { inn: values.inn }), // 👈 faqat bolsa yuboriladi
};
if (initialValues) {
edit({
id: initialValues.id,
body: {
extra_location: {
latitude: Number(values.lat),
longitude: Number(values.long),
},
latitude: Number(values.lat),
longitude: Number(values.long),
inn: values.inn,
name: values.name,
owner_phone: onlyNumber(values.phone_number),
responsible_phone: onlyNumber(values.additional_phone),
},
body: baseBody,
});
} else {
mutate({
...baseBody,
district_id: Number(values.district),
extra_location: {
latitude: Number(values.lat),
longitude: Number(values.long),
},
latitude: Number(values.lat),
longitude: Number(values.long),
inn: values.inn,
name: values.name,
owner_phone: onlyNumber(values.phone_number),
place_id: Number(values.object),
responsible_phone: onlyNumber(values.additional_phone),
user_id: Number(values.user),
});
}
@@ -343,7 +338,7 @@ const AddedPharmacies = ({ initialValues, setDialogOpen }: Props) => {
<Input
placeholder="+998 90 123-45-67"
{...field}
value={formatPhone(field.value)}
value={field.value && formatPhone(field.value)}
/>
</FormControl>
<FormMessage />
@@ -419,7 +414,7 @@ const AddedPharmacies = ({ initialValues, setDialogOpen }: Props) => {
: "opacity-0",
)}
/>
{u.first_name} {u.last_name} {u.region.name}
{u.first_name} {u.last_name} {u.region?.name}
</CommandItem>
))}
</CommandGroup>

View File

@@ -1,3 +1,4 @@
import { pharmacies_api } from "@/features/pharmacies/lib/api";
import type { PharmaciesListData } from "@/features/pharmacies/lib/data";
import AddedPharmacies from "@/features/pharmacies/ui/AddedPharmacies";
import { Button } from "@/shared/ui/button";
@@ -9,8 +10,11 @@ import {
DialogTrigger,
} from "@/shared/ui/dialog";
import { Input } from "@/shared/ui/input";
import { Plus } from "lucide-react";
import { useMutation } from "@tanstack/react-query";
import type { AxiosError } from "axios";
import { CloudDownload, Loader2, Plus } from "lucide-react";
import type { Dispatch, SetStateAction } from "react";
import { toast } from "sonner";
interface Props {
searchName: string;
@@ -41,6 +45,45 @@ const PharmaciesFilter = ({
setEditingPlan,
editingPlan,
}: Props) => {
const { mutate, isPending } = useMutation({
mutationFn: async () => {
const res = await pharmacies_api.export();
return res.data;
},
onSuccess: (data: Blob) => {
// Blob URL yaratish
const url = window.URL.createObjectURL(
new Blob([data], {
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
}),
);
// <a> elementi orqali yuklab olish
const link = document.createElement("a");
link.href = url;
link.setAttribute("download", "dorixonalar.xlsx"); // Fayl nomi
document.body.appendChild(link);
link.click();
link.remove();
// Blob URL-ni ozod qilish
window.URL.revokeObjectURL(url);
toast.success("Excel muvaffaqiyatli yuklab olindi", {
position: "top-center",
richColors: true,
});
},
onError: (err: AxiosError) => {
const errMessage = err.response?.data as { message: string };
const messageText = errMessage.message;
toast.error(messageText || "Xatolik yuz berdi", {
richColors: true,
position: "top-center",
});
},
});
return (
<div className="flex justify-end gap-2 w-full">
<Input
@@ -67,6 +110,15 @@ const PharmaciesFilter = ({
onChange={(e) => setSearchUser(e.target.value)}
className="w-full md:w-48"
/>
<Button
variant="default"
className="bg-blue-500 cursor-pointer hover:bg-blue-500"
onClick={() => mutate()}
disabled={isPending}
>
<CloudDownload className="!h-5 !w-5" /> Excel formatda yuklash
{isPending && <Loader2 className="animate-spin" />}
</Button>
<Dialog open={dialogOpen} onOpenChange={setDialogOpen}>
<DialogTrigger asChild>
<Button

View File

@@ -1,4 +1,6 @@
import type { PharmaciesListData } from "@/features/pharmacies/lib/data";
import { userStore } from "@/shared/hooks/user";
import formatDate from "@/shared/lib/formatDate";
import formatPhone from "@/shared/lib/formatPhone";
import { Button } from "@/shared/ui/button";
import {
@@ -29,6 +31,7 @@ const PharmaciesTable = ({
setDialogOpen,
handleDelete,
}: Props) => {
const { user: getme } = userStore();
return (
<div className="flex-1 overflow-auto">
<Table>
@@ -42,6 +45,7 @@ const PharmaciesTable = ({
<TableHead>Tuman</TableHead>
<TableHead>Obyekt</TableHead>
<TableHead>Kim qo'shgan</TableHead>
<TableHead>Qo'shgan sanasi</TableHead>
<TableHead className="text-right">Amallar</TableHead>
</TableRow>
</TableHeader>
@@ -59,6 +63,10 @@ const PharmaciesTable = ({
{item.user.first_name} {item.user.last_name}
</TableCell>
<TableCell>
{formatDate.format(item.created_at, "DD-MM-YYYY")}
</TableCell>
<TableCell className="text-right flex gap-2 justify-end">
<Button
variant="outline"
@@ -82,14 +90,17 @@ const PharmaciesTable = ({
>
<Pencil size={18} />
</Button>
<Button
variant="destructive"
size="icon"
className="cursor-pointer"
onClick={() => handleDelete(item)}
>
<Trash2 size={18} />
</Button>
{getme?.is_superuser && (
<Button
variant="destructive"
size="icon"
disabled={!getme?.is_superuser}
className="cursor-pointer"
onClick={() => handleDelete(item)}
>
<Trash2 size={18} />
</Button>
)}
</TableCell>
</TableRow>
))}

View File

@@ -2,6 +2,8 @@ import { pill_api } from "@/features/pill/lib/api";
import { type PillListData, type PillType } from "@/features/pill/lib/data";
import AddedPill from "@/features/pill/ui/AddedPill";
import DeletePill from "@/features/pill/ui/DeletePill";
import { userStore } from "@/shared/hooks/user";
import formatDate from "@/shared/lib/formatDate";
import formatPrice from "@/shared/lib/formatPrice";
import { Button } from "@/shared/ui/button";
import {
@@ -26,6 +28,7 @@ import { Edit, Plus, Trash } from "lucide-react";
import { useState } from "react";
const PillList = () => {
const { user: getme } = userStore();
const [currentPage, setCurrentPage] = useState(1);
const limit = 20;
const [nameFilter, setNameFilter] = useState<string>("");
@@ -102,6 +105,7 @@ const PillList = () => {
<TableHead className="text-start">ID</TableHead>
<TableHead className="text-start">Nomi</TableHead>
<TableHead className="text-start">Narxi</TableHead>
<TableHead className="text-start">Qo'shilgan sanasi</TableHead>
<TableHead className="text-end">Amallar</TableHead>
</TableRow>
</TableHeader>
@@ -111,6 +115,9 @@ const PillList = () => {
<TableCell>{plan.id}</TableCell>
<TableCell>{plan.name}</TableCell>
<TableCell>{formatPrice(plan.price)}</TableCell>
<TableCell>
{formatDate.format(plan.created_at, "Dd-MM-YYYY")}
</TableCell>
<TableCell className="flex gap-2 justify-end">
<Button
variant="outline"
@@ -123,14 +130,17 @@ const PillList = () => {
>
<Edit className="h-4 w-4" />
</Button>
<Button
variant="destructive"
size="sm"
className="cursor-pointer"
onClick={() => handleDelete(plan)}
>
<Trash className="h-4 w-4" />
</Button>
{getme?.is_superuser && (
<Button
variant="destructive"
size="sm"
className="cursor-pointer"
onClick={() => handleDelete(plan)}
disabled={!getme.is_superuser}
>
<Trash className="h-4 w-4" />
</Button>
)}
</TableCell>
</TableRow>
))}

View File

@@ -51,7 +51,7 @@ export interface PlanListData {
}
export interface PlanCreateReq {
title: string;
title?: string;
description: string;
date: string;
user_id: number;
@@ -63,7 +63,7 @@ export interface PlanCreateReq {
}
export interface PlanUpdateReq {
title: string;
title?: string;
description: string;
date: string;
longitude: number;

View File

@@ -1,7 +1,7 @@
import z from "zod";
export const createPlanFormData = z.object({
name: z.string().min(1, { message: "Majburiy maydon" }),
name: z.string().optional(),
description: z.string().min(1, { message: "Majburiy maydon" }),
user: z.string().min(1, { message: "Majburiy maydon" }),
date: z.string().min(1, { message: "Majburiy maydon" }),

View File

@@ -49,7 +49,7 @@ const AddedPlan = ({ initialValues, setDialogOpen }: Props) => {
const form = useForm<z.infer<typeof createPlanFormData>>({
resolver: zodResolver(createPlanFormData),
defaultValues: {
name: initialValues?.title || "",
// name: initialValues?.title || "",
description: initialValues?.description || "",
user: initialValues ? String(initialValues.user.id) : "",
date: initialValues ? initialValues?.date : "",
@@ -174,13 +174,15 @@ const AddedPlan = ({ initialValues, setDialogOpen }: Props) => {
body: {
date: formatDate.format(data.date, "YYYY-MM-DD"),
description: data.description,
...(data.name && {
title: data.name,
}),
extra_location: {
latitude: initialValues.latitude,
longitude: initialValues.longitude,
},
latitude: initialValues.latitude,
longitude: initialValues.longitude,
title: data.name,
},
id: initialValues.id,
});
@@ -194,7 +196,9 @@ const AddedPlan = ({ initialValues, setDialogOpen }: Props) => {
},
latitude: lat,
longitude: long,
title: data.name,
...(data.name && {
title: data.name,
}),
doctor_id: data.doctor_id ? Number(data.doctor_id) : null,
pharmacy_id: data.pharmacy_id ? Number(data.pharmacy_id) : null,
user_id: Number(data.user),
@@ -274,7 +278,7 @@ const AddedPlan = ({ initialValues, setDialogOpen }: Props) => {
: "opacity-0",
)}
/>
{u.first_name} {u.last_name} {u.region.name}
{u.first_name} {u.last_name} {u.region?.name}
</CommandItem>
))}
</CommandGroup>

View File

@@ -1,4 +1,6 @@
import type { PlanListData } from "@/features/plans/lib/data";
import { userStore } from "@/shared/hooks/user";
import formatDate from "@/shared/lib/formatDate";
import { Button } from "@/shared/ui/button";
import {
Table,
@@ -33,6 +35,7 @@ const PalanTable = ({
setDialogOpen,
handleDelete,
}: Props) => {
const { user: getme } = userStore();
return (
<div className="flex-1 overflow-auto">
{(isLoading || isFetching) && (
@@ -58,6 +61,8 @@ const PalanTable = ({
<TableHead className="text-start">ID</TableHead>
<TableHead className="text-start">Reja nomi</TableHead>
<TableHead className="text-start">Tavsifi</TableHead>
<TableHead className="text-start">Qo'shilgan sanasi</TableHead>
<TableHead className="text-start">Bajarilish sanasi</TableHead>
<TableHead className="text-start">Kimga tegishli</TableHead>
<TableHead className="text-start">Shifokor biriktirgan</TableHead>
<TableHead className="text-start">
@@ -73,6 +78,12 @@ const PalanTable = ({
<TableCell>{plan.id}</TableCell>
<TableCell>{plan.title}</TableCell>
<TableCell>{plan.description}</TableCell>
<TableCell>
{formatDate.format(plan.created_at, "DD-MM-YYYY")}
</TableCell>
<TableCell>
{formatDate.format(plan.date, "DD-MM-YYYY")}
</TableCell>
<TableCell>
{plan.user.first_name + " " + plan.user.last_name}
</TableCell>
@@ -115,15 +126,19 @@ const PalanTable = ({
>
<Edit className="h-4 w-4" />
</Button>
<Button
variant="destructive"
size="sm"
className="cursor-pointer"
disabled={plan.comment ? true : false}
onClick={() => handleDelete(plan)}
>
<Trash className="h-4 w-4" />
</Button>
{getme?.is_superuser && (
<Button
variant="destructive"
size="sm"
className="cursor-pointer"
disabled={
!getme?.is_superuser || plan.comment ? true : false
}
onClick={() => handleDelete(plan)}
>
<Trash className="h-4 w-4" />
</Button>
)}
</TableCell>
</TableRow>
))}

View File

@@ -1,4 +1,6 @@
import type { RegionListResData } from "@/features/region/lib/data";
import { userStore } from "@/shared/hooks/user";
import formatDate from "@/shared/lib/formatDate";
import { Button } from "@/shared/ui/button";
import {
Table,
@@ -26,6 +28,7 @@ const RegionTable = ({
setDialogOpen: Dispatch<SetStateAction<boolean>>;
handleDelete: (user: RegionListResData) => void;
}) => {
const { user: getme } = userStore();
return (
<div className="flex-1 overflow-auto">
{isLoading && (
@@ -49,6 +52,7 @@ const RegionTable = ({
<TableRow className="text-center">
<TableHead className="text-start">ID</TableHead>
<TableHead className="text-start">Nomi</TableHead>
<TableHead className="text-start">Qo'shilgan sanasi</TableHead>
</TableRow>
</TableHeader>
<TableBody>
@@ -56,6 +60,9 @@ const RegionTable = ({
<TableRow key={plan.id} className="text-start">
<TableCell>{index + 1}</TableCell>
<TableCell>{plan.name}</TableCell>
<TableCell>
{formatDate.format(plan.created_at, "DD-MM-YYYY")}
</TableCell>
<TableCell className="flex gap-2 justify-end">
<Button
variant="outline"
@@ -68,14 +75,17 @@ const RegionTable = ({
>
<Edit className="h-4 w-4" />
</Button>
<Button
variant="destructive"
size="sm"
className="cursor-pointer"
onClick={() => handleDelete(plan)}
>
<Trash className="h-4 w-4" />
</Button>
{getme?.is_superuser && (
<Button
variant="destructive"
size="sm"
disabled={!getme?.is_superuser}
className="cursor-pointer"
onClick={() => handleDelete(plan)}
>
<Trash className="h-4 w-4" />
</Button>
)}
</TableCell>
</TableRow>
))}

View File

@@ -420,7 +420,7 @@ export const AddedSpecification = ({ initialValues, setDialogOpen }: Props) => {
: "opacity-0",
)}
/>
{u.first_name} {u.last_name} {u.region.name}
{u.first_name} {u.last_name} {u.region?.name}
</CommandItem>
))}
</CommandGroup>

View File

@@ -5,6 +5,7 @@ import { type OrderListDataRes } from "@/features/specifications/lib/data";
import { AddedSpecification } from "@/features/specifications/ui/AddedSpecification";
import DeleteOrder from "@/features/specifications/ui/DeleteOrder";
import { SpecificationDetail } from "@/features/specifications/ui/SpecificationDetail ";
import { userStore } from "@/shared/hooks/user";
import formatPrice from "@/shared/lib/formatPrice";
import { Button } from "@/shared/ui/button";
import {
@@ -34,6 +35,7 @@ const SpecificationsList = () => {
const [dialogOpen, setDialogOpen] = useState(false);
const [currentPage, setCurrentPage] = useState(1);
const limit = 20;
const { user: getme } = userStore();
const {
data: order,
@@ -154,14 +156,17 @@ const SpecificationsList = () => {
>
<Pencil size={18} />
</Button>
<Button
size="icon"
variant="destructive"
className="cursor-pointer"
onClick={() => handleDelete(item)}
>
<Trash2 size={18} />
</Button>
{getme?.is_superuser && (
<Button
size="icon"
disabled={!getme?.is_superuser}
variant="destructive"
className="cursor-pointer"
onClick={() => handleDelete(item)}
>
<Trash2 size={18} />
</Button>
)}
</TableCell>
</TableRow>
))}

View File

@@ -202,7 +202,7 @@ const AddedTourPlan = ({ initialValues, setDialogOpen }: Props) => {
: "opacity-0",
)}
/>
{u.first_name} {u.last_name} {u.region.name}
{u.first_name} {u.last_name} {u.region?.name}
</CommandItem>
))}
</CommandGroup>

View File

@@ -1,4 +1,5 @@
import type { PlanTourListDataRes } from "@/features/tour-plan/lib/data";
import { userStore } from "@/shared/hooks/user";
import formatDate from "@/shared/lib/formatDate";
import { Button } from "@/shared/ui/button";
import {
@@ -36,6 +37,7 @@ const TourPlanTable = ({
setDialogOpen,
setDetailOpen,
}: Props) => {
const { user: getme } = userStore();
return (
<div className="flex-1 overflow-auto">
{(isLoading || isFetching) && (
@@ -107,14 +109,17 @@ const TourPlanTable = ({
>
<Edit className="h-4 w-4" />
</Button>
<Button
variant="destructive"
size="icon"
className="cursor-pointer"
onClick={() => handleDelete(plan)}
>
<Trash className="h-4 w-4" />
</Button>
{getme?.is_superuser && (
<Button
variant="destructive"
size="icon"
disabled={!getme?.is_superuser}
className="cursor-pointer"
onClick={() => handleDelete(plan)}
>
<Trash className="h-4 w-4" />
</Button>
)}
</TableCell>
</TableRow>
))

View File

@@ -65,11 +65,11 @@ export interface UserListRes {
export interface UserListData {
id: number;
first_name: string;
last_name: string;
first_name: string | null;
last_name: string | null;
region: {
id: number;
name: string;
name: string | null;
};
is_active: boolean;
telegram_id: string;

View File

@@ -1,5 +1,7 @@
import { user_api } from "@/features/users/lib/api";
import type { UserListData, UserListRes } from "@/features/users/lib/data";
import { userStore } from "@/shared/hooks/user";
import formatDate from "@/shared/lib/formatDate";
import { Button } from "@/shared/ui/button";
import { Checkbox } from "@/shared/ui/checkbox";
import {
@@ -43,6 +45,7 @@ const UserTable = ({
currentPage,
}: Props) => {
const queryClient = useQueryClient();
const { user: getme } = userStore();
const [pendingUserId, setPendingUserId] = useState<number | null>(null);
// TableHeader checkbox holati
@@ -129,6 +132,7 @@ const UserTable = ({
<TableHead className="text-start">Ismi</TableHead>
<TableHead className="text-start">Familiyasi</TableHead>
<TableHead className="text-start">Hududi</TableHead>
<TableHead className="text-start">Qo'shilgan sanasi</TableHead>
<TableHead className="text-center">Holati</TableHead>
<TableHead className="text-right">Harakatlar</TableHead>
</TableRow>
@@ -148,9 +152,18 @@ const UserTable = ({
</TableCell>
)}
<TableCell>{index + 1 + (currentPage - 1) * 20}</TableCell>
<TableCell>{user.first_name}</TableCell>
<TableCell>{user.last_name}</TableCell>
<TableCell>{user.region.name}</TableCell>
<TableCell>
{user.first_name ? user.first_name : "No'malum"}
</TableCell>
<TableCell>
{user.last_name ? user.last_name : "No'malum"}
</TableCell>
<TableCell>
{user?.region ? user?.region?.name : "No'malum"}
</TableCell>
<TableCell>
{formatDate.format(user?.created_at, "DD-MM-YYYY")}
</TableCell>
<TableCell className="text-center">
<Button
className={clsx(
@@ -182,15 +195,17 @@ const UserTable = ({
>
<Edit className="h-4 w-4" />
</Button>
<Button
variant="destructive"
size="sm"
disabled={sendMessage}
onClick={() => handleDelete(user)}
className="cursor-pointer"
>
<Trash className="h-4 w-4" />
</Button>
{getme?.is_superuser && (
<Button
variant="destructive"
size="sm"
disabled={!getme?.is_superuser || sendMessage}
onClick={() => handleDelete(user)}
className="cursor-pointer"
>
<Trash className="h-4 w-4" />
</Button>
)}
</TableCell>
</TableRow>
))

View File

@@ -8,8 +8,10 @@ export const API_URLS = {
REGIONS: `${API_V}admin/region/`,
DISTRICT: `${API_V}admin/district/`,
DOCTOR: `${API_V}admin/doctor/`,
DOCTOR_EXPORT: `${API_V}admin/doctor/export/`,
OBJECT: `${API_V}admin/place/`,
PHARMACIES: `${API_V}admin/pharmacy/`,
PHARMACIES_EXPORT: `${API_V}admin/pharmacy/export/`,
PLANS: `${API_V}admin/plan/`,
PILL: `${API_V}admin/product/`,
LOCATION: `${API_V}admin/location/`,
@@ -21,4 +23,5 @@ export const API_URLS = {
SUPPORT: `${API_V}admin/support/list/`,
DISTRIBUTED: `${API_V}admin/distributed_product/list/`,
SEND_MESSAGE: `${API_V}admin/send_message/`,
GET_ME: `${API_V}accounts/user/me/`,
};

View File

@@ -0,0 +1,11 @@
import httpClient from "@/shared/config/api/httpClient";
import { API_URLS } from "@/shared/config/api/URLs";
import type { GetMeRes } from "@/shared/config/api/user/type";
import type { AxiosResponse } from "axios";
export const user_api = {
async getMe(): Promise<AxiosResponse<GetMeRes>> {
const res = httpClient.get(API_URLS.GET_ME);
return res;
},
};

View File

@@ -0,0 +1,16 @@
export interface GetMeRes {
status: string;
status_code: number;
data: GetMeResData;
}
export interface GetMeResData {
created_at: string;
first_name: string;
id: number;
is_active: boolean;
is_superuser: boolean;
last_name: string;
region: null | number;
telegram_id: null | number;
}

15
src/shared/hooks/user.ts Normal file
View File

@@ -0,0 +1,15 @@
import type { GetMeResData } from "@/shared/config/api/user/type";
import { create } from "zustand";
type State = {
user: GetMeResData | null;
};
type Actions = {
addUser: (user: GetMeResData) => void;
};
export const userStore = create<State & Actions>((set) => ({
user: null,
addUser: (user: GetMeResData | null) => set(() => ({ user })),
}));

View File

@@ -6,7 +6,6 @@ import {
ClipboardList,
FileText,
Hospital,
ListChecks,
LogOut,
Map,
MapPin,
@@ -77,11 +76,11 @@ const items = [
url: "/dashboard/reports",
icon: ClipboardList,
},
{
title: "Tur planlar",
url: "/dashboard/tour-plan",
icon: ListChecks,
},
// {
// title: "Tur planlar",
// url: "/dashboard/tour-plan",
// icon: ListChecks,
// },
{
title: "Hududlar",
url: "/dashboard/region",

View File

@@ -10,4 +10,8 @@ export default defineConfig({
resolve: {
alias: [{ find: "@", replacement: path.resolve(__dirname, "src") }],
},
server: {
port: 5175,
host: true, // barcha hostlarga ruxsat
},
});