From d60afaa363ac145d144daed81c47fc4da6b40785 Mon Sep 17 00:00:00 2001 From: Charlie Meister Date: Mon, 25 Nov 2024 17:11:03 +0100 Subject: [PATCH] extract TOS checkbox to component --- .../admin/auth/registration_form_generic.tsx | 28 +------------ .../admin/auth/registration_form_wkorg.tsx | 29 +------------- .../admin/auth/tos_check_form_item.tsx | 40 +++++++++++++++++++ 3 files changed, 44 insertions(+), 53 deletions(-) create mode 100644 frontend/javascripts/admin/auth/tos_check_form_item.tsx diff --git a/frontend/javascripts/admin/auth/registration_form_generic.tsx b/frontend/javascripts/admin/auth/registration_form_generic.tsx index d26a404fdd..dbb6c877a5 100644 --- a/frontend/javascripts/admin/auth/registration_form_generic.tsx +++ b/frontend/javascripts/admin/auth/registration_form_generic.tsx @@ -11,6 +11,7 @@ import { setHasOrganizationsAction } from "oxalis/model/actions/ui_actions"; import { setActiveOrganizationAction } from "oxalis/model/actions/organization_actions"; import { useFetch } from "libs/react_helpers"; import { getTermsOfService } from "admin/api/terms_of_service"; +import { TOSCheckFormItem } from "./tos_check_form_item"; const FormItem = Form.Item; const { Password } = Input; @@ -301,32 +302,7 @@ function RegistrationFormGeneric(props: Props) { )} - {terms == null || terms.enabled ? ( - - value - ? Promise.resolve() - : Promise.reject(new Error(messages["auth.tos_check_required"])), - }, - ]} - > - - I agree to the{" "} - {terms == null ? ( - "terms of service" - ) : ( - - terms of service - - )} - . - - - ) : null} + diff --git a/frontend/javascripts/admin/auth/registration_form_wkorg.tsx b/frontend/javascripts/admin/auth/registration_form_wkorg.tsx index d4997b0d1b..633e7613d0 100644 --- a/frontend/javascripts/admin/auth/registration_form_wkorg.tsx +++ b/frontend/javascripts/admin/auth/registration_form_wkorg.tsx @@ -9,6 +9,7 @@ import messages from "messages"; import { setActiveOrganizationAction } from "oxalis/model/actions/organization_actions"; import { useFetch } from "libs/react_helpers"; import { getTermsOfService } from "admin/api/terms_of_service"; +import { TOSCheckFormItem } from "./tos_check_form_item"; const FormItem = Form.Item; const { Password } = Input; @@ -180,33 +181,7 @@ function RegistrationFormWKOrg(props: Props) { . - - {terms == null || terms.enabled ? ( - - value - ? Promise.resolve() - : Promise.reject(new Error(messages["auth.tos_check_required"])), - }, - ]} - > - - I agree to the{" "} - {terms == null ? ( - "terms of service" - ) : ( - - terms of service - - )} - . - - - ) : null} + diff --git a/frontend/javascripts/admin/auth/tos_check_form_item.tsx b/frontend/javascripts/admin/auth/tos_check_form_item.tsx new file mode 100644 index 0000000000..472d2e7745 --- /dev/null +++ b/frontend/javascripts/admin/auth/tos_check_form_item.tsx @@ -0,0 +1,40 @@ +import { Checkbox, Form } from "antd"; +import messages from "messages"; + +const FormItem = Form.Item; + +type TOSProps = { + terms: { + enabled: boolean; + url: string; + } | null; +}; + +export function TOSCheckFormItem({ terms }: TOSProps) { + return terms == null || terms.enabled ? ( + + value + ? Promise.resolve() + : Promise.reject(new Error(messages["auth.tos_check_required"])), + }, + ]} + > + + I agree to the{" "} + {terms == null ? ( + "terms of service" + ) : ( + + terms of service + + )} + . + + + ) : null; +}