mirror of
https://github.com/docmost/docmost.git
synced 2025-11-10 03:32:06 +10:00
less create workspace form fields in cloud (#1265)
* sync * less signup form fields in cloud * min length
This commit is contained in:
@ -21,7 +21,7 @@ import { Link } from "react-router-dom";
|
||||
import APP_ROUTE from "@/lib/app-route.ts";
|
||||
|
||||
const formSchema = z.object({
|
||||
workspaceName: z.string().trim().min(3).max(50),
|
||||
workspaceName: z.string().trim().max(50).optional(),
|
||||
name: z.string().min(1).max(50),
|
||||
email: z
|
||||
.string()
|
||||
@ -46,6 +46,7 @@ export function SetupWorkspaceForm() {
|
||||
});
|
||||
|
||||
async function onSubmit(data: ISetupWorkspace) {
|
||||
console.log(data)
|
||||
await setupWorkspace(data);
|
||||
}
|
||||
|
||||
@ -60,15 +61,17 @@ export function SetupWorkspaceForm() {
|
||||
{isCloud() && <SsoCloudSignup />}
|
||||
|
||||
<form onSubmit={form.onSubmit(onSubmit)}>
|
||||
<TextInput
|
||||
id="workspaceName"
|
||||
type="text"
|
||||
label={t("Workspace Name")}
|
||||
placeholder={t("e.g ACME Inc")}
|
||||
variant="filled"
|
||||
mt="md"
|
||||
{...form.getInputProps("workspaceName")}
|
||||
/>
|
||||
{!isCloud() && (
|
||||
<TextInput
|
||||
id="workspaceName"
|
||||
type="text"
|
||||
label={t("Workspace Name")}
|
||||
placeholder={t("e.g ACME Inc")}
|
||||
variant="filled"
|
||||
mt="md"
|
||||
{...form.getInputProps("workspaceName")}
|
||||
/>
|
||||
)}
|
||||
|
||||
<TextInput
|
||||
id="name"
|
||||
|
||||
@ -10,7 +10,7 @@ export interface IRegister {
|
||||
}
|
||||
|
||||
export interface ISetupWorkspace {
|
||||
workspaceName: string;
|
||||
workspaceName?: string;
|
||||
name: string;
|
||||
email: string;
|
||||
password: string;
|
||||
|
||||
@ -11,7 +11,7 @@ import { notifications } from "@mantine/notifications";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
const formSchema = z.object({
|
||||
name: z.string().min(2).max(40),
|
||||
name: z.string().min(1).max(40),
|
||||
});
|
||||
|
||||
type FormValues = z.infer<typeof formSchema>;
|
||||
|
||||
@ -11,7 +11,7 @@ import useUserRole from "@/hooks/use-user-role.tsx";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
const formSchema = z.object({
|
||||
name: z.string().min(4),
|
||||
name: z.string().min(1),
|
||||
});
|
||||
|
||||
type FormValues = z.infer<typeof formSchema>;
|
||||
|
||||
@ -16,6 +16,12 @@ export async function comparePasswordHash(
|
||||
return bcrypt.compare(plainPassword, passwordHash);
|
||||
}
|
||||
|
||||
export function generateRandomSuffixNumbers(length: number) {
|
||||
return Math.random()
|
||||
.toFixed(length)
|
||||
.substring(2, 2 + length);
|
||||
}
|
||||
|
||||
export type RedisConfig = {
|
||||
host: string;
|
||||
port: number;
|
||||
|
||||
@ -1,6 +1,12 @@
|
||||
import { IsNotEmpty, IsString, MaxLength, MinLength } from 'class-validator';
|
||||
import {
|
||||
IsNotEmpty,
|
||||
IsOptional,
|
||||
IsString,
|
||||
MaxLength,
|
||||
MinLength,
|
||||
} from 'class-validator';
|
||||
import { CreateUserDto } from './create-user.dto';
|
||||
import {Transform, TransformFnParams} from "class-transformer";
|
||||
import { Transform, TransformFnParams } from 'class-transformer';
|
||||
|
||||
export class CreateAdminUserDto extends CreateUserDto {
|
||||
@IsNotEmpty()
|
||||
@ -9,10 +15,17 @@ export class CreateAdminUserDto extends CreateUserDto {
|
||||
@Transform(({ value }: TransformFnParams) => value?.trim())
|
||||
name: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
@MinLength(3)
|
||||
@IsOptional()
|
||||
@MinLength(1)
|
||||
@MaxLength(50)
|
||||
@IsString()
|
||||
@Transform(({ value }: TransformFnParams) => value?.trim())
|
||||
workspaceName: string;
|
||||
|
||||
@IsOptional()
|
||||
@MinLength(4)
|
||||
@MaxLength(50)
|
||||
@IsString()
|
||||
@Transform(({ value }: TransformFnParams) => value?.trim())
|
||||
hostname?: string;
|
||||
}
|
||||
|
||||
@ -92,7 +92,8 @@ export class SignupService {
|
||||
|
||||
// create workspace with full setup
|
||||
const workspaceData: CreateWorkspaceDto = {
|
||||
name: createAdminUserDto.workspaceName,
|
||||
name: createAdminUserDto.workspaceName || 'My workspace',
|
||||
hostname: createAdminUserDto.hostname,
|
||||
};
|
||||
|
||||
workspace = await this.workspaceService.create(
|
||||
|
||||
@ -32,6 +32,7 @@ import { AttachmentType } from 'src/core/attachment/attachment.constants';
|
||||
import { InjectQueue } from '@nestjs/bullmq';
|
||||
import { QueueJob, QueueName } from '../../../integrations/queue/constants';
|
||||
import { Queue } from 'bullmq';
|
||||
import { generateRandomSuffixNumbers } from '../../../common/helpers';
|
||||
|
||||
@Injectable()
|
||||
export class WorkspaceService {
|
||||
@ -377,24 +378,20 @@ export class WorkspaceService {
|
||||
name: string,
|
||||
trx?: KyselyTransaction,
|
||||
): Promise<string> {
|
||||
const generateRandomSuffix = (length: number) =>
|
||||
Math.random()
|
||||
.toFixed(length)
|
||||
.substring(2, 2 + length);
|
||||
|
||||
let subdomain = name
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]/g, '')
|
||||
.substring(0, 20);
|
||||
.replace(/[^a-z0-9-]/g, '')
|
||||
.substring(0, 20)
|
||||
.replace(/^-+|-+$/g, ''); //remove any hyphen at the start or end
|
||||
// Ensure we leave room for a random suffix.
|
||||
const maxSuffixLength = 6;
|
||||
|
||||
if (subdomain.length < 4) {
|
||||
subdomain = `${subdomain}-${generateRandomSuffix(maxSuffixLength)}`;
|
||||
subdomain = `${subdomain}-${generateRandomSuffixNumbers(maxSuffixLength)}`;
|
||||
}
|
||||
|
||||
if (DISALLOWED_HOSTNAMES.includes(subdomain)) {
|
||||
subdomain = `workspace-${generateRandomSuffix(maxSuffixLength)}`;
|
||||
subdomain = `workspace-${generateRandomSuffixNumbers(maxSuffixLength)}`;
|
||||
}
|
||||
|
||||
let uniqueHostname = subdomain;
|
||||
@ -408,7 +405,7 @@ export class WorkspaceService {
|
||||
break;
|
||||
}
|
||||
// Append a random suffix and retry.
|
||||
const randomSuffix = generateRandomSuffix(maxSuffixLength);
|
||||
const randomSuffix = generateRandomSuffixNumbers(maxSuffixLength);
|
||||
uniqueHostname = `${subdomain}-${randomSuffix}`.substring(0, 25);
|
||||
}
|
||||
|
||||
|
||||
Submodule apps/server/src/ee updated: 4d1b0a17d3...397352b9f4
Reference in New Issue
Block a user