Skip to content

Commit 699e699

Browse files
committed
feat: close the settings popup if saved successfully
1 parent 2126efc commit 699e699

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

web/src/layout/Header/navbar/Menu/Settings/Notifications/FormContactDetails/index.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Button } from "@kleros/ui-components-library";
55
import { uploadSettingsToSupabase } from "utils/uploadSettingsToSupabase";
66
import FormContact from "./FormContact";
77
import messages from "../../../../../../../consts/eip712-messages";
8+
import { ISettings } from "../../types";
89

910
const FormContainer = styled.form`
1011
position: relative;
@@ -25,15 +26,15 @@ const FormContactContainer = styled.div`
2526
margin-bottom: 24px;
2627
`;
2728

28-
const FormContactDetails: React.FC = () => {
29+
const FormContactDetails: React.FC<ISettings> = ({ setIsSettingsOpen }) => {
2930
const [telegramInput, setTelegramInput] = useState<string>("");
3031
const [emailInput, setEmailInput] = useState<string>("");
3132
const [telegramIsValid, setTelegramIsValid] = useState<boolean>(false);
3233
const [emailIsValid, setEmailIsValid] = useState<boolean>(false);
3334
const { data: walletClient } = useWalletClient();
3435
const { address } = useAccount();
3536

36-
// TODO: retrieve the current email address from the database and populate the email input with it
37+
// TODO: after the user is authenticated, retrieve the current email/telegram from the database and populate the form
3738

3839
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
3940
e.preventDefault();
@@ -54,7 +55,10 @@ const FormContactDetails: React.FC = () => {
5455
address,
5556
signature,
5657
};
57-
await uploadSettingsToSupabase(data);
58+
const response = await uploadSettingsToSupabase(data);
59+
if (response.ok) {
60+
setIsSettingsOpen(false);
61+
}
5862
};
5963
return (
6064
<FormContainer onSubmit={handleSubmit}>

web/src/layout/Header/navbar/Menu/Settings/Notifications/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from "react";
22
import styled from "styled-components";
3+
import { ISettings } from "../types";
34

45
import FormContactDetails from "./FormContactDetails";
56
import { EnsureChain } from "components/EnsureChain";
@@ -32,13 +33,13 @@ const EnsureChainContainer = styled.div`
3233
padding-bottom: 16px;
3334
`;
3435

35-
const NotificationSettings: React.FC = () => {
36+
const NotificationSettings: React.FC<ISettings> = ({ setIsSettingsOpen }) => {
3637
return (
3738
<EnsureChainContainer>
3839
<EnsureChain>
3940
<Container>
4041
<HeaderNotifs />
41-
<FormContactDetails />
42+
<FormContactDetails setIsSettingsOpen={setIsSettingsOpen} />
4243
</Container>
4344
</EnsureChain>
4445
</EnsureChainContainer>

web/src/layout/Header/navbar/Menu/Settings/index.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import React, { Dispatch, SetStateAction, useRef, useState } from "react";
1+
import React, { useRef, useState } from "react";
22
import styled from "styled-components";
33
import { Tabs } from "@kleros/ui-components-library";
44
import General from "./General";
55
import NotificationSettings from "./Notifications";
66
import { useFocusOutside } from "hooks/useFocusOutside";
77
import { Overlay } from "components/Overlay";
8+
import { ISettings } from "./types";
89

910
const Container = styled.div`
1011
display: flex;
@@ -44,10 +45,6 @@ const TABS = [
4445
},
4546
];
4647

47-
interface ISettings {
48-
setIsSettingsOpen: Dispatch<SetStateAction<boolean>>;
49-
}
50-
5148
const Settings: React.FC<ISettings> = ({ setIsSettingsOpen }) => {
5249
const [currentTab, setCurrentTab] = useState<number>(0);
5350
const containerRef = useRef(null);
@@ -65,7 +62,7 @@ const Settings: React.FC<ISettings> = ({ setIsSettingsOpen }) => {
6562
setCurrentTab(n);
6663
}}
6764
/>
68-
{currentTab === 0 ? <General /> : <NotificationSettings />}
65+
{currentTab === 0 ? <General /> : <NotificationSettings setIsSettingsOpen={setIsSettingsOpen} />}
6966
</Container>
7067
</>
7168
);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { Dispatch, SetStateAction } from "react";
2+
3+
export type ISettings = {
4+
setIsSettingsOpen: Dispatch<SetStateAction<boolean>>;
5+
};

0 commit comments

Comments
 (0)