Skip to content

Commit

Permalink
fixes 17-the-wild-oasis starter file fix jonasschmedtmann#8
Browse files Browse the repository at this point in the history
  • Loading branch information
kjroelke committed Jun 24, 2023
1 parent 3e69024 commit a18e578
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 66 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules
/**/node_modules
83 changes: 17 additions & 66 deletions 17-the-wild-oasis/starter/features/settings/UpdateSettingsForm.jsx
Original file line number Diff line number Diff line change
@@ -1,74 +1,25 @@
import Spinner from 'ui/Spinner';
import { useSettings } from 'features/settings/useSettings';
import { useUpdateSetting } from 'features/settings/useUpdateSetting';

import Form from 'ui/Form';
import FormRow from 'ui/FormRow';
import Input from 'ui/Input';

function UpdateSettingsForm() {
const {
settings: {
minBookingLength,
maxBookingLength,
maxGuestsPerBooking,
breakfastPrice,
} = {},
isLoading,
} = useSettings();
const { mutate: updateSetting, isLoading: isUpdating } = useUpdateSetting();

// return <Spinner />;
if (isLoading) return <Spinner />;

function handleBlur(e, field) {
const { value } = e.target;

if (!value) return;
updateSetting({ [field]: value });
}

// This time we are using UNCONTROLLED fields, so we will NOT store state
return (
<Form>
<FormRow label='Minimum nights/booking'>
<Input
type='number'
defaultValue={minBookingLength}
onBlur={(e) => handleBlur(e, 'minBookingLength')}
disabled={isUpdating}
id='min-nights'
/>
</FormRow>
<FormRow label='Maximum nights/booking'>
<Input
type='number'
defaultValue={maxBookingLength}
onBlur={(e) => handleBlur(e, 'maxBookingLength')}
disabled={isUpdating}
id='max-nights'
/>
</FormRow>
<FormRow label='Maximum guests/booking'>
<Input
type='number'
defaultValue={maxGuestsPerBooking}
onBlur={(e) => handleBlur(e, 'maxGuestsPerBooking')}
disabled={isUpdating}
id='max-guests'
/>
</FormRow>
<FormRow label='Breakfast price'>
<Input
type='number'
defaultValue={breakfastPrice}
onBlur={(e) => handleBlur(e, 'breakfastPrice')}
disabled={isUpdating}
id='breakfast-price'
/>
</FormRow>
</Form>
);
// This time we are using UNCONTROLLED fields, so we will NOT store state
return (
<Form>
<FormRow label="Minimum nights/booking">
<Input type="number" id="min-nights" />
</FormRow>
<FormRow label="Maximum nights/booking">
<Input type="number" id="max-nights" />
</FormRow>
<FormRow label="Maximum guests/booking">
<Input type="number" id="max-guests" />
</FormRow>
<FormRow label="Breakfast price">
<Input type="number" id="breakfast-price" />
</FormRow>
</Form>
);
}

export default UpdateSettingsForm;

0 comments on commit a18e578

Please sign in to comment.