From 2134eaf7326a8ea24c37ca30043127b9223f8c8a Mon Sep 17 00:00:00 2001 From: Quan HL Date: Mon, 23 Oct 2023 06:49:41 +0700 Subject: [PATCH] feat advance --- src/window/settings/basic.tsx | 163 ++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 src/window/settings/basic.tsx diff --git a/src/window/settings/basic.tsx b/src/window/settings/basic.tsx new file mode 100644 index 0000000..a466c86 --- /dev/null +++ b/src/window/settings/basic.tsx @@ -0,0 +1,163 @@ +import { + Box, + Button, + FormControl, + FormLabel, + HStack, + Image, + Input, + Spacer, + Text, + VStack, + useToast, +} from "@chakra-ui/react"; +import { useEffect, useState } from "react"; +import PasswordInput from "src/components/password-input"; +import { getSettings, saveSettings } from "src/storage"; +import InfoIcon from "src/imgs/icons/Info.svg"; +import ResetIcon from "src/imgs/icons/Reset.svg"; +import { AppSettings } from "src/common/types"; +import { DEFAULT_TOAST_DURATION } from "src/common/constants"; + +export const BasicSettings = () => { + const [sipDomain, setSipDomain] = useState(""); + const [sipServerAddress, setSipServerAddress] = useState(""); + const [sipUsername, setSipUsername] = useState(""); + const [sipPassword, setSipPassword] = useState(""); + const [sipDisplayName, setSipDisplayName] = useState(""); + + const toast = useToast(); + + const handleSubmit = (e: React.FormEvent) => { + e.preventDefault(); + + const settings: AppSettings = { + sipDomain, + sipServerAddress: sipServerAddress, + sipUsername, + sipPassword, + sipDisplayName, + }; + + saveSettings(settings); + toast({ + title: "Settings saved successfully", + status: "success", + duration: DEFAULT_TOAST_DURATION, + isClosable: true, + colorScheme: "jambonz", + }); + }; + + const resetSetting = () => { + saveSettings({} as AppSettings); + setSipDomain(""); + setSipServerAddress(""); + setSipUsername(""); + setSipPassword(""); + setSipDisplayName(""); + }; + + useEffect(() => { + const settings = getSettings(); + if (settings.sipDomain) { + setSipDomain(settings.sipDomain); + } + if (settings.sipServerAddress) { + setSipServerAddress(settings.sipServerAddress); + } + if (settings.sipUsername) { + setSipUsername(settings.sipUsername); + } + if (settings.sipPassword) { + setSipPassword(settings.sipPassword); + } + if (settings.sipDisplayName) { + setSipDisplayName(settings.sipDisplayName); + } + }, []); + return ( +
+ + + + Jambonz SIP Domain + setSipDomain(e.target.value)} + /> + + + + Jambonz Server Address + setSipServerAddress(e.target.value)} + /> + + + + SIP Username + setSipUsername(e.target.value)} + /> + + + + SIP Password + + + + + SIP Display Name + setSipDisplayName(e.target.value)} + /> + + + + + + + Get help + + + + + + + Reset settings + + + + +
+ ); +}; + +export default BasicSettings;