feat: Add more pages
This commit is contained in:
		
							
								
								
									
										86
									
								
								src/pages/Country/CountryListPage/index.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										86
									
								
								src/pages/Country/CountryListPage/index.tsx
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,86 @@
 | 
			
		||||
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, Trash2 } from "lucide-react";
 | 
			
		||||
import { useNavigate } from "react-router-dom";
 | 
			
		||||
import { CreateButton, DeleteModal, LanguageSwitcher } from "@widgets";
 | 
			
		||||
 | 
			
		||||
export const CountryListPage = observer(() => {
 | 
			
		||||
  const { countries, getCountries } = countryStore;
 | 
			
		||||
  const navigate = useNavigate();
 | 
			
		||||
  const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
 | 
			
		||||
  const [rowId, setRowId] = useState<string | null>(null); // Lifted state
 | 
			
		||||
  const { language } = languageStore;
 | 
			
		||||
 | 
			
		||||
  useEffect(() => {
 | 
			
		||||
    getCountries();
 | 
			
		||||
  }, [language]);
 | 
			
		||||
 | 
			
		||||
  const columns: GridColDef[] = [
 | 
			
		||||
    {
 | 
			
		||||
      field: "name",
 | 
			
		||||
      headerName: "Название",
 | 
			
		||||
      flex: 1,
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
      field: "actions",
 | 
			
		||||
      headerName: "Действия",
 | 
			
		||||
      align: "center",
 | 
			
		||||
      headerAlign: "center",
 | 
			
		||||
 | 
			
		||||
      renderCell: (params: GridRenderCellParams) => {
 | 
			
		||||
        return (
 | 
			
		||||
          <div className="flex h-full gap-7 justify-center items-center">
 | 
			
		||||
            <button onClick={() => navigate(`/country/${params.row.code}`)}>
 | 
			
		||||
              <Eye size={20} className="text-green-500" />
 | 
			
		||||
            </button>
 | 
			
		||||
            <button
 | 
			
		||||
              onClick={() => {
 | 
			
		||||
                setIsDeleteModalOpen(true);
 | 
			
		||||
                setRowId(params.row.code);
 | 
			
		||||
              }}
 | 
			
		||||
            >
 | 
			
		||||
              <Trash2 size={20} className="text-red-500" />
 | 
			
		||||
            </button>
 | 
			
		||||
          </div>
 | 
			
		||||
        );
 | 
			
		||||
      },
 | 
			
		||||
    },
 | 
			
		||||
  ];
 | 
			
		||||
 | 
			
		||||
  const rows = countries.map((country) => ({
 | 
			
		||||
    id: country.code,
 | 
			
		||||
    code: country.code,
 | 
			
		||||
    name: country.name,
 | 
			
		||||
  }));
 | 
			
		||||
 | 
			
		||||
  return (
 | 
			
		||||
    <>
 | 
			
		||||
      <LanguageSwitcher />
 | 
			
		||||
 | 
			
		||||
      <div className="w-full">
 | 
			
		||||
        <div className="flex justify-between items-center mb-10">
 | 
			
		||||
          <h1 className="text-2xl">Страны</h1>
 | 
			
		||||
          <CreateButton label="Создать страну" path="/country/create" />
 | 
			
		||||
        </div>
 | 
			
		||||
        <DataGrid rows={rows} columns={columns} hideFooter />
 | 
			
		||||
      </div>
 | 
			
		||||
      <DeleteModal
 | 
			
		||||
        open={isDeleteModalOpen}
 | 
			
		||||
        onDelete={async () => {
 | 
			
		||||
          if (rowId) {
 | 
			
		||||
            await countryStore.deleteCountry(rowId);
 | 
			
		||||
            getCountries(); // Refresh the list after deletion
 | 
			
		||||
          }
 | 
			
		||||
          setIsDeleteModalOpen(false);
 | 
			
		||||
          setRowId(null);
 | 
			
		||||
        }}
 | 
			
		||||
        onCancel={() => {
 | 
			
		||||
          setIsDeleteModalOpen(false);
 | 
			
		||||
          setRowId(null);
 | 
			
		||||
        }}
 | 
			
		||||
      />
 | 
			
		||||
    </>
 | 
			
		||||
  );
 | 
			
		||||
});
 | 
			
		||||
		Reference in New Issue
	
	Block a user