-
{formatDate(new Date(historyItem.createdAt))}
+
+ {formattedDate(new Date(historyItem.createdAt))}
+
diff --git a/apps/client/src/lib/time.ts b/apps/client/src/lib/time.ts
index 8e20e653..7651f829 100644
--- a/apps/client/src/lib/time.ts
+++ b/apps/client/src/lib/time.ts
@@ -1,16 +1,16 @@
-import { formatDistanceStrict } from 'date-fns';
-import { format, isToday, isYesterday } from 'date-fns';
+import { formatDistanceStrict } from "date-fns";
+import { format, isToday, isYesterday } from "date-fns";
export function timeAgo(date: Date) {
return formatDistanceStrict(new Date(date), new Date(), { addSuffix: true });
}
-export function formatDate(date: Date) {
+export function formattedDate(date: Date) {
if (isToday(date)) {
- return `Today, ${format(date, 'h:mma')}`;
+ return `Today, ${format(date, "h:mma")}`;
} else if (isYesterday(date)) {
- return `Yesterday, ${format(date, 'h:mma')}`;
+ return `Yesterday, ${format(date, "h:mma")}`;
} else {
- return format(date, 'MMM dd, yyyy, h:mma');
+ return format(date, "MMM dd, yyyy, h:mma");
}
}
diff --git a/apps/server/src/core/space/dto/create-space.dto.ts b/apps/server/src/core/space/dto/create-space.dto.ts
index a22e6d6f..5f022873 100644
--- a/apps/server/src/core/space/dto/create-space.dto.ts
+++ b/apps/server/src/core/space/dto/create-space.dto.ts
@@ -10,7 +10,8 @@ export class CreateSpaceDto {
@IsString()
description?: string;
- @IsOptional()
+ @MinLength(4)
+ @MaxLength(64)
@IsString()
- slug?: string;
+ slug: string;
}
diff --git a/apps/server/src/core/space/services/space.service.ts b/apps/server/src/core/space/services/space.service.ts
index 45f9e3e1..bc275161 100644
--- a/apps/server/src/core/space/services/space.service.ts
+++ b/apps/server/src/core/space/services/space.service.ts
@@ -10,8 +10,6 @@ import { KyselyTransaction } from '@docmost/db/types/kysely.types';
import { Space } from '@docmost/db/types/entity.types';
import { PaginationResult } from '@docmost/db/pagination/pagination';
import { UpdateSpaceDto } from '../dto/update-space.dto';
-// eslint-disable-next-line @typescript-eslint/no-var-requires
-const { slugify } = require('fix-esm').require('@sindresorhus/slugify');
@Injectable()
export class SpaceService {
@@ -23,14 +21,14 @@ export class SpaceService {
createSpaceDto: CreateSpaceDto,
trx?: KyselyTransaction,
): Promise {
- const slug = slugify(
- createSpaceDto?.slug?.toLowerCase() ?? createSpaceDto.name.toLowerCase(),
+ const slugExists = await this.spaceRepo.slugExists(
+ createSpaceDto.slug,
+ workspaceId,
+ trx,
);
-
- const slugExists = await this.spaceRepo.slugExists(slug, workspaceId, trx);
if (slugExists) {
throw new BadRequestException(
- 'Slug exist. Please use a unique space slug',
+ 'Slug exists. Please use a unique space slug',
);
}
@@ -40,7 +38,7 @@ export class SpaceService {
description: createSpaceDto.description ?? '',
creatorId: userId,
workspaceId: workspaceId,
- slug: slug,
+ slug: createSpaceDto.slug,
},
trx,
);
diff --git a/apps/server/src/core/workspace/services/workspace.service.ts b/apps/server/src/core/workspace/services/workspace.service.ts
index 56c8f288..72ece960 100644
--- a/apps/server/src/core/workspace/services/workspace.service.ts
+++ b/apps/server/src/core/workspace/services/workspace.service.ts
@@ -104,6 +104,7 @@ export class WorkspaceService {
// create default space
const spaceInfo: CreateSpaceDto = {
name: 'General',
+ slug: 'general',
};
const createdSpace = await this.spaceService.create(