Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: redirect if post already imported #1829

Merged
merged 3 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/components/PostCreate/PostCreate.container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const PostCreateContainer: React.FC<PostCreateContainerType> = props => {
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down('xs'));
const enqueueSnackbar = useEnqueueSnackbar();
const [redirect, setRedirect] = useState(false);

const user = useSelector<RootState, User | null>(
state => state.userState.user,
Expand Down Expand Up @@ -111,6 +112,15 @@ export const PostCreateContainer: React.FC<PostCreateContainerType> = props => {
message = i18n.t(
`Home.RichText.Prompt_Import.Error.${statusCode}`,
);
if (statusCode === 409) {
setRedirect(true);
user.fullAccess
? enqueueSnackbar({
message: message,
variant: 'success',
})
: _handlePostNotFullAccess();
}
}

setDialogFailedImport({ open: true, message, postId });
Expand Down Expand Up @@ -175,6 +185,8 @@ export const PostCreateContainer: React.FC<PostCreateContainerType> = props => {
onSubmit={submitPost}
isMobile={isMobile}
/>
{redirect &&
router.push({ pathname: `/post/${dialogFailedImport.postId}` })}
<PromptComponent
title={i18n.t('Home.RichText.Prompt_Import.Title')}
subtitle={dialogFailedImport.message}
Expand Down
7 changes: 7 additions & 0 deletions src/components/PostCreate/PostCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ export const PostCreate: React.FC<PostCreateProps> = props => {
setPost(prevPost => ({ ...prevPost, visibility }));
};

const handleImagePaste = event => {
if (event.clipboardData.getData('image') != '') {
event.preventDefault();
}
};

const handleSubmit = () => {
if (activeTab === 'import' && importUrl) {
onSubmit(importUrl, {
Expand Down Expand Up @@ -427,6 +433,7 @@ export const PostCreate: React.FC<PostCreateProps> = props => {
title={handleTitleModal().title}
subtitle={handleTitleModal().subtitle}
onClose={handleClose}
onPaste={handleImagePaste}
open={open}
fullScreen={isMobile}
maxWidth="md"
Expand Down