update new api reques and response

This commit is contained in:
Samandar Turgunboyev
2025-12-05 17:47:11 +05:00
parent 21725762c6
commit db6bfa7e40
30 changed files with 1755 additions and 262 deletions

View File

@@ -0,0 +1,21 @@
import type { SupportListRes } from "@/features/support/lib/data";
import httpClient from "@/shared/config/api/httpClient";
import { SUPPORT } from "@/shared/config/api/URLs";
import type { AxiosResponse } from "axios";
export const support_api = {
async list(): Promise<AxiosResponse<SupportListRes>> {
const res = await httpClient.get(`${SUPPORT}list/`);
return res;
},
async send(body: {
district_id?: number;
problem: string;
date: string;
type: "PROBLEM" | "HELP";
}) {
const res = await httpClient.post(`${SUPPORT}send/`, body);
return res;
},
};

View File

@@ -0,0 +1,32 @@
import type { SupportListData } from "@/features/support/lib/data";
import type { ColumnDef } from "@tanstack/react-table";
export const columnsSupport = (): ColumnDef<SupportListData>[] => [
{
accessorKey: "id",
header: () => <div className="text-center"></div>,
cell: ({ row }) => {
return <div className="text-center font-medium">{row.index + 1}</div>;
},
},
{
accessorKey: "name",
header: () => <div className="text-center">Xabar tavsifi</div>,
cell: ({ row }) => {
return (
<div className="text-center font-medium">{row.original.problem}</div>
);
},
},
{
accessorKey: "districtName",
header: () => <div className="text-center">Tuman</div>,
cell: ({ row }) => {
return (
<div className="text-center font-medium">
{row.original.district ? row.original.district.name : "-"}
</div>
);
},
},
];

View File

@@ -0,0 +1,80 @@
"use client";
import {
flexRender,
getCoreRowModel,
useReactTable,
type ColumnDef,
} from "@tanstack/react-table";
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/shared/ui/table";
interface DataTableProps<ObjectAllData, TValue> {
columns: ColumnDef<ObjectAllData, TValue>[];
data: ObjectAllData[];
}
export function DataTableSupport<ObjectAllData, TValue>({
columns,
data,
}: DataTableProps<ObjectAllData, TValue>) {
const table = useReactTable({
data,
columns,
getCoreRowModel: getCoreRowModel(),
});
return (
<div className="overflow-hidden rounded-md border">
<Table className="">
<TableHeader>
{table.getHeaderGroups().map((headerGroup) => (
<TableRow key={headerGroup.id}>
{headerGroup.headers.map((header) => {
return (
<TableHead key={header.id} className="border-r">
{header.isPlaceholder
? null
: flexRender(
header.column.columnDef.header,
header.getContext(),
)}
</TableHead>
);
})}
</TableRow>
))}
</TableHeader>
<TableBody>
{table.getRowModel().rows?.length ? (
table.getRowModel().rows.map((row) => (
<TableRow
key={row.id}
data-state={row.getIsSelected() && "selected"}
>
{row.getVisibleCells().map((cell) => (
<TableCell key={cell.id} className="border-r">
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</TableCell>
))}
</TableRow>
))
) : (
<TableRow>
<TableCell colSpan={columns.length} className="h-24 text-center">
Yordam so'rovlari mavjud emas
</TableCell>
</TableRow>
)}
</TableBody>
</Table>
</div>
);
}

View File

@@ -0,0 +1,23 @@
export interface SupportListRes {
status_code: number;
status: string;
message: string;
data: {
count: number;
next: null | string;
previous: null | string;
results: SupportListData[];
};
}
export interface SupportListData {
id: number;
problem: string;
date: string;
type: string;
district: {
id: number;
name: string;
} | null;
created_at: string;
}