fixed open account form bug, aligned UI sty;les to match figma css

This commit is contained in:
abdurahman
2024-08-29 22:32:45 +01:00
parent a36b497444
commit 8a33284338
7 changed files with 71 additions and 15 deletions

View File

@@ -4,6 +4,12 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" /> <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Source+Sans+3:ital,wght@0,200..900;1,200..900&display=swap"
rel="stylesheet"
/>
<meta name="theme-color" content="#000000" /> <meta name="theme-color" content="#000000" />
<meta <meta
name="description" name="description"

View File

@@ -18,7 +18,6 @@ function AnimateOnShow({
animate={{ opacity: 1, y: 0 }} animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: exit }} exit={{ opacity: 0, y: exit }}
transition={{ duration: duration }} transition={{ duration: duration }}
className="test"
> >
{children} {children}
</motion.div> </motion.div>

View File

@@ -1,6 +1,10 @@
import { extendTheme } from "@chakra-ui/react"; import { extendTheme } from "@chakra-ui/react";
const mainTheme = extendTheme({ const mainTheme = extendTheme({
fonts: {
heading: "'Source Sans 3', 'sans-serif'",
body: "'Source Sans 3', 'sans-serif'",
},
colors: { colors: {
jambonz: { jambonz: {
0: "#EDDEE3", 0: "#EDDEE3",

View File

@@ -1,18 +1,21 @@
import { HStack, Text, VStack } from "@chakra-ui/react"; import { HStack, Text, VStack } from "@chakra-ui/react";
import { faCheck } from "@fortawesome/free-solid-svg-icons"; import { faCheck } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import React from "react"; import React, { RefObject } from "react";
import { IAppSettings } from "src/common/types"; import { IAppSettings } from "src/common/types";
function AvailableAccounts({ function AvailableAccounts({
allSettings, allSettings,
onSetActive, onSetActive,
refData,
}: { }: {
allSettings: IAppSettings[]; allSettings: IAppSettings[];
onSetActive: (x: number) => void; onSetActive: (x: number) => void;
refData: RefObject<HTMLDivElement>;
}) { }) {
return ( return (
<VStack <VStack
ref={refData}
w={"full"} w={"full"}
alignItems={"start"} alignItems={"start"}
bg={"grey.200"} bg={"grey.200"}

View File

@@ -142,6 +142,7 @@ export const Phone = ({
const unregisteredReasonRef = useRef(""); const unregisteredReasonRef = useRef("");
const isInputNumberFocusRef = useRef(false); const isInputNumberFocusRef = useRef(false);
const secondsRef = useRef(seconds); const secondsRef = useRef(seconds);
const accountsCardRef = useRef<HTMLDivElement | null>(null);
const toast = useToast(); const toast = useToast();
@@ -250,6 +251,18 @@ export const Phone = ({
}; };
}, []); }, []);
useEffect(() => {
if (showAccounts) {
document.addEventListener("mousedown", handleClickOutside);
} else {
document.removeEventListener("mousedown", handleClickOutside);
}
return () => {
document.removeEventListener("mousedown", handleClickOutside);
};
}, [showAccounts]);
const fetchRegisterUser = () => { const fetchRegisterUser = () => {
getSelfRegisteredUser(sipUsernameRef.current) getSelfRegisteredUser(sipUsernameRef.current)
.then(({ json }) => { .then(({ json }) => {
@@ -501,6 +514,12 @@ export const Phone = ({
reload(); reload();
}; };
const handleClickOutside = (event: Event) => {
const target = event.target as Node;
if (accountsCardRef.current && !accountsCardRef.current.contains(target)) {
setShowAccounts(false);
}
};
return ( return (
<Box flexDirection="column"> <Box flexDirection="column">
{allSettings.length >= 1 ? ( {allSettings.length >= 1 ? (
@@ -556,6 +575,7 @@ export const Phone = ({
{showAccounts && ( {showAccounts && (
<AnimateOnShow initial={2} exit={0} duration={0.01}> <AnimateOnShow initial={2} exit={0} duration={0.01}>
<AvailableAccounts <AvailableAccounts
refData={accountsCardRef}
allSettings={allSettings} allSettings={allSettings}
onSetActive={handleSetActive} onSetActive={handleSetActive}
/> />

View File

@@ -13,30 +13,44 @@ import SettingItem from "src/window/settings/settingItem";
export function AccordionList({ export function AccordionList({
allSettings, allSettings,
reload, reload,
onOpenForm, handleOpenFormInAccordion,
handleCloseFormInAccordion,
isNewFormOpen, isNewFormOpen,
handleCloseNewForm,
}: { }: {
allSettings: IAppSettings[]; allSettings: IAppSettings[];
reload: () => void; reload: () => void;
onOpenForm: () => void; handleOpenFormInAccordion: () => void;
handleCloseFormInAccordion: () => void;
isNewFormOpen: boolean; isNewFormOpen: boolean;
handleCloseNewForm: () => void;
}) { }) {
const { isOpen, onToggle } = useDisclosure(); const { isOpen, onOpen, onClose } = useDisclosure();
const [openAcc, setOpenAcc] = useState(0); const [openAcc, setOpenAcc] = useState(0);
const closeFormInAccordion = function () { const closeFormInAccordion = function () {
onClose();
handleCloseFormInAccordion();
reload(); reload();
onToggle();
}; };
function handleToggleAcc(accIndex: number) { function handleToggleAcc(accIndex: number) {
if (isNewFormOpen) return; //prevents opening form if for for new account is open if (isNewFormOpen) handleCloseNewForm(); //closes new form if open
onOpenForm(); handleOpenFormInAccordion();
setOpenAcc(accIndex); setOpenAcc(accIndex);
onToggle(); // onToggle();
onOpen();
} }
return ( return (
<Accordion index={isOpen ? [openAcc] : []} allowToggle> <Accordion
index={isOpen ? [openAcc] : []}
allowToggle
sx={{
"& > *:last-child": {
marginBottom: "7px",
},
}}
>
{allSettings.map((data, index) => ( {allSettings.map((data, index) => (
<AccordionItem borderColor={"white"} key={index}> <AccordionItem borderColor={"white"} key={index}>
<AccordionButton <AccordionButton
@@ -47,10 +61,12 @@ export function AccordionList({
cursor: "default", cursor: "default",
}} }}
> >
<SettingItem {isOpen && index === openAcc ? null : (
onToggleAcc={() => handleToggleAcc(index)} <SettingItem
data={data} onToggleAcc={() => handleToggleAcc(index)}
/> data={data}
/>
)}
</AccordionButton> </AccordionButton>
<AccordionPanel pb={4} px={0}> <AccordionPanel pb={4} px={0}>
<AccountForm <AccountForm

View File

@@ -26,6 +26,12 @@ export const Settings = () => {
function handleCloseForm() { function handleCloseForm() {
setShowForm(false); setShowForm(false);
} }
function handleOpenFormInAccordion() {
setShowFormInAccordion(true);
}
function handleCloseFormInAccordion() {
setShowFormInAccordion(false);
}
const loadSettings = function () { const loadSettings = function () {
setAllSettings(getSettings()); setAllSettings(getSettings());
@@ -37,10 +43,12 @@ export const Settings = () => {
<div> <div>
<Box> <Box>
<AccordionList <AccordionList
onOpenForm={() => setShowFormInAccordion((prev) => !prev)} handleOpenFormInAccordion={handleOpenFormInAccordion}
handleCloseFormInAccordion={handleCloseFormInAccordion}
allSettings={allSettings} allSettings={allSettings}
reload={loadSettings} reload={loadSettings}
isNewFormOpen={showForm} isNewFormOpen={showForm}
handleCloseNewForm={handleCloseForm}
/> />
</Box> </Box>
{!showForm && !showFormInAccordion && ( {!showForm && !showFormInAccordion && (