-
-
Notifications
You must be signed in to change notification settings - Fork 719
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
302eed8
commit 24f13de
Showing
8 changed files
with
80 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
apps/www/src/registry/default/plate-ui/media-upload-toast.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { useEffect } from 'react'; | ||
|
||
import { useEditorRef } from '@udecode/plate-core/react'; | ||
import { PlaceholderPlugin, UploadErrorCode } from '@udecode/plate-media/react'; | ||
import { toast } from 'sonner'; | ||
|
||
export const useUploadErrorToast = () => { | ||
const editor = useEditorRef(); | ||
|
||
const uploadError = editor.useOption(PlaceholderPlugin, 'error'); | ||
|
||
useEffect(() => { | ||
if (!uploadError) return; | ||
|
||
const { code, data } = uploadError; | ||
|
||
switch (code) { | ||
case UploadErrorCode.INVALID_FILE_SIZE: { | ||
toast.error( | ||
`The size of files ${data.files | ||
.map((f) => f.name) | ||
.join(', ')} is invalid` | ||
); | ||
|
||
break; | ||
} | ||
case UploadErrorCode.INVALID_FILE_TYPE: { | ||
toast.error( | ||
`The type of files ${data.files | ||
.map((f) => f.name) | ||
.join(', ')} is invalid` | ||
); | ||
|
||
break; | ||
} | ||
case UploadErrorCode.TOO_LARGE: { | ||
toast.error( | ||
`The size of files ${data.files | ||
.map((f) => f.name) | ||
.join(', ')} is too large than ${data.maxFileSize}` | ||
); | ||
|
||
break; | ||
} | ||
case UploadErrorCode.TOO_LESS_FILES: { | ||
toast.error( | ||
`The mini um number of files is ${data.minFileCount} for ${data.fileType}` | ||
); | ||
|
||
break; | ||
} | ||
case UploadErrorCode.TOO_MANY_FILES: { | ||
toast.error( | ||
`The maximum number of files is ${data.maxFileCount} ${ | ||
data.fileType ? `for ${data.fileType}` : '' | ||
}` | ||
); | ||
|
||
break; | ||
} | ||
} | ||
}, [uploadError]); | ||
}; | ||
|
||
export const MediaUploadToast = () => { | ||
useUploadErrorToast(); | ||
|
||
return null; | ||
}; |
32 changes: 0 additions & 32 deletions
32
apps/www/src/registry/default/plate-ui/undo-toolbar-button.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters