Skip to content

Commit

Permalink
fix: Prevent empty titles for Areas to be saved
Browse files Browse the repository at this point in the history
Also provides a fallback presentation in case the area has previously been
updated with an empty title.
  • Loading branch information
ajoensson committed Feb 15, 2025
1 parent 4f6fb48 commit 1d1b986
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/features/areas/components/AreaOverlay/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import ZUIPreviewableInput, {
import ZUIEllipsisMenu from 'zui/ZUIEllipsisMenu';
import { ZUIConfirmDialogContext } from 'zui/ZUIConfirmDialogProvider';
import TagsSection from './TagsSection';
import { Msg } from 'core/i18n';
import { Msg, useMessages } from 'core/i18n';
import messageIds from 'features/areas/l10n/messageIds';

type Props = {
Expand All @@ -36,6 +36,7 @@ const AreaOverlay: FC<Props> = ({
onCancelEdit,
onClose,
}) => {
const messages = useMessages(messageIds);
const [title, setTitle] = useState(area.title);
const [description, setDescription] = useState(area.description);
const [fieldEditing, setFieldEditing] = useState<
Expand Down Expand Up @@ -84,7 +85,9 @@ const AreaOverlay: FC<Props> = ({
onClickAway={() => {
if (fieldEditing === 'title') {
setFieldEditing(null);
updateArea({ title });
updateArea({
title: title?.trim() || messages.areas.default.title(),
});
} else if (fieldEditing === 'description') {
setFieldEditing(null);
updateArea({ description });
Expand All @@ -111,7 +114,9 @@ const AreaOverlay: FC<Props> = ({
onBlur={() => {
if (fieldEditing === 'title') {
setFieldEditing(null);
updateArea({ title });
updateArea({
title: title?.trim() || messages.areas.default.title(),
});
}
}}
onChange={(ev) => setTitle(ev.target.value)}
Expand All @@ -120,7 +125,9 @@ const AreaOverlay: FC<Props> = ({
/>
)}
renderPreview={() => (
<Typography variant="h5">{area.title}</Typography>
<Typography variant="h5">
{area.title?.trim() || messages.areas.default.title()}
</Typography>
)}
value={area.title || ''}
/>
Expand Down

0 comments on commit 1d1b986

Please sign in to comment.