Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

feat(Users): Add user unsubscribe result

haitao(lj)f4f2e054822a
diff --git a/i18n/en_US.yaml b/i18n/en_US.yaml
index e301ee93..5d8c929c 100644
--- a/i18n/en_US.yaml
+++ b/i18n/en_US.yaml
@@ -838,6 +838,11 @@ ui:
confirm_new_email_invalid: >-
Sorry, this confirmation link is no longer valid. Perhaps your email was
already changed?
+ unsubscribe:
+ page_title: Unsubscribe
+ success_title: Unsubscribe Successful
+ success_desc: You have been successfully removed from this subscriber list and won’t receive any further emails from us.
+ link: Change settings
question:
following_tags: Following Tags
edit: Edit
diff --git a/ui/src/pages/Users/Settings/Notification/index.tsx b/ui/src/pages/Users/Settings/Notification/index.tsx
index 77275d48..e970fd18 100644
--- a/ui/src/pages/Users/Settings/Notification/index.tsx
+++ b/ui/src/pages/Users/Settings/Notification/index.tsx
@@ -31,13 +31,15 @@ const Index = () => {
const getProfile = () => {
getLoggedUserInfo().then((res) => {
- setFormData({
- notice_switch: {
- value: res.notice_status === 1,
- isInvalid: false,
- errorMsg: '',
- },
- });
+ if (res) {
+ setFormData({
+ notice_switch: {
+ value: res.notice_status === 1,
+ isInvalid: false,
+ errorMsg: '',
+ },
+ });
+ }
});
};
diff --git a/ui/src/pages/Users/Settings/index.tsx b/ui/src/pages/Users/Settings/index.tsx
index 3c7cf204..272d6df3 100644
--- a/ui/src/pages/Users/Settings/index.tsx
+++ b/ui/src/pages/Users/Settings/index.tsx
@@ -43,12 +43,14 @@ const Index: React.FC = () => {
});
const getProfile = () => {
getLoggedUserInfo().then((res) => {
- formData.display_name.value = res.display_name;
- formData.bio.value = res.bio;
- formData.avatar.value = res.avatar;
- formData.location.value = res.location;
- formData.website.value = res.website;
- setFormData({ ...formData });
+ if (res) {
+ formData.display_name.value = res.display_name;
+ formData.bio.value = res.bio;
+ formData.avatar.value = res.avatar;
+ formData.location.value = res.location;
+ formData.website.value = res.website;
+ setFormData({ ...formData });
+ }
});
};
diff --git a/ui/src/pages/Users/Unsubscribe/index.tsx b/ui/src/pages/Users/Unsubscribe/index.tsx
new file mode 100644
index 00000000..b654b4f4
--- /dev/null
+++ b/ui/src/pages/Users/Unsubscribe/index.tsx
@@ -0,0 +1,28 @@
+import { FC, memo } from 'react';
+import { Container, Row, Col } from 'react-bootstrap';
+import { Link } from 'react-router-dom';
+import { useTranslation } from 'react-i18next';
+
+import { usePageTags } from '@/hooks';
+
+const Index: FC = () => {
+ const { t } = useTranslation('translation', { keyPrefix: 'unsubscribe' });
+ usePageTags({
+ title: t('page_title'),
+ });
+ return (
+ <Container className="pt-4 mt-2 mb-5">
+ <Row className="justify-content-center">
+ <Col lg={6}>
+ <h3 className="text-center mt-3 mb-5">{t('success_title')}</h3>
+ <p className="text-center">{t('success_desc')}</p>
+ <div className="text-center">
+ <Link to="/users/settings/notify">{t('link')}</Link>
+ </div>
+ </Col>
+ </Row>
+ </Container>
+ );
+};
+
+export default memo(Index);
diff --git a/ui/src/router/routes.ts b/ui/src/router/routes.ts
index 63ac8355..12d6a51b 100644
--- a/ui/src/router/routes.ts
+++ b/ui/src/router/routes.ts
@@ -337,6 +337,10 @@ const routes: RouteNode[] = [
},
],
},
+ {
+ path: '/users/unsubscribe',
+ page: 'pages/Users/Unsubscribe',
+ },
],
},
{
diff --git a/ui/src/utils/floppyNavigation.ts b/ui/src/utils/floppyNavigation.ts
index 68e6f8a5..2fd6f565 100644
--- a/ui/src/utils/floppyNavigation.ts
+++ b/ui/src/utils/floppyNavigation.ts
@@ -8,12 +8,23 @@ const differentCurrent = (target: string, base?: string) => {
return targetUrl.toString() !== window.location.href;
};
+const storageLoginRedirect = () => {
+ const { pathname } = window.location;
+ if (pathname !== RouteAlias.login && pathname !== RouteAlias.register) {
+ const loc = window.location;
+ const redirectUrl = loc.href.replace(loc.origin, '');
+ Storage.set(REDIRECT_PATH_STORAGE_KEY, redirectUrl);
+ }
+};
/**
* only navigate if not same as current url
* @param pathname
* @param callback
*/
const navigate = (pathname: string, callback: Function) => {
+ if (pathname === RouteAlias.login) {
+ storageLoginRedirect();
+ }
if (differentCurrent(pathname)) {
callback();
}
@@ -23,12 +34,7 @@ const navigate = (pathname: string, callback: Function) => {
* auto navigate to login page with redirect info
*/
const navigateToLogin = () => {
- const { pathname } = window.location;
- if (pathname !== RouteAlias.login && pathname !== RouteAlias.register) {
- const loc = window.location;
- const redirectUrl = loc.href.replace(loc.origin, '');
- Storage.set(REDIRECT_PATH_STORAGE_KEY, redirectUrl);
- }
+ storageLoginRedirect();
navigate(RouteAlias.login, () => {
window.location.replace(RouteAlias.login);
});