refactor: use enums

This commit is contained in:
Mohamed Marrouchi
2025-01-16 17:41:30 +01:00
parent 4fac5d4fc9
commit 359049ff3d
22 changed files with 124 additions and 90 deletions

View File

@@ -13,7 +13,7 @@ import { forwardRef } from "react";
import { useGet } from "@/hooks/crud/useGet";
import { useHasPermission } from "@/hooks/useHasPermission";
import { EntityType } from "@/services/types";
import { IAttachment, TAttachmentResourceRef } from "@/types/attachment.types";
import { AttachmentResourceRef, IAttachment } from "@/types/attachment.types";
import { PermissionAction } from "@/types/permission.types";
import AttachmentThumbnail from "./AttachmentThumbnail";
@@ -29,7 +29,7 @@ type AttachmentThumbnailProps = {
onChange?: (id: string | null, mimeType: string | null) => void;
error?: boolean;
helperText?: string;
resourceRef: TAttachmentResourceRef;
resourceRef: AttachmentResourceRef;
};
const AttachmentInput = forwardRef<HTMLDivElement, AttachmentThumbnailProps>(

View File

@@ -17,7 +17,7 @@ import { getDisplayDialogs, useDialog } from "@/hooks/useDialog";
import { useToast } from "@/hooks/useToast";
import { useTranslate } from "@/hooks/useTranslate";
import { EntityType } from "@/services/types";
import { IAttachment, TAttachmentResourceRef } from "@/types/attachment.types";
import { AttachmentResourceRef, IAttachment } from "@/types/attachment.types";
import { AttachmentDialog } from "./AttachmentDialog";
import AttachmentThumbnail from "./AttachmentThumbnail";
@@ -68,7 +68,7 @@ export type FileUploadProps = {
enableMediaLibrary?: boolean;
onChange?: (data?: IAttachment | null) => void;
onUploadComplete?: () => void;
resourceRef: TAttachmentResourceRef;
resourceRef: AttachmentResourceRef;
};
const AttachmentUploader: FC<FileUploadProps> = ({

View File

@@ -12,7 +12,7 @@ import { forwardRef, useState } from "react";
import { useHasPermission } from "@/hooks/useHasPermission";
import { EntityType } from "@/services/types";
import { IAttachment, TAttachmentResourceRef } from "@/types/attachment.types";
import { AttachmentResourceRef, IAttachment } from "@/types/attachment.types";
import { PermissionAction } from "@/types/permission.types";
import AttachmentThumbnail from "./AttachmentThumbnail";
@@ -28,7 +28,7 @@ type MultipleAttachmentInputProps = {
onChange?: (ids: string[]) => void;
error?: boolean;
helperText?: string;
resourceRef: TAttachmentResourceRef;
resourceRef: AttachmentResourceRef;
};
const MultipleAttachmentInput = forwardRef<

View File

@@ -9,7 +9,7 @@
import { useMutation, useQueryClient } from "react-query";
import { QueryType, TMutationOptions } from "@/services/types";
import { TAttachmentResourceRef } from "@/types/attachment.types";
import { AttachmentResourceRef } from "@/types/attachment.types";
import { IBaseSchema, IDynamicProps, TType } from "@/types/base.types";
import { useEntityApiClient } from "../useApiClient";
@@ -27,7 +27,7 @@ export const useUpload = <
TMutationOptions<
TBasic,
Error,
{ file: File; resourceRef: TAttachmentResourceRef },
{ file: File; resourceRef: AttachmentResourceRef },
TBasic
>,
"mutationFn" | "mutationKey"

View File

@@ -9,7 +9,7 @@
import { AxiosInstance, AxiosResponse } from "axios";
import { TAttachmentResourceRef } from "@/types/attachment.types";
import { AttachmentResourceRef } from "@/types/attachment.types";
import { ILoginAttributes } from "@/types/auth/login.types";
import { IUserPermissions } from "@/types/auth/permission.types";
import { StatsType } from "@/types/bot-stat.types";
@@ -302,7 +302,7 @@ export class EntityApiClient<TAttr, TBasic, TFull> extends ApiClient {
return data;
}
async upload(file: File, resourceRef?: TAttachmentResourceRef) {
async upload(file: File, resourceRef?: AttachmentResourceRef) {
const { _csrf } = await this.getCsrf();
const formData = new FormData();

View File

@@ -22,8 +22,6 @@ export enum AttachmentCreatedByRef {
Subscriber = "Subscriber",
}
export type TAttachmentCreatedByRef = `${AttachmentCreatedByRef}`;
/**
* Defines the various resource references in which an attachment can exist.
* These references influence how the attachment is uploaded, stored, and accessed:
@@ -37,7 +35,10 @@ export enum AttachmentResourceRef {
MessageAttachment = "Message", // Files sent or received via messages, uploaded programmatically, accessible to users with inbox permissions.;
}
export type TAttachmentResourceRef = `${AttachmentResourceRef}`;
export enum AttachmentAccess {
Public = "public",
Private = "private",
}
export interface IAttachmentAttributes {
name: string;
@@ -46,8 +47,9 @@ export interface IAttachmentAttributes {
location: string;
url: string;
channel?: Record<string, any>;
resourceRef: TAttachmentResourceRef;
createdByRef: TAttachmentCreatedByRef;
resourceRef: AttachmentResourceRef;
access: AttachmentAccess;
createdByRef: AttachmentCreatedByRef;
createdBy: string | null;
}