Skip to content

Commit

Permalink
fix: reset values on cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
remvze committed Apr 25, 2024
1 parent af92b1e commit 89a8308
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/components/toolbox/pomodoro/setting/setting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,26 @@ interface SettingProps {
export function Setting({ onChange, onClose, show, times }: SettingProps) {
const [values, setValues] = useState(times);

useEffect(() => setValues(times), [times]);
useEffect(() => {
if (show) setValues(times);
}, [times, show]);

const handleChange = (id: string) => (value: number) => {
setValues(prev => ({ ...prev, [id]: value * 60 }));
};

const handleSubmit = e => {
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();

onChange(values);
};

const handleCancel = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
e.preventDefault();

onClose();
};

return (
<Modal lockBody={false} show={show} onClose={onClose}>
<h2 className={styles.title}>Change Times</h2>
Expand All @@ -51,14 +59,7 @@ export function Setting({ onChange, onClose, show, times }: SettingProps) {
/>

<div className={styles.buttons}>
<button
onClick={e => {
e.preventDefault();
onClose();
}}
>
Cancel
</button>
<button onClick={handleCancel}>Cancel</button>
<button className={styles.primary}>Save</button>
</div>
</form>
Expand Down

0 comments on commit 89a8308

Please sign in to comment.