import { DialogBody, DialogCloseTrigger, DialogContent, DialogFooter, DialogHeader, DialogRoot, DialogTitle, DialogTrigger } from "../../../components/ui/dialog" import { Field, Input, Stack, Text } from "@chakra-ui/react" import { IoMdAdd } from "react-icons/io" import { Button } from "../../../components/ui/button" import { useState } from "react"; import { PostCountry, useCreateCountryPostMutation } from "../../../Redux/Service/country.master"; import { Toaster, toaster } from "../../../components/ui/toaster"; function CountryAddModel() { const [createCountryPost] = useCreateCountryPostMutation() const [isOpen, setIsOpen] = useState(false); const [countryName, setCountryName] = useState({ en_name: '', country_code: '', phonecode: '', capital: '', currency: '', currency_name: '', currency_symbol: '', }); const handleOpenModal = () => { setIsOpen(true); // Open modal when clicking "Add" }; const handleSubmit = async () => { if (countryName.en_name === "") { toaster.create({ title: "Error", description: "Input fields cannot be empty", type: "error", }); return; } const payload: PostCountry = { en_name: countryName.en_name, country_code: countryName.country_code, phonecode: countryName.phonecode, capital: countryName.capital, currency: countryName.currency, currency_name: countryName.currency_name, currency_symbol: countryName.currency_symbol, }; try { const response = await createCountryPost(payload).unwrap(); if (response) { toaster.create({ title: "Success", description: "Country added successfully", type: "success", }); setIsOpen(false); } else { toaster.create({ title: "Error", description: "Failed to add Country", type: "error", }); } } catch (error) { console.error("Error updating template:", error); // alert("Failed to update template"); } }; return ( <> setIsOpen(open)}> {/* */} Add Country setCountryName({ ...countryName, en_name: e.target.value })} /> Country Code setCountryName({ ...countryName, country_code: e.target.value })} /> Phone Code setCountryName({ ...countryName, phonecode: e.target.value })} /> Capital setCountryName({ ...countryName, capital: e.target.value })} /> Currency setCountryName({ ...countryName, currency: e.target.value })} /> Currency name setCountryName({ ...countryName, currency_name: e.target.value })} /> Currency Symbol setCountryName({ ...countryName, currency_symbol: e.target.value })} /> ) } export default CountryAddModel