feat: Add more pages
This commit is contained in:
		
							
								
								
									
										75
									
								
								src/pages/Country/CountryCreatePage/index.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										75
									
								
								src/pages/Country/CountryCreatePage/index.tsx
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,75 @@
 | 
			
		||||
import { Button, Paper, TextField } 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 } 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 handleCreate = async () => {
 | 
			
		||||
    try {
 | 
			
		||||
      setIsLoading(true);
 | 
			
		||||
      await countryStore.createCountry(code, name);
 | 
			
		||||
      toast.success("Страна успешно создана");
 | 
			
		||||
      navigate("/country");
 | 
			
		||||
    } catch (error) {
 | 
			
		||||
      toast.error("Ошибка при создании страны");
 | 
			
		||||
    } finally {
 | 
			
		||||
      setIsLoading(false);
 | 
			
		||||
    }
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  return (
 | 
			
		||||
    <Paper className="w-full h-full p-3 flex flex-col gap-10">
 | 
			
		||||
      <LanguageSwitcher />
 | 
			
		||||
      <div className="flex items-center gap-4">
 | 
			
		||||
        <button
 | 
			
		||||
          className="flex items-center gap-2"
 | 
			
		||||
          onClick={() => navigate("/country")}
 | 
			
		||||
        >
 | 
			
		||||
          <ArrowLeft size={20} />
 | 
			
		||||
          Назад
 | 
			
		||||
        </button>
 | 
			
		||||
      </div>
 | 
			
		||||
 | 
			
		||||
      <div className="flex flex-col gap-10 w-full items-end">
 | 
			
		||||
        <TextField
 | 
			
		||||
          fullWidth
 | 
			
		||||
          label="Код страны"
 | 
			
		||||
          value={code}
 | 
			
		||||
          required
 | 
			
		||||
          onChange={(e) => setCode(e.target.value)}
 | 
			
		||||
        />
 | 
			
		||||
        <TextField
 | 
			
		||||
          fullWidth
 | 
			
		||||
          label="Название"
 | 
			
		||||
          value={name}
 | 
			
		||||
          required
 | 
			
		||||
          onChange={(e) => setName(e.target.value)}
 | 
			
		||||
        />
 | 
			
		||||
 | 
			
		||||
        <Button
 | 
			
		||||
          variant="contained"
 | 
			
		||||
          className="w-min flex gap-2 items-center"
 | 
			
		||||
          startIcon={<Save size={20} />}
 | 
			
		||||
          onClick={handleCreate}
 | 
			
		||||
          disabled={isLoading || !name || !code}
 | 
			
		||||
        >
 | 
			
		||||
          {isLoading ? (
 | 
			
		||||
            <Loader2 size={20} className="animate-spin" />
 | 
			
		||||
          ) : (
 | 
			
		||||
            "Создать"
 | 
			
		||||
          )}
 | 
			
		||||
        </Button>
 | 
			
		||||
      </div>
 | 
			
		||||
    </Paper>
 | 
			
		||||
  );
 | 
			
		||||
});
 | 
			
		||||
		Reference in New Issue
	
	Block a user