Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
45 changes: 18 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"date-fns": "^4.4.0",
"dompurify": "^3.4.13",
"holy-loader": "^2.3.14",
"husky": "^9.1.7",
"input-otp": "^1.4.2",
Expand Down
3 changes: 2 additions & 1 deletion src/api/backend/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ export const localeDir: Record<Locale, 'ltr' | 'rtl'> = {

export const mediaTypes = ['image', 'video', 'audio', 'raw'] as const;

export const mediaFolders = ['product', 'variant', 'brand', 'userReview'] as const;
export const mediaFolders = ['product', 'variant', 'brand', 'userReview', 'announcement'] as const;

export const mediaFoldersTypeMap = {
product: 'all',
variant: 'image',
brand: 'image',
userReview: 'image',
announcement: 'all',
} as const satisfies Record<MediaFolder, MediaFormat | MediaFormat[]>;

export const mediaRawFormats = ['.pdf', '.csv', '.txt', '.zip', '.doc', '.docx', '.xls', '.xlsx'] as const;
Expand Down
14 changes: 14 additions & 0 deletions src/api/backend/schemas/settings/announcementSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import z from 'zod';

import { optionalLocalizedSchema } from '../localizedSchema';
import { MediaByFolder } from '../../types';

export const announcementSchema = z.object({
enabled: z.boolean(),
message: optionalLocalizedSchema.optional(),
media: z.array(z.custom<MediaByFolder<'announcement'>>()).optional(),
disableAt: z.string().nullable().optional(),
intervalHours: z.number().int().min(0).optional(),
});

export type AnnouncementSchema = z.infer<typeof announcementSchema>;
2 changes: 2 additions & 0 deletions src/api/backend/schemas/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import z, { ZodObject } from 'zod';

import { AppSettingsKey } from '@/api';
import { maintenanceModeSchema } from './maintenanceModeSchema';
import { announcementSchema } from './announcementSchema';

export const appSettingsSchemas = {
maintenanceMode: maintenanceModeSchema,
announcement: announcementSchema,
} as const satisfies Record<AppSettingsKey, ZodObject>;

export type AppSettingsSchemas = {
Expand Down
1 change: 1 addition & 0 deletions src/api/backend/schemas/settings/maintenanceModeSchema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import z from 'zod';

import { optionalLocalizedSchema } from '../localizedSchema';

export const maintenanceModeSchema = z.object({
Expand Down
8 changes: 8 additions & 0 deletions src/api/backend/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,14 @@ export interface AppSettings {
disableOnCountdownEnd?: boolean;
countdown?: string;
};
announcement: {
enabled: boolean;
message: Localized;
mediaIds: number[];
intervalHours: number;
media?: Media<'image' | 'video'>[];
disableAt?: string | null;
};
Comment thread
OmarLawaty marked this conversation as resolved.
}

export type AppSettingsKey = keyof AppSettings;
Expand Down
4 changes: 2 additions & 2 deletions src/app/(hydration)/(base)/(store)/products/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ProductForm,
SelectProductRelations,
ProductStatusSelectMenu,
ProductUploadMedia,
ReorderedMediaUpload,
ProductVariants,
LocalizedForm,
ProductFormCTA,
Expand Down Expand Up @@ -49,7 +49,7 @@ export default async function EditProduct(props: PagePropsWithParams<{ id: strin
<LocalizedForm<ProductSchema> name="description" type="richtext" />
</section>

<ProductUploadMedia />
<ReorderedMediaUpload folder="product" className="p-4" />

<ProductVariants />
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/app/(hydration)/(base)/(store)/products/add/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ProductForm,
SelectProductRelations,
ProductStatusSelectMenu,
ProductUploadMedia,
ReorderedMediaUpload,
ProductVariants,
LocalizedForm,
ProductFormCTA,
Expand Down Expand Up @@ -34,7 +34,7 @@ export default async function AddProduct() {
<LocalizedForm<ProductSchema> name="description" type="richtext" />
</section>

<ProductUploadMedia />
<ReorderedMediaUpload folder="product" className="p-4" />

<ProductVariants />
</div>
Expand Down
4 changes: 3 additions & 1 deletion src/app/(hydration)/(base)/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Metadata } from 'next';
import { dehydrate, HydrationBoundary, QueryClient } from '@tanstack/react-query';

import { useAppSettingsQuery } from '@/hooks';
import { MaintenanceMode } from '@/components';
import { Announcement, MaintenanceMode } from '@/components';

export const metadata: Metadata = { title: 'Gamers Core | Settings' };

Expand All @@ -14,6 +14,8 @@ export default async function Settings() {
return (
<HydrationBoundary state={dehydrate(queryClient)}>
<MaintenanceMode {...settings.maintenanceMode} />

<Announcement {...settings.announcement} />
</HydrationBoundary>
);
}
3 changes: 2 additions & 1 deletion src/components/HTMLRender.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { memo } from 'react';
import DOMPurify from 'dompurify';

import { cn } from '@/lib/utils';

Expand All @@ -10,7 +11,7 @@ interface HTMLRenderProps {
export const HTMLRender = (displayName: string) => {
const Component = memo(({ html, className, ...props }: HTMLRenderProps) => (
<div
dangerouslySetInnerHTML={{ __html: html }}
dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(html) }}
className={cn(
'prose prose-sm md:prose-base dark:prose-invert max-w-none prose-li:leading-normal prose-p:mt-0 prose-p:mb-0 prose-ul:mb-0 prose-ul:mt-0',
className,
Expand Down
Loading
Loading