Skip to content

Commit

Permalink
fixup!
Browse files Browse the repository at this point in the history
  • Loading branch information
Saelmala authored and malmen237 committed Nov 20, 2024
1 parent 9c4b847 commit 1c36f01
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/components/production-line/settings-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,21 @@ export const SettingsModal = ({
}
};

const handleSave = () => {
const hasErrors = Object.values(errors).some((error) => error !== "");
if (!hasErrors) {
onSave();
}
};

const handleKeyDown = (e: React.KeyboardEvent, index: number) => {
if (e.key === "Enter") {
e.preventDefault();
const nextInput = inputRefs.current[index + 1];
if (nextInput) {
nextInput.focus();
} else {
const hasErrors = Object.values(errors).some((error) => error !== "");
if (!hasErrors) {
onSave();
}
handleSave();
}
} else if (e.key === "ArrowUp") {
e.preventDefault();
Expand Down Expand Up @@ -237,15 +241,7 @@ export const SettingsModal = ({
<CancelButton type="button" onClick={onClose}>
Cancel
</CancelButton>
<PrimaryButton
type="button"
onClick={() => {
const hasErrors = Object.values(errors).some(
(error) => error !== ""
);
if (!hasErrors) onSave();
}}
>
<PrimaryButton type="button" onClick={handleSave}>
Save settings
</PrimaryButton>
</ButtonDiv>
Expand Down

0 comments on commit 1c36f01

Please sign in to comment.