Skip to content

Commit

Permalink
fix: reset button loading status when field has errors (#2439)
Browse files Browse the repository at this point in the history
  • Loading branch information
finnar-bin authored Jan 9, 2024
1 parent b38f68f commit 63649f1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/apps/content-editor/src/app/views/ItemEdit/ItemEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,11 @@ export default function ItemEdit() {
component="section"
sx={{ display: "flex", flexDirection: "column", height: "100%" }}
>
<ItemEditHeader onSave={save} saving={saving} />
<ItemEditHeader
onSave={save}
saving={saving}
hasError={Object.keys(fieldErrors)?.length}
/>
<Switch>
<Route
exact
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ const ITEM_STATES = {
type ItemEditHeaderActionsProps = {
saving: boolean;
onSave: () => void;
hasError: boolean;
};

export const ItemEditHeaderActions = ({
saving,
onSave,
hasError,
}: ItemEditHeaderActionsProps) => {
const { modelZUID, itemZUID } = useParams<{
modelZUID: string;
Expand Down Expand Up @@ -183,6 +185,12 @@ export const ItemEditHeaderActions = ({
}
}, [item, scheduleAfterSave, saving, activePublishing]);

useEffect(() => {
if (!saving && hasError) {
setPublishAfterSave(false);
}
}, [hasError, saving]);

return (
<>
<Tooltip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ export type ContentItemWithDirtyAndPublishing = ContentItem & {
type HeaderProps = {
saving: boolean;
onSave: () => void;
hasError: boolean;
};
export const ItemEditHeader = ({ saving, onSave }: HeaderProps) => {
export const ItemEditHeader = ({ saving, onSave, hasError }: HeaderProps) => {
const { modelZUID, itemZUID } = useParams<{
modelZUID: string;
itemZUID: string;
Expand Down Expand Up @@ -164,7 +165,11 @@ export const ItemEditHeader = ({ saving, onSave }: HeaderProps) => {
<ContentCopyRounded fontSize="small" />
</IconButton>
{type !== "dataset" && <PreviewMenu />}
<ItemEditHeaderActions saving={saving} onSave={onSave} />
<ItemEditHeaderActions
saving={saving}
onSave={onSave}
hasError={hasError}
/>
</Box>
</Box>
<Box
Expand Down

0 comments on commit 63649f1

Please sign in to comment.