feat: add onboarding with oldmarr import (#1606)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { z } from "zod";
|
||||
import { zfd } from "zod-form-data";
|
||||
|
||||
import {
|
||||
backgroundImageAttachments,
|
||||
@@ -9,7 +8,6 @@ import {
|
||||
} from "@homarr/definitions";
|
||||
|
||||
import { zodEnumFromArray } from "./enums";
|
||||
import { createCustomErrorParams } from "./form/i18n";
|
||||
import { createSavePermissionsSchema } from "./permissions";
|
||||
import { commonItemSchema, createSectionSchema } from "./shared";
|
||||
|
||||
@@ -69,53 +67,6 @@ const permissionsSchema = z.object({
|
||||
id: z.string(),
|
||||
});
|
||||
|
||||
export const oldmarrImportConfigurationSchema = z.object({
|
||||
name: boardNameSchema,
|
||||
onlyImportApps: z.boolean().default(false),
|
||||
distinctAppsByHref: z.boolean().default(true),
|
||||
screenSize: z.enum(["lg", "md", "sm"]).default("lg"),
|
||||
sidebarBehaviour: z.enum(["remove-items", "last-section"]).default("last-section"),
|
||||
});
|
||||
|
||||
export type OldmarrImportConfiguration = z.infer<typeof oldmarrImportConfigurationSchema>;
|
||||
|
||||
export const superRefineJsonImportFile = (value: File | null, context: z.RefinementCtx) => {
|
||||
if (!value) {
|
||||
return context.addIssue({
|
||||
code: "invalid_type",
|
||||
expected: "object",
|
||||
received: "null",
|
||||
});
|
||||
}
|
||||
|
||||
if (value.type !== "application/json") {
|
||||
return context.addIssue({
|
||||
code: "custom",
|
||||
params: createCustomErrorParams({
|
||||
key: "invalidFileType",
|
||||
params: { expected: "JSON" },
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
if (value.size > 1024 * 1024) {
|
||||
return context.addIssue({
|
||||
code: "custom",
|
||||
params: createCustomErrorParams({
|
||||
key: "fileTooLarge",
|
||||
params: { maxSize: "1 MB" },
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
const importJsonFileSchema = zfd.formData({
|
||||
file: zfd.file().superRefine(superRefineJsonImportFile),
|
||||
configuration: zfd.json(oldmarrImportConfigurationSchema),
|
||||
});
|
||||
|
||||
const savePermissionsSchema = createSavePermissionsSchema(zodEnumFromArray(boardPermissions));
|
||||
|
||||
z.object({
|
||||
@@ -129,6 +80,7 @@ z.object({
|
||||
});
|
||||
|
||||
export const boardSchemas = {
|
||||
name: boardNameSchema,
|
||||
byName: byNameSchema,
|
||||
savePartialSettings: savePartialSettingsSchema,
|
||||
save: saveSchema,
|
||||
@@ -137,5 +89,4 @@ export const boardSchemas = {
|
||||
changeVisibility: changeVisibilitySchema,
|
||||
permissions: permissionsSchema,
|
||||
savePermissions: savePermissionsSchema,
|
||||
importOldmarrConfig: importJsonFileSchema,
|
||||
};
|
||||
|
||||
@@ -7,6 +7,7 @@ import { integrationSchemas } from "./integration";
|
||||
import { locationSchemas } from "./location";
|
||||
import { mediaSchemas } from "./media";
|
||||
import { searchEngineSchemas } from "./search-engine";
|
||||
import { settingsSchemas } from "./settings";
|
||||
import { userSchemas } from "./user";
|
||||
import { widgetSchemas } from "./widgets";
|
||||
|
||||
@@ -21,11 +22,10 @@ export const validation = {
|
||||
icons: iconsSchemas,
|
||||
searchEngine: searchEngineSchemas,
|
||||
media: mediaSchemas,
|
||||
settings: settingsSchemas,
|
||||
common: commonSchemas,
|
||||
};
|
||||
|
||||
export { oldmarrImportConfigurationSchema, superRefineJsonImportFile } from "./board";
|
||||
export type { OldmarrImportConfiguration } from "./board";
|
||||
export {
|
||||
createSectionSchema,
|
||||
itemAdvancedOptionsSchema,
|
||||
@@ -35,3 +35,4 @@ export {
|
||||
} from "./shared";
|
||||
export { passwordRequirements } from "./user";
|
||||
export { supportedMediaUploadFormats } from "./media";
|
||||
export { zodEnumFromArray, zodUnionFromArray } from "./enums";
|
||||
|
||||
20
packages/validation/src/settings.ts
Normal file
20
packages/validation/src/settings.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { z } from "zod";
|
||||
|
||||
const initSettingsSchema = z.object({
|
||||
analytics: z.object({
|
||||
enableGeneral: z.boolean(),
|
||||
enableWidgetData: z.boolean(),
|
||||
enableIntegrationData: z.boolean(),
|
||||
enableUserData: z.boolean(),
|
||||
}),
|
||||
crawlingAndIndexing: z.object({
|
||||
noIndex: z.boolean(),
|
||||
noFollow: z.boolean(),
|
||||
noTranslate: z.boolean(),
|
||||
noSiteLinksSearchBox: z.boolean(),
|
||||
}),
|
||||
});
|
||||
|
||||
export const settingsSchemas = {
|
||||
init: initSettingsSchema,
|
||||
};
|
||||
Reference in New Issue
Block a user