Skip to content

Commit

Permalink
fix(journal): properly validate required fields (#499)
Browse files Browse the repository at this point in the history
Co-authored-by: lukastresch <[email protected]>
  • Loading branch information
nimdanitro and lukastresch authored Nov 7, 2024
1 parent 738c47c commit 291d918
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions ui/src/views/journal/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type Action =
| { type: "set_content"; content: string }
| { type: "set_time"; time: Date | undefined }
| { type: "save" }
| { type: "save_error" }
| { type: "set_media_detail"; detail: MediaDetail }
| { type: "set_autofill_details"; detail: AutofillDetail };
type Dispatch = (action: Action) => void;
Expand Down Expand Up @@ -109,6 +110,9 @@ function Editor() {
// reset the form values
dispatch({ type: "clear" });
},
onError() {
dispatch({ type: "save_error" });
},
refetchQueries: [{ query: GetJournalMessages, variables: { journalId: journalId } }],
});

Expand All @@ -117,6 +121,9 @@ function Editor() {
// reset the form values
dispatch({ type: "clear" });
},
onError() {
dispatch({ type: "save_error" });
},
refetchQueries: [{ query: GetJournalMessages, variables: { journalId: journalId } }],
});

Expand All @@ -125,6 +132,9 @@ function Editor() {
case "save": {
return Object.assign({}, state, { saving: true });
}
case "save_error": {
return Object.assign({}, state, { saving: false });
}
case "set_sender": {
return Object.assign({}, state, { sender: action.sender });
}
Expand Down
3 changes: 2 additions & 1 deletion ui/src/views/journal/EditorForms/Elements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ const RadioChannelDetailInput = () => {
};

const SaveButton = () => {
const { dispatch } = useEditorContext();
const { state, dispatch } = useEditorContext();
return (
<div className="control">
<button
Expand All @@ -173,6 +173,7 @@ const SaveButton = () => {
e.preventDefault();
dispatch({ type: "save" });
}}
disabled={state.content === "" || state.sender === "" || state.receiver === ""}
>
{t("save")}
</button>
Expand Down

0 comments on commit 291d918

Please sign in to comment.