diff --git a/src/components/Chatbar/components/ChatFolders.tsx b/src/components/Chatbar/components/ChatFolders.tsx index 4fa86ab35d..f9b759885f 100644 --- a/src/components/Chatbar/components/ChatFolders.tsx +++ b/src/components/Chatbar/components/ChatFolders.tsx @@ -289,6 +289,10 @@ export function ChatFolders() { ConversationsSelectors.selectMyItemsFilters, ); + const isPublishingEnabled = useAppSelector((state) => + SettingsSelectors.isPublishingEnabled(state, FeatureType.Chat), + ); + const isSharingEnabled = useAppSelector((state) => SettingsSelectors.isSharingEnabled(state, FeatureType.Chat), ); @@ -297,7 +301,7 @@ export function ChatFolders() { () => [ { - hidden: !isSharingEnabled || !isFilterEmpty, + hidden: !isPublishingEnabled || !isFilterEmpty, name: t('Organization'), filters: PublishedWithMeFilter, displayRootFiles: true, @@ -320,7 +324,14 @@ export function ChatFolders() { dataQa: 'pinned-chats', }, ].filter(({ hidden }) => !hidden), - [commonItemFilter, isFilterEmpty, isSharingEnabled, searchTerm.length, t], + [ + commonItemFilter, + isFilterEmpty, + isPublishingEnabled, + isSharingEnabled, + searchTerm.length, + t, + ], ); return ( diff --git a/src/components/Common/FolderContextMenu.tsx b/src/components/Common/FolderContextMenu.tsx index c3be9004be..ca35a64fa8 100644 --- a/src/components/Common/FolderContextMenu.tsx +++ b/src/components/Common/FolderContextMenu.tsx @@ -59,7 +59,7 @@ export const FolderContextMenu = ({ SettingsSelectors.isPublishingEnabled(state, featureType), ); const isSharingEnabled = useAppSelector((state) => - SettingsSelectors.isPublishingEnabled(state, featureType), + SettingsSelectors.isSharingEnabled(state, featureType), ); const menuItems: DisplayMenuItemProps[] = useMemo( () => [ diff --git a/src/components/Common/ItemContextMenu.tsx b/src/components/Common/ItemContextMenu.tsx index 3ac80e0bd6..dece276ef0 100644 --- a/src/components/Common/ItemContextMenu.tsx +++ b/src/components/Common/ItemContextMenu.tsx @@ -80,7 +80,7 @@ export default function ItemContextMenu({ SettingsSelectors.isPublishingEnabled(state, featureType), ); const isSharingEnabled = useAppSelector((state) => - SettingsSelectors.isPublishingEnabled(state, featureType), + SettingsSelectors.isSharingEnabled(state, featureType), ); const menuItems: DisplayMenuItemProps[] = useMemo( () => [ diff --git a/src/components/Files/PreUploadModal.tsx b/src/components/Files/PreUploadModal.tsx index 67dd8b8784..ab19e1191d 100644 --- a/src/components/Files/PreUploadModal.tsx +++ b/src/components/Files/PreUploadModal.tsx @@ -185,8 +185,9 @@ export const PreUploadDialog = ({ ); const handleUpload = useCallback(() => { + const errors = []; if (attachments.length + selectedFiles.length > 10) { - setErrorMessage( + errors.push( t( `Maximum allowed attachments number is {{maxAttachmentsAmount}}. With your uploadings amount will be {{selectedAttachmentsAmount}}`, { @@ -196,7 +197,21 @@ export const PreUploadDialog = ({ }, ) as string, ); - return; + } + const incorrectFileNames: string[] = getFilesWithInvalidFileName( + selectedFiles, + ).map((file) => file.name); + + if (incorrectFileNames.length > 0) { + errors.push( + t( + `The symbols {{notAllowedSymbols}} are not allowed in file name. Please rename or remove them from uploading files list: {{fileNames}}`, + { + notAllowedSymbols: notAllowedSymbols.join(''), + fileNames: incorrectFileNames.join(', '), + }, + ) as string, + ); } const attachmentsNames = files @@ -206,32 +221,25 @@ export const PreUploadDialog = ({ .filter((file) => attachmentsNames.includes(file.name)) .map((file) => file.name); if (localIncorrectSameNameFiles.length > 0) { - setErrorMessage( + errors.push( t( 'Files which you trying to upload already presented in selected folder. Please rename or remove them from uploading files list: {{fileNames}}', { fileNames: localIncorrectSameNameFiles.join(', ') }, ) as string, ); - return; - } - let isFilesNamesSame = false; - for (let i = 0; i < selectedFiles.length - 1; i++) { - for (let j = i + 1; j < selectedFiles.length; j++) { - if (selectedFiles[i].name === selectedFiles[j].name) { - isFilesNamesSame = true; - break; - } - } - if (isFilesNamesSame) { - break; - } } - if (isFilesNamesSame) { - setErrorMessage( + + const fileNameSet = new Set(selectedFiles.map((file) => file.name)); + if (fileNameSet.size < selectedFiles.length) { + errors.push( t( 'Files which you trying to upload have same names. Please rename or remove them from uploading files list', ) as string, ); + } + + if (errors.length) { + setErrorMessage(errors.join('\n')); return; } diff --git a/src/components/Promptbar/components/PromptFolders.tsx b/src/components/Promptbar/components/PromptFolders.tsx index 7fb4ad9ff7..0e60b5557b 100644 --- a/src/components/Promptbar/components/PromptFolders.tsx +++ b/src/components/Promptbar/components/PromptFolders.tsx @@ -277,11 +277,15 @@ export function PromptFolders() { SettingsSelectors.isSharingEnabled(state, FeatureType.Prompt), ); + const isPublishingEnabled = useAppSelector((state) => + SettingsSelectors.isPublishingEnabled(state, FeatureType.Prompt), + ); + const folderItems: FolderSectionProps[] = useMemo( () => [ { - hidden: !isSharingEnabled || !isFilterEmpty, + hidden: !isPublishingEnabled || !isFilterEmpty, name: t('Organization'), filters: PublishedWithMeFilter, displayRootFiles: true, @@ -304,7 +308,14 @@ export function PromptFolders() { dataQa: 'pinned-prompts', }, ].filter(({ hidden }) => !hidden), - [commonSearchFilter, isFilterEmpty, isSharingEnabled, searchTerm.length, t], + [ + commonSearchFilter, + isFilterEmpty, + isPublishingEnabled, + isSharingEnabled, + searchTerm.length, + t, + ], ); return ( diff --git a/src/utils/app/file.ts b/src/utils/app/file.ts index b7c063b251..08746e5b8c 100644 --- a/src/utils/app/file.ts +++ b/src/utils/app/file.ts @@ -99,7 +99,9 @@ export const notAllowedSymbolsRegex = new RegExp( `[${notAllowedSymbols.join()}]`, 'g', ); -export const getFilesWithInvalidFileName = (files: File[]): File[] => { +export const getFilesWithInvalidFileName = ( + files: T[], +): T[] => { return files.filter(({ name }) => name.match(notAllowedSymbolsRegex)); };