Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
29 changes: 29 additions & 0 deletions 17-the-wild-oasis/final-1-after-setup/src/ui/FormRowVertical.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import styled from "styled-components";

const StyledFormRow = styled.div`
display: flex;
flex-direction: column;
gap: 0.8rem;
padding: 1.2rem 0;
`;

const Label = styled.label`
font-weight: 500;
`;

const Error = styled.span`
font-size: 1.4rem;
color: var(--color-red-700);
`;

function FormRowVertical({ label, error, children }) {
return (
<StyledFormRow>
{label && <Label htmlFor={children.props.id}>{label}</Label>}
{children}
{error && <Error>{error}</Error>}
</StyledFormRow>
);
}

export default FormRowVertical;
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import styled from "styled-components";

const StyledFormRow = styled.div`
display: flex;
flex-direction: column;
gap: 0.8rem;
padding: 1.2rem 0;
`;

const Label = styled.label`
font-weight: 500;
`;

const Error = styled.span`
font-size: 1.4rem;
color: var(--color-red-700);
`;

function FormRowVertical({ label, error, children }) {
return (
<StyledFormRow>
{label && <Label htmlFor={children.props.id}>{label}</Label>}
{children}
{error && <Error>{error}</Error>}
</StyledFormRow>
);
}

export default FormRowVertical;
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import styled from "styled-components";

const StyledFormRow = styled.div`
display: flex;
flex-direction: column;
gap: 0.8rem;
padding: 1.2rem 0;
`;

const Label = styled.label`
font-weight: 500;
`;

const Error = styled.span`
font-size: 1.4rem;
color: var(--color-red-700);
`;

function FormRowVertical({ label, error, children }) {
return (
<StyledFormRow>
{label && <Label htmlFor={children.props.id}>{label}</Label>}
{children}
{error && <Error>{error}</Error>}
</StyledFormRow>
);
}

export default FormRowVertical;
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import styled from "styled-components";

const StyledFormRow = styled.div`
display: flex;
flex-direction: column;
gap: 0.8rem;
padding: 1.2rem 0;
`;

const Label = styled.label`
font-weight: 500;
`;

const Error = styled.span`
font-size: 1.4rem;
color: var(--color-red-700);
`;

function FormRowVertical({ label, error, children }) {
return (
<StyledFormRow>
{label && <Label htmlFor={children.props.id}>{label}</Label>}
{children}
{error && <Error>{error}</Error>}
</StyledFormRow>
);
}

export default FormRowVertical;
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import styled from "styled-components";

const StyledFormRow = styled.div`
display: flex;
flex-direction: column;
gap: 0.8rem;
padding: 1.2rem 0;
`;

const Label = styled.label`
font-weight: 500;
`;

const Error = styled.span`
font-size: 1.4rem;
color: var(--color-red-700);
`;

function FormRowVertical({ label, error, children }) {
return (
<StyledFormRow>
{label && <Label htmlFor={children.props.id}>{label}</Label>}
{children}
{error && <Error>{error}</Error>}
</StyledFormRow>
);
}

export default FormRowVertical;
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;
29 changes: 29 additions & 0 deletions 17-the-wild-oasis/starter/ui/FormRowVertical.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import styled from "styled-components";

const StyledFormRow = styled.div`
display: flex;
flex-direction: column;
gap: 0.8rem;
padding: 1.2rem 0;
`;

const Label = styled.label`
font-weight: 500;
`;

const Error = styled.span`
font-size: 1.4rem;
color: var(--color-red-700);
`;

function FormRowVertical({ label, error, children }) {
return (
<StyledFormRow>
{label && <Label htmlFor={children.props.id}>{label}</Label>}
{children}
{error && <Error>{error}</Error>}
</StyledFormRow>
);
}

export default FormRowVertical;