Skip to content

Commit

Permalink
Validation fixes (#2374)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsorohova committed Jan 22, 2024
1 parent b43c5cb commit 3e2d250
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
12 changes: 7 additions & 5 deletions src/admin/media/mediaModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,14 @@ export class MediaModal extends React.Component<MediaModalProps, MediaModalState
}

renameMedia = async (mediaItem: MediaContract): Promise<void> => {
const updatedMedia: MediaContract = {
...mediaItem,
fileName: this.state.fileNewName
if (this.state.fileNewName) {
const updatedMedia: MediaContract = {
...mediaItem,
fileName: this.state.fileNewName
}
await this.mediaService.updateMedia(updatedMedia);
this.eventManager.dispatchEvent('onSaveChanges');
}
await this.mediaService.updateMedia(updatedMedia);
this.eventManager.dispatchEvent('onSaveChanges');

this.setState({ fileForRename: '', fileNewName: '' });
this.searchMedia();
Expand Down
2 changes: 1 addition & 1 deletion src/admin/pages/pageDetailsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class PageDetailsModal extends React.Component<PageDetailsModalProps, Pag
}

validatePermalink = async (permalink: string): Promise<string> => {
if (permalink === this.props.page?.permalink) return '';
if (!this.state.copyPage && permalink === this.props.page?.permalink) return '';

const isPermalinkNotDefined = await this.permalinkService.isPermalinkDefined(permalink) && !reservedPermalinks.includes(permalink);
const errorMessage = validateField(UNIQUE_REQUIRED, permalink, isPermalinkNotDefined);
Expand Down
6 changes: 3 additions & 3 deletions src/admin/pages/pageLayoutDetailsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ export class PageLayoutDetailsModal extends React.Component<PageLayoutModalProps
}

validatePermalink = async (permalink: string): Promise<string> => {
if (permalink === this.props.layout?.permalinkTemplate) return '';
if (!this.state.copyLayout && permalink === this.props.layout?.permalinkTemplate) return '';

const isPermalinkNotDefined = !(await this.layoutService.getLayoutByPermalinkTemplate(permalink)) && !reservedPermalinks.includes(permalink);
const isPermalinkNotDefined = permalink ? !(await this.layoutService.getLayoutByPermalinkTemplate(permalink)) : true && !reservedPermalinks.includes(permalink);
const errorMessage = validateField(UNIQUE_REQUIRED, permalink, isPermalinkNotDefined);

return errorMessage;
Expand All @@ -95,7 +95,7 @@ export class PageLayoutDetailsModal extends React.Component<PageLayoutModalProps
copyLayout = async (): Promise<void> => {
this.setState({ copyLayout: true, layout: {
...this.state.layout,
permalinkTemplate: null,
permalinkTemplate: this.state.layout.permalinkTemplate + '-copy',
title: this.state.layout.title + ' (copy)'
}});
}
Expand Down

0 comments on commit 3e2d250

Please sign in to comment.