Skip to content

Commit

Permalink
extract TOS checkbox to component
Browse files Browse the repository at this point in the history
  • Loading branch information
knollengewaechs committed Nov 25, 2024
1 parent 94be416 commit d60afaa
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 53 deletions.
28 changes: 2 additions & 26 deletions frontend/javascripts/admin/auth/registration_form_generic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -301,32 +302,7 @@ function RegistrationFormGeneric(props: Props) {
</Checkbox>
</FormItem>
)}
{terms == null || terms.enabled ? (
<FormItem
name="tos_check"
valuePropName="checked"
rules={[
{
validator: (_, value) =>
value
? Promise.resolve()
: Promise.reject(new Error(messages["auth.tos_check_required"])),
},
]}
>
<Checkbox disabled={terms == null}>
I agree to the{" "}
{terms == null ? (
"terms of service"
) : (
<a target="_blank" href={terms.url} rel="noopener noreferrer">
terms of service
</a>
)}
.
</Checkbox>
</FormItem>
) : null}
<TOSCheckFormItem terms={terms} />
</div>

<FormItem>
Expand Down
29 changes: 2 additions & 27 deletions frontend/javascripts/admin/auth/registration_form_wkorg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -180,33 +181,7 @@ function RegistrationFormWKOrg(props: Props) {
.
</Checkbox>
</FormItem>

{terms == null || terms.enabled ? (
<FormItem
name="tos_check"
valuePropName="checked"
rules={[
{
validator: (_, value) =>
value
? Promise.resolve()
: Promise.reject(new Error(messages["auth.tos_check_required"])),
},
]}
>
<Checkbox disabled={terms == null}>
I agree to the{" "}
{terms == null ? (
"terms of service"
) : (
<a target="_blank" href={terms.url} rel="noopener noreferrer">
terms of service
</a>
)}
.
</Checkbox>
</FormItem>
) : null}
<TOSCheckFormItem terms={terms} />
</div>

<FormItem>
Expand Down
40 changes: 40 additions & 0 deletions frontend/javascripts/admin/auth/tos_check_form_item.tsx
Original file line number Diff line number Diff line change
@@ -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 ? (
<FormItem
name="tos_check"
valuePropName="checked"
rules={[
{
validator: (_, value) =>
value
? Promise.resolve()
: Promise.reject(new Error(messages["auth.tos_check_required"])),
},
]}
>
<Checkbox disabled={terms == null}>
I agree to the{" "}
{terms == null ? (
"terms of service"
) : (
<a target="_blank" href={terms.url} rel="noopener noreferrer">
terms of service
</a>
)}
.
</Checkbox>
</FormItem>
) : null;
}

0 comments on commit d60afaa

Please sign in to comment.