diff --git a/public/locales/de/translation.json b/public/locales/de/translation.json index b12ecc4..b26785e 100644 --- a/public/locales/de/translation.json +++ b/public/locales/de/translation.json @@ -245,9 +245,35 @@ } }, "userProfile": { - "title": "Ihr Profil", - "language": "Sprache", - "analytics": "Analytik", - "analyticsDescription": "Dazu gehören Informationen über die Nutzung unseres Dashboards, wie die besuchten Seiten, die Verweildauer auf den Seiten und die allgemeine Interaktion mit den Seiten. Dies hilft uns, unser Dashboard zu verbessern und es benutzerfreundlicher zu gestalten." + "tabs": { + "yourProfile": "Ihr Profil", + "changePassword": "Passwort ändern", + "yourSessions": "Ihre Sitzungen", + "deleteAccount": "Konto löschen" + }, + "yourProfile": { + "cardTitle": "Ihr Profil", + "language": "Sprache", + "analytics": "Analytik", + "analyticsDescription": "Dazu gehören Informationen über die Nutzung unseres Dashboards, wie die besuchten Seiten, die Verweildauer auf den Seiten und die allgemeine Interaktion mit den Seiten. Dies hilft uns, unser Dashboard zu verbessern und es benutzerfreundlicher zu gestalten." + }, + "changePassword": { + "cardTitle": "Passwort ändern", + "currentPassword": "Aktuelles Passwort", + "currentPasswordPlaceholder": "Geben Sie Ihr aktuelles Passwort ein", + "newPassword": "Neues Passwort", + "newPasswordPlaceholder": "Geben Sie Ihr neues Passwort ein", + "confirmNewPassword": "Bestätigen Sie Ihr neues Passwort", + "confirmNewPasswordPlaceholder": "Bestätigen Sie Ihr neues Passwort", + "confirmNewPasswordMismatch": "Das neue Passwort stimmt nicht überein", + "button": "Passwort ändern", + "buttonInfo": "Nachdem Sie Ihr Passwort geändert haben, werden Sie abgemeldet und müssen sich erneut anmelden." + }, + "yourSessions": { + "cardTitle": "Ihre Sitzungen" + }, + "deleteAccount": { + "cardTitle": "Konto löschen" + } } } diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index df892fc..d46db48 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -67,7 +67,7 @@ "failedInternetProblem": { "title": "Request failed", "description": "The request failed. Please check your internet connection and try again." - } + } } }, "app": { @@ -238,7 +238,7 @@ }, "tabs": { "general": "General", - "banner": "Banner", + "banner": "Banner", "colorPalette": "Color palette", "portfolio": "Portfolio", "ratings": "Ratings", @@ -248,9 +248,41 @@ } }, "userProfile": { - "title": "Your profile", - "language": "Language", - "analytics": "Analytics", - "analyticsDescription": "This includes information about the use of our dashboard, such as the visited pages, the length of stay on the pages and the general interaction with the pages. This helps us to improve our dashboard and make it more user-friendly." + "tabs": { + "yourProfile": "Your profile", + "changePassword": "Change password", + "yourSessions": "Your sessions", + "deleteAccount": "Delete account" + }, + "yourProfile": { + "cardTitle": "Your profile", + "language": "Language", + "analytics": "Analytics", + "analyticsDescription": "This includes information about the use of our dashboard, such as the visited pages, the length of stay on the pages and the general interaction with the pages. This helps us to improve our dashboard and make it more user-friendly." + }, + "changePassword": { + "cardTitle": "Change password", + "currentPassword": "Current password", + "currentPasswordPlaceholder": "Enter your current password", + "newPassword": "New password", + "newPasswordPlaceholder": "Enter your new password", + "confirmNewPassword": "Confirm new password", + "confirmNewPasswordPlaceholder": "Confirm your new password", + "confirmNewPasswordMismatch": "The new password do not match", + "button": "Change password", + "buttonInfo": "After changing your password, you will be logged out and have to log in again.", + "request": { + "400": { + "title": "Password incorrect", + "description": "Please check your password and try again." + } + } + }, + "yourSessions": { + "cardTitle": "Your sessions" + }, + "deleteAccount": { + "cardTitle": "Delete account" + } } } diff --git a/src/Components/MyFormInputs/index.js b/src/Components/MyFormInputs/index.js index f00fba3..6ee403f 100644 --- a/src/Components/MyFormInputs/index.js +++ b/src/Components/MyFormInputs/index.js @@ -3,13 +3,18 @@ import { Constants, myFetch } from "../../utils"; import { useRef } from "react"; import { useTranslation } from "react-i18next"; -export function MyUsernameFormInput({ propsFormItem, propsInput }) { +export function MyUsernameFormInput({ + propsFormItem, + propsInput, + showSkeleton, +}) { const { t } = useTranslation(); return ( ); } @@ -144,6 +159,7 @@ export function MyAvailableCheckFormInput({ fetchParameter, fetchDelay, hasFeedback, + showSkeleton, }) { const delayTimeout = useRef(); @@ -166,6 +182,7 @@ export function MyAvailableCheckFormInput({ ruleMessageValueMinLengthRequired={ruleMessageValueMinLengthRequired} inputPlaceholder={inputPlaceholder} inputType={inputType} + showSkeleton={showSkeleton} formItemRules={[ () => ({ validator(_, value) { @@ -238,7 +255,12 @@ export function MyFormInput({ } if (formItemRules) { - myFormItemRules.push(...formItemRules); + // check if formItemRules is an array + if (Array.isArray(formItemRules)) { + myFormItemRules.push(...formItemRules); + } else { + myFormItemRules.push(formItemRules); + } } if (inputType === "number") { diff --git a/src/Pages/Store/Employees/index.js b/src/Pages/Store/Employees/index.js index 775421f..f4fa63e 100644 --- a/src/Pages/Store/Employees/index.js +++ b/src/Pages/Store/Employees/index.js @@ -108,11 +108,7 @@ export default function StoreEmployees() { t: t, }) .then(() => fetchEmployees()) - .catch((errStatus) => { - console.log(errStatus); - - setIsRequesting(false); - }); + .catch(() => setIsRequesting(false)); }} > {t("common.button.delete")} @@ -152,9 +148,7 @@ export default function StoreEmployees() { setIsRequesting(false); setRequestData(data); }) - .catch((errStatus) => { - console.log(errStatus); - }); + .catch(() => {}); }; useEffect(() => fetchEmployees(), []); diff --git a/src/Pages/Store/Settings/index.js b/src/Pages/Store/Settings/index.js index eefef57..d7ede98 100644 --- a/src/Pages/Store/Settings/index.js +++ b/src/Pages/Store/Settings/index.js @@ -44,9 +44,7 @@ export default function StoreSettings() { setIsRequesting(false); }) - .catch((errStatus) => { - console.log(errStatus); - }); + .catch(() => {}); }, []); useEffect(() => { @@ -83,10 +81,7 @@ export default function StoreSettings() { t: t, }) .then(() => setRequestState(RequestState.SUCCESS)) - .catch((errStatus) => { - console.log(errStatus); - setRequestState(RequestState.FAILED); - }); + .catch(() => setRequestState(RequestState.FAILED)); }, 500); }, [companyName, phoneNumber, email, address]); diff --git a/src/Pages/Store/Website/index.js b/src/Pages/Store/Website/index.js index 2aa2cab..03531c7 100644 --- a/src/Pages/Store/Website/index.js +++ b/src/Pages/Store/Website/index.js @@ -11,12 +11,6 @@ const General = lazy(() => import("./General")); const Banner = lazy(() => import("./Banner")); const ColorPalette = lazy(() => import("./ColorPalette")); -function SuspenseFallback({ children }) { - return ( - {children} - ); -} - export default function Website() { const { storeId } = useParams(); const { t } = useTranslation(); @@ -45,7 +39,11 @@ export default function Website() { return { key: index, ...item, - children: {item.children}, + children: ( + + {item.children} + + ), }; }); @@ -86,7 +84,6 @@ export default function Website() { { - myFetch({ - url: "/user/profile/settings", - method: "GET", - notificationApi: notificationApi, - t: t, - }) - .then((data) => { - form.setFieldsValue({ - language: data.language, - analytics: data.analytics_enabled, - }); - }) - .catch((errStatus) => { - console.log(errStatus); - }); - }, []); - - useEffect(() => { - if (language === undefined || analytics === undefined) return; - - if (RequestState.INIT === requestState) { - setRequestState(RequestState.NOTHING); - return; - } - - setRequestState(RequestState.REQUESTING); - - if (delayTimeout.current) { - clearTimeout(delayTimeout.current); - } - - delayTimeout.current = setTimeout(() => { - myFetch({ - url: "/user/profile/settings", - method: "POST", - body: { - language: language, - analyticsEnabled: analytics, - }, - notificationApi: notificationApi, - t: t, - }) - .then(() => setRequestState(RequestState.SUCCESS)) - .catch((errStatus) => { - console.log(errStatus); - setRequestState(RequestState.FAILED); - }); - }, 500); - }, [language, analytics]); + const tabItems = [ + { + label: t("userProfile.tabs.yourProfile"), + cardTitle: t("userProfile.yourProfile.cardTitle"), + children: ( + + ), + }, + { + label: t("userProfile.tabs.changePassword"), + cardTitle: t("userProfile.changePassword.cardTitle"), + children: ( + + ), + }, + { + label: t("userProfile.tabs.yourSessions"), + cardTitle: t("userProfile.yourSessions.cardTitle"), + children: , + }, + { + label: t("userProfile.tabs.deleteAccount"), + cardTitle: t("userProfile.deleteAccount.cardTitle"), + children: , + }, + ].map((item, index) => { + return { + key: index, + ...item, + children: ( + + + {item.children} + + + ), + }; + }); return ( <> {notificationContextHolder} - setActiveTab(key)} + tabBarExtraContent={ + setGlobalRequestState({ + ...globalRequestState, + global: state, + }) + } /> } - > -
- - {requestState === RequestState.INIT ? ( - - ) : ( - i18n.changeLanguage(e)} + /> + )} + + + + {requestState === RequestState.INIT ? ( + + ) : ( + {t("userProfile.yourProfile.analytics")} + )} + + + + + + + ); +} + +function ChangePassword({ + notificationApi, + globalRequestState, + setGlobalRequestState, + setUserSession, +}) { + const { t } = useTranslation(); + + const [form] = Form.useForm(); + + const handlePasswordChange = () => { + form + .validateFields() + .then((values) => { + console.log(values); + + setGlobalRequestState({ + ...globalRequestState, + global: RequestState.REQUESTING, + changePassword: RequestState.REQUESTING, + }); + + myFetch({ + url: "/user/profile/password", + method: "POST", + body: { + currentPassword: EncodeStringToBase64(values.currentPassword), + newPassword: EncodeStringToBase64(values.newPassword), + }, + notificationApi: notificationApi, + t: t, + }) + .then(() => { + form.resetFields(); + + setGlobalRequestState({ + ...globalRequestState, + global: RequestState.SUCCESS, + changePassword: RequestState.NOTHING, + }); + + handleLogout({ + setUserSession: setUserSession, + }); + }) + .catch((err) => { + setGlobalRequestState({ + ...globalRequestState, + global: RequestState.FAILED, + changePassword: RequestState.NOTHING, + }); + + if (err === 400) { + notificationApi["error"]({ + message: t("userProfile.changePassword.request.400.title"), + description: t( + "userProfile.changePassword.request.400.description" + ), + }); + } + }); + }) + .catch(() => showInputsInvalidNotification(notificationApi, t)); + }; + + return ( +
+ + + + + ({ + validator(_, value) { + if (!value || getFieldValue("newPassword") === value) { + return Promise.resolve(); + } + return Promise.reject( + new Error( + t("userProfile.changePassword.confirmNewPasswordMismatch") + ) + ); + }, + })} + /> + + + + + + + + ); +} + +function YourSessions() { + useEffect(() => { + console.log("your sessions"); + }, []); + + return

Test

; +} + +function DeleteAccount() { + return
Delete account, Password and feedback
; +} diff --git a/src/utils.js b/src/utils.js index 198e391..0c9c8fe 100644 --- a/src/utils.js +++ b/src/utils.js @@ -246,3 +246,8 @@ export function showInputsInvalidNotification(notificationApi, t) { description: t("common.request.inputsInvalid.description"), }); } + +export function handleLogout({ setUserSession }) { + setUserSession(); + window.location.href = "/"; +}