fix: Fix Map page

This commit is contained in:
2025-06-12 22:50:43 +03:00
parent 27cb644242
commit 300ff262ce
41 changed files with 2216 additions and 1055 deletions

View File

@ -2,15 +2,15 @@ import { DataGrid, GridColDef, GridRenderCellParams } from "@mui/x-data-grid";
import { countryStore, languageStore } from "@shared";
import { useEffect, useState } from "react";
import { observer } from "mobx-react-lite";
import { Eye, Pencil, Trash2 } from "lucide-react";
import { Pencil, Trash2, Minus } from "lucide-react";
import { useNavigate } from "react-router-dom";
import { CreateButton, DeleteModal, LanguageSwitcher } from "@widgets";
export const CountryListPage = observer(() => {
const { countries, getCountries } = countryStore;
const { countries, getCountries, deleteCountry } = countryStore;
const navigate = useNavigate();
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
const [rowId, setRowId] = useState<string | null>(null); // Lifted state
const [rowId, setRowId] = useState<string | null>(null);
const { language } = languageStore;
useEffect(() => {
@ -22,6 +22,17 @@ export const CountryListPage = observer(() => {
field: "name",
headerName: "Название",
flex: 1,
renderCell: (params: GridRenderCellParams) => {
return (
<div className="w-full h-full flex items-center ">
{params.value ? (
params.value
) : (
<Minus size={20} className="text-red-500" />
)}
</div>
);
},
},
{
field: "actions",
@ -37,9 +48,9 @@ export const CountryListPage = observer(() => {
>
<Pencil size={20} className="text-blue-500" />
</button>
<button onClick={() => navigate(`/country/${params.row.code}`)}>
{/* <button onClick={() => navigate(`/country/${params.row.code}`)}>
<Eye size={20} className="text-green-500" />
</button>
</button> */}
<button
onClick={() => {
setIsDeleteModalOpen(true);
@ -54,7 +65,7 @@ export const CountryListPage = observer(() => {
},
];
const rows = countries[language]?.map((country) => ({
const rows = countries[language]?.data.map((country) => ({
id: country.code,
code: country.code,
name: country.name,
@ -75,17 +86,14 @@ export const CountryListPage = observer(() => {
<DeleteModal
open={isDeleteModalOpen}
onDelete={async () => {
if (rowId) {
await countryStore.deleteCountry(rowId, language);
getCountries(language); // Refresh the list after deletion
setIsDeleteModalOpen(false);
}
setIsDeleteModalOpen(false);
if (!rowId) return;
await deleteCountry(rowId, language);
setRowId(null);
setIsDeleteModalOpen(false);
}}
onCancel={() => {
setIsDeleteModalOpen(false);
setRowId(null);
setIsDeleteModalOpen(false);
}}
/>
</>