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.

refactor Changes - moved legal clicks outside of signup (#835)

Akhil64381f16823d
diff --git a/ui/src/behaviour/clicks.tsx b/ui/src/behaviour/clicks.tsx
new file mode 100644
index 00000000..a098b3e8
--- /dev/null
+++ b/ui/src/behaviour/clicks.tsx
@@ -0,0 +1,32 @@
+import { MouseEvent, useCallback } from 'react';
+
+import { useLegalPrivacy, useLegalTos } from '@/services/client/legal';
+
+export const useLegalClick = () => {
+ const { data: tos } = useLegalTos();
+ const { data: privacy } = useLegalPrivacy();
+
+ const legalClick = useCallback(
+ (evt: MouseEvent, type: 'tos' | 'privacy') => {
+ evt.stopPropagation();
+ const contentText =
+ type === 'tos'
+ ? tos?.terms_of_service_original_text
+ : privacy?.privacy_policy_original_text;
+ let matchUrl: URL | undefined;
+ try {
+ if (contentText) {
+ matchUrl = new URL(contentText);
+ }
+ // eslint-disable-next-line no-empty
+ } catch (ex) {}
+ if (matchUrl) {
+ evt.preventDefault();
+ window.open(matchUrl.toString());
+ }
+ },
+ [tos, privacy],
+ );
+
+ return legalClick;
+};
diff --git a/ui/src/pages/Users/Register/components/SignUpForm/index.tsx b/ui/src/pages/Users/Register/components/SignUpForm/index.tsx
index 9e322df0..c865f048 100644
--- a/ui/src/pages/Users/Register/components/SignUpForm/index.tsx
+++ b/ui/src/pages/Users/Register/components/SignUpForm/index.tsx
@@ -17,16 +17,17 @@
* under the License.
*/
-import React, { FormEvent, MouseEvent, useState } from 'react';
+import React, { FormEvent, useState } from 'react';
import { Form, Button } from 'react-bootstrap';
import { Link } from 'react-router-dom';
import { Trans, useTranslation } from 'react-i18next';
import { useCaptchaModal } from '@/hooks';
import type { FormDataType, RegisterReqParams } from '@/common/interface';
-import { register, useLegalTos, useLegalPrivacy } from '@/services';
+import { register } from '@/services';
import userStore from '@/stores/loggedUserInfo';
import { handleFormError } from '@/utils';
+import { useLegalClick } from '@/behaviour/clicks';
interface Props {
callback: () => void;
@@ -86,26 +87,7 @@ const Index: React.FC<Props> = ({ callback }) => {
return bol;
};
- const { data: tos } = useLegalTos();
- const { data: privacy } = useLegalPrivacy();
- const argumentClick = (evt: MouseEvent, type: 'tos' | 'privacy') => {
- evt.stopPropagation();
- const contentText =
- type === 'tos'
- ? tos?.terms_of_service_original_text
- : privacy?.privacy_policy_original_text;
- let matchUrl: URL | undefined;
- try {
- if (contentText) {
- matchUrl = new URL(contentText);
- }
- // eslint-disable-next-line no-empty
- } catch (ex) {}
- if (matchUrl) {
- evt.preventDefault();
- window.open(matchUrl.toString());
- }
- };
+ const legalClick = useLegalClick();
const handleRegister = (event?: any) => {
if (event) {
@@ -232,7 +214,7 @@ const Index: React.FC<Props> = ({ callback }) => {
<Link
to="/privacy"
onClick={(evt) => {
- argumentClick(evt, 'privacy');
+ legalClick(evt, 'privacy');
}}
target="_blank">
privacy policy
@@ -241,7 +223,7 @@ const Index: React.FC<Props> = ({ callback }) => {
<Link
to="/tos"
onClick={(evt) => {
- argumentClick(evt, 'tos');
+ legalClick(evt, 'tos');
}}
target="_blank">
terms of service