mirror of
https://github.com/remvze/moodist.git
synced 2025-12-17 08:54:13 +00:00
fix: reset values on cancel
This commit is contained in:
parent
af92b1ed90
commit
89a83089c5
1 changed files with 11 additions and 10 deletions
|
|
@ -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>
|
||||
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue