unlink calendar with password

master
alex 2024-01-21 16:46:38 +01:00
parent fcaab64820
commit e09c48c977
4 changed files with 113 additions and 40 deletions

View File

@ -170,7 +170,8 @@
}, },
"unlinkGoogleCalendar": { "unlinkGoogleCalendar": {
"title": "Google Kalender trennen", "title": "Google Kalender trennen",
"description": "Möchten Sie die Verbindung zu Ihrem Google Kalender wirklich trennen?", "description": "Aus Sicherheitsgründen müssen Sie Ihr Passwort eingeben, um die Verbindung zu Ihrem Google Kalender zu trennen.",
"checkboxDeleteCalendars": "Kalender für Öffnungszeiten und Termine löschen (Alle Termine werden gelöscht und können nicht wiederhergestellt werden)",
"button": "Google Kalender trennen" "button": "Google Kalender trennen"
} }
}, },

View File

@ -173,7 +173,8 @@
}, },
"unlinkGoogleCalendar": { "unlinkGoogleCalendar": {
"title": "Unlink Google Calendar", "title": "Unlink Google Calendar",
"description": "Are you sure you want to unlink your Google Calendar?", "description": "For security reasons, you need to enter your password to unlink your Google Calendar.",
"checkboxDeleteCalendars": "Delete calendar for opening hours and appointments (all appointments are deleted and cannot be restored)",
"button": "Unlink Google Calendar" "button": "Unlink Google Calendar"
} }
}, },

View File

@ -104,6 +104,27 @@ export function MyModalOnlyCloseButtonFooter({ onCancel }) {
return <Button onClick={onCancel}>{t("common.button.close")}</Button>; return <Button onClick={onCancel}>{t("common.button.close")}</Button>;
} }
export function MyModalCloseConfirmButtonFooter({
onCancel,
onConfirm,
isConfirmButtonLoading,
}) {
const { t } = useTranslation();
return (
<>
<Button onClick={onCancel}>{t("common.button.close")}</Button>
<Button
onClick={onConfirm}
type="primary"
loading={isConfirmButtonLoading}
>
{t("common.button.confirm")}
</Button>
</>
);
}
export function MyModalCloseSaveButtonFooter({ export function MyModalCloseSaveButtonFooter({
onCancel, onCancel,
onSave, onSave,

View File

@ -1,6 +1,7 @@
import { import {
Button, Button,
Card, Card,
Checkbox,
Col, Col,
Form, Form,
Popconfirm, Popconfirm,
@ -9,10 +10,12 @@ import {
Space, Space,
Spin, Spin,
Switch, Switch,
Typography,
} from "antd"; } from "antd";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { import {
Constants, Constants,
EncodeStringToBase64,
getUserSessionFromLocalStorage, getUserSessionFromLocalStorage,
myFetch, myFetch,
} from "../../../utils"; } from "../../../utils";
@ -21,11 +24,16 @@ import MyCenteredContainer from "../../../Components/MyContainer";
import { import {
MyCalendarMaxFutureBookingDaysFormInput, MyCalendarMaxFutureBookingDaysFormInput,
MyCalendarMinEarliestBookingTimeFormInput, MyCalendarMinEarliestBookingTimeFormInput,
MyPasswordFormInput,
} from "../../../Components/MyFormInputs"; } from "../../../Components/MyFormInputs";
import { import {
RequestState, RequestState,
RequestStateItem, RequestStateItem,
} from "../../../Components/MyRequestStateItem"; } from "../../../Components/MyRequestStateItem";
import MyModal, {
MyModalCloseConfirmButtonFooter,
MyModalCloseSaveButtonFooter,
} from "../../../Components/MyModal";
export default function StoreCalendar() { export default function StoreCalendar() {
const { t } = useTranslation(); const { t } = useTranslation();
@ -104,15 +112,22 @@ export default function StoreCalendar() {
function CardPersonalCalendarSettings({ settings }) { function CardPersonalCalendarSettings({ settings }) {
const { t } = useTranslation(); const { t } = useTranslation();
const [form] = Form.useForm(); const [form] = Form.useForm();
const [formUnlinkCalendar] = Form.useForm();
const [requestState, setRequestState] = useState(RequestState.INIT); const [requestState, setRequestState] = useState(RequestState.INIT);
const delayTimeout = useRef(); const delayTimeout = useRef();
const [isModalOpen, setIsModalOpen] = useState(false);
const [isRequesting, setIsRequesting] = useState(false);
const usingPrimaryCalendar = Form.useWatch( const usingPrimaryCalendar = Form.useWatch(
"calendarUsingPrimaryCalendar", "calendarUsingPrimaryCalendar",
form form
); );
const handleModalClose = () => {
setIsModalOpen(false);
};
useEffect(() => { useEffect(() => {
if (!settings) return; if (!settings) return;
@ -149,6 +164,7 @@ function CardPersonalCalendarSettings({ settings }) {
}, [usingPrimaryCalendar]); }, [usingPrimaryCalendar]);
return ( return (
<>
<Card <Card
title={t("calendar.cardPersonalCalendarSettings.title")} title={t("calendar.cardPersonalCalendarSettings.title")}
extra={ extra={
@ -158,24 +174,9 @@ function CardPersonalCalendarSettings({ settings }) {
setRequestState={setRequestState} setRequestState={setRequestState}
/> />
<Popconfirm <Button danger onClick={() => setIsModalOpen(true)}>
okText={t("common.button.confirm")} {t("calendar.unlinkGoogleCalendar.button")}
cancelText={t("common.button.cancel")} </Button>
title={t("calendar.unlinkGoogleCalendar.title")}
description={t("calendar.unlinkGoogleCalendar.description")}
onConfirm={() => {
myFetch("/calendar/settings/personal/unlink", "POST")
.then((res) => {
console.log(res);
window.location.reload();
})
.catch((errStatus) => {
console.log(errStatus);
});
}}
>
<Button danger>{t("calendar.unlinkGoogleCalendar.button")}</Button>
</Popconfirm>
</Space> </Space>
} }
> >
@ -189,6 +190,55 @@ function CardPersonalCalendarSettings({ settings }) {
</Form.Item> </Form.Item>
</Form> </Form>
</Card> </Card>
<MyModal
title={t("calendar.unlinkGoogleCalendar.title")}
isOpen={isModalOpen}
onCancel={handleModalClose}
footer={
<MyModalCloseConfirmButtonFooter
onCancel={handleModalClose}
isConfirmButtonLoading={isRequesting}
onConfirm={() => {
formUnlinkCalendar.validateFields().then((values) => {
setIsRequesting(true);
myFetch("/calendar/settings/personal/unlink", "POST", {
password: EncodeStringToBase64(values.password),
deleteCalendars: values.deleteEvents,
})
.then((res) => {
console.log(res);
window.location.reload();
})
.catch((errStatus) => {
console.log(errStatus);
setIsRequesting(false);
// TODO: show error message
});
});
}}
/>
}
>
<>
<Form
form={formUnlinkCalendar}
requiredMark={false}
layout="vertical"
>
<p>{t("calendar.unlinkGoogleCalendar.description")}</p>
<MyPasswordFormInput />
<Form.Item>
<Checkbox>
{t("calendar.unlinkGoogleCalendar.checkboxDeleteCalendars")}
</Checkbox>
</Form.Item>
</Form>
</>
</MyModal>
</>
); );
} }