Metadata modules for PageLayoutTab PageLayoutWidget (#16662)
# Introduction Creating dedicated folders and module for both `page-layout-tab` and `page-layout-widget` The addition diff with deletion is due to the module being added
This commit is contained in:
+59
@@ -0,0 +1,59 @@
|
||||
import { type MessageDescriptor } from '@lingui/core';
|
||||
import { msg } from '@lingui/core/macro';
|
||||
import { assertUnreachable } from 'twenty-shared/utils';
|
||||
|
||||
import { CustomException } from 'src/utils/custom-exception';
|
||||
|
||||
export enum PageLayoutTabExceptionCode {
|
||||
PAGE_LAYOUT_TAB_NOT_FOUND = 'PAGE_LAYOUT_TAB_NOT_FOUND',
|
||||
INVALID_PAGE_LAYOUT_TAB_DATA = 'INVALID_PAGE_LAYOUT_TAB_DATA',
|
||||
}
|
||||
|
||||
export enum PageLayoutTabExceptionMessageKey {
|
||||
PAGE_LAYOUT_TAB_NOT_FOUND = 'PAGE_LAYOUT_TAB_NOT_FOUND',
|
||||
TITLE_REQUIRED = 'TITLE_REQUIRED',
|
||||
PAGE_LAYOUT_ID_REQUIRED = 'PAGE_LAYOUT_ID_REQUIRED',
|
||||
PAGE_LAYOUT_NOT_FOUND = 'PAGE_LAYOUT_NOT_FOUND',
|
||||
PAGE_LAYOUT_TAB_NOT_DELETED = 'PAGE_LAYOUT_TAB_NOT_DELETED',
|
||||
}
|
||||
|
||||
const pageLayoutTabExceptionUserFriendlyMessages: Record<
|
||||
PageLayoutTabExceptionCode,
|
||||
MessageDescriptor
|
||||
> = {
|
||||
[PageLayoutTabExceptionCode.PAGE_LAYOUT_TAB_NOT_FOUND]: msg`Page layout tab not found.`,
|
||||
[PageLayoutTabExceptionCode.INVALID_PAGE_LAYOUT_TAB_DATA]: msg`Invalid page layout tab data.`,
|
||||
};
|
||||
|
||||
export class PageLayoutTabException extends CustomException<PageLayoutTabExceptionCode> {
|
||||
constructor(
|
||||
message: string,
|
||||
code: PageLayoutTabExceptionCode,
|
||||
{ userFriendlyMessage }: { userFriendlyMessage?: MessageDescriptor } = {},
|
||||
) {
|
||||
super(message, code, {
|
||||
userFriendlyMessage:
|
||||
userFriendlyMessage ?? pageLayoutTabExceptionUserFriendlyMessages[code],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const generatePageLayoutTabExceptionMessage = (
|
||||
key: PageLayoutTabExceptionMessageKey,
|
||||
value?: string,
|
||||
): string => {
|
||||
switch (key) {
|
||||
case PageLayoutTabExceptionMessageKey.PAGE_LAYOUT_TAB_NOT_FOUND:
|
||||
return `Page layout tab with ID "${value}" not found`;
|
||||
case PageLayoutTabExceptionMessageKey.TITLE_REQUIRED:
|
||||
return 'Page layout tab title is required';
|
||||
case PageLayoutTabExceptionMessageKey.PAGE_LAYOUT_ID_REQUIRED:
|
||||
return 'Page layout ID is required';
|
||||
case PageLayoutTabExceptionMessageKey.PAGE_LAYOUT_NOT_FOUND:
|
||||
return 'Page layout not found';
|
||||
case PageLayoutTabExceptionMessageKey.PAGE_LAYOUT_TAB_NOT_DELETED:
|
||||
return 'Page layout tab is not deleted and cannot be restored';
|
||||
default:
|
||||
assertUnreachable(key);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user