import { Button, Paper, TextField, Autocomplete, FormControl, } from "@mui/material"; import { observer } from "mobx-react-lite"; import { ArrowLeft, Save } from "lucide-react"; import { Loader2 } from "lucide-react"; import { useNavigate } from "react-router-dom"; import { toast } from "react-toastify"; import { countryStore, RU_COUNTRIES, EN_COUNTRIES, ZH_COUNTRIES, } from "@shared"; import { useState } from "react"; export const CountryAddPage = observer(() => { const navigate = useNavigate(); const [isLoading, setIsLoading] = useState(false); const { createCountryData, setCountryData, createCountry } = countryStore; const handleCountryCodeChange = (code: string) => { const ruCountry = RU_COUNTRIES.find((c) => c.code === code); const enCountry = EN_COUNTRIES.find((c) => c.code === code); const zhCountry = ZH_COUNTRIES.find((c) => c.code === code); if (ruCountry && enCountry && zhCountry) { setCountryData(code, ruCountry.name, "ru"); setCountryData(code, enCountry.name, "en"); setCountryData(code, zhCountry.name, "zh"); } }; const handleCreate = async () => { try { setIsLoading(true); await createCountry(); toast.success("Страна успешно создана"); navigate("/country"); } catch (error) { toast.error("Ошибка при создании страны"); } finally { setIsLoading(false); } }; return (
c.code === createCountryData.code) || null } onChange={(_, newValue) => { if (newValue) { handleCountryCodeChange(newValue.code); } }} options={RU_COUNTRIES} getOptionLabel={(option) => `${option.code} - ${option.name}`} renderInput={(params) => ( )} filterOptions={(options, { inputValue }) => { const searchValue = inputValue.toUpperCase(); return options.filter( (option) => option.code.includes(searchValue) || option.name.toLowerCase().includes(inputValue.toLowerCase()) ); }} />
); });