feat: Add edit pages with cache
				
					
				
			This commit is contained in:
		@@ -4,20 +4,20 @@ import { ArrowLeft, Save } from "lucide-react";
 | 
			
		||||
import { Loader2 } from "lucide-react";
 | 
			
		||||
import { useNavigate } from "react-router-dom";
 | 
			
		||||
import { toast } from "react-toastify";
 | 
			
		||||
import { countryStore } from "@shared";
 | 
			
		||||
import { countryStore, languageStore } from "@shared";
 | 
			
		||||
import { useState } from "react";
 | 
			
		||||
import { LanguageSwitcher } from "@widgets";
 | 
			
		||||
 | 
			
		||||
export const CountryCreatePage = observer(() => {
 | 
			
		||||
  const navigate = useNavigate();
 | 
			
		||||
  const [name, setName] = useState("");
 | 
			
		||||
  const [code, setCode] = useState("");
 | 
			
		||||
  const [isLoading, setIsLoading] = useState(false);
 | 
			
		||||
  const { language } = languageStore;
 | 
			
		||||
  const { createCountryData, setCountryData, createCountry } = countryStore;
 | 
			
		||||
 | 
			
		||||
  const handleCreate = async () => {
 | 
			
		||||
    try {
 | 
			
		||||
      setIsLoading(true);
 | 
			
		||||
      await countryStore.createCountry(code, name);
 | 
			
		||||
      await createCountry();
 | 
			
		||||
      toast.success("Страна успешно создана");
 | 
			
		||||
      navigate("/country");
 | 
			
		||||
    } catch (error) {
 | 
			
		||||
@@ -44,16 +44,24 @@ export const CountryCreatePage = observer(() => {
 | 
			
		||||
        <TextField
 | 
			
		||||
          fullWidth
 | 
			
		||||
          label="Код страны"
 | 
			
		||||
          value={code}
 | 
			
		||||
          value={createCountryData.code}
 | 
			
		||||
          required
 | 
			
		||||
          onChange={(e) => setCode(e.target.value)}
 | 
			
		||||
          onChange={(e) =>
 | 
			
		||||
            setCountryData(
 | 
			
		||||
              e.target.value,
 | 
			
		||||
              createCountryData[language].name,
 | 
			
		||||
              language
 | 
			
		||||
            )
 | 
			
		||||
          }
 | 
			
		||||
        />
 | 
			
		||||
        <TextField
 | 
			
		||||
          fullWidth
 | 
			
		||||
          label="Название"
 | 
			
		||||
          value={name}
 | 
			
		||||
          value={createCountryData[language].name}
 | 
			
		||||
          required
 | 
			
		||||
          onChange={(e) => setName(e.target.value)}
 | 
			
		||||
          onChange={(e) =>
 | 
			
		||||
            setCountryData(createCountryData.code, e.target.value, language)
 | 
			
		||||
          }
 | 
			
		||||
        />
 | 
			
		||||
 | 
			
		||||
        <Button
 | 
			
		||||
@@ -61,7 +69,7 @@ export const CountryCreatePage = observer(() => {
 | 
			
		||||
          className="w-min flex gap-2 items-center"
 | 
			
		||||
          startIcon={<Save size={20} />}
 | 
			
		||||
          onClick={handleCreate}
 | 
			
		||||
          disabled={isLoading || !name || !code}
 | 
			
		||||
          disabled={isLoading || !createCountryData[language].name}
 | 
			
		||||
        >
 | 
			
		||||
          {isLoading ? (
 | 
			
		||||
            <Loader2 size={20} className="animate-spin" />
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user