Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an invite code field to the register page #4

Merged
merged 7 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/client/components/auth/src/flows/FlowCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ export default function FlowCreate() {
const email = data.get("email") as string;
const password = data.get("password") as string;
const captcha = data.get("captcha") as string;
const invite = data.get("invite") as string;

await clientController.api.post("/auth/account/create", {
email,
password,
captcha,
invite,
});

// FIXME: should tell client if email was sent
Expand All @@ -48,7 +50,7 @@ export default function FlowCreate() {
{t("login.welcome2")}
</FlowTitle>
<Form onSubmit={create} captcha={CONFIGURATION.HCAPTCHA_SITEKEY}>
<Fields fields={["email", "password"]} />
<Fields fields={["email", "password", "invite"]} />
<Row align justify="center">
<a href="..">
<Button variant="plain">
Expand Down
16 changes: 13 additions & 3 deletions packages/client/components/auth/src/flows/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { For, JSX, Show, createSignal } from "solid-js";

import { cva } from "styled-system/css";

import { mapAnyError } from "@revolt/client";
import { clientController, mapAnyError } from "@revolt/client";
import { useTranslation } from "@revolt/i18n";
import { Checkbox, Column, FormGroup, Input, Typography } from "@revolt/ui";
import { autoComplete } from "@revolt/ui/directives";

/**
* Available field types
*/
type Field = "email" | "password" | "new-password" | "log-out" | "username";
type Field = "email" | "password" | "new-password" | "log-out" | "username" | "invite";

/**
* Properties to apply to fields
Expand Down Expand Up @@ -47,6 +48,13 @@ const useFieldConfiguration = () => {
name: () => t("login.username"),
placeholder: () => t("login.enter.username"),
},
invite: {
minLength: 2,
type: "text",
autoComplete: "none",
name: () => t("login.invite"),
placeholder: () => t("login.enter.invite"),
}
};
};

Expand All @@ -72,6 +80,8 @@ export function Fields(props: FieldProps) {
const fieldConfiguration = useFieldConfiguration();
const [failedValidation, setFailedValidation] = createSignal(false);

const inviteCodeNeeded: boolean|undefined = clientController.lifecycle.client.configuration?.features.invite_only;

/**
* If an input element notifies us it was invalid, enable live input validation.
*/
Expand All @@ -81,7 +91,7 @@ export function Fields(props: FieldProps) {

return (
<For each={props.fields}>
{(field) => (
{(field) => (field != "invite" || inviteCodeNeeded) && (
<FormGroup>
{field === "log-out" ? (
<label class={labelRow()}>
Expand Down
2 changes: 1 addition & 1 deletion packages/client/components/client/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class Lifecycle {
},
captcha: {} as never,
email: true,
invite_only: false,
invite_only: CONFIGURATION.INVITE_ONLY,
voso: {} as never,
},
vapid: String(),
Expand Down
6 changes: 6 additions & 0 deletions packages/client/components/common/lib/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ export default {
* Maximum number of attachments a message can have
*/
MAX_ATTACHMENTS: (import.meta.env.VITE_CFG_MAX_ATTACHMENTS as number) ?? 5,

/**
* Determines whether or not an invite code is required on signing up.
*/
INVITE_ONLY: (import.meta.env.VITE_INVITE_ONLY as boolean) ?? false,

/**
* Session ID to set during development.
*/
Expand Down
Loading