Skip to content

Commit

Permalink
refactor: replace textarea elements with new component
Browse files Browse the repository at this point in the history
  • Loading branch information
stphnnnn committed Nov 30, 2023
1 parent 7a044f8 commit 895b835
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 24 deletions.
6 changes: 5 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
"functional/no-method-signature": 0,
"no-var": "error",
"no-param-reassign": "error",
"prefer-const": "error"
"prefer-const": "error",
"jsx-a11y/label-has-associated-control": [
2,
{ "controlComponents": ["TextArea"] }
]
},
"settings": {
"react": {
Expand Down
17 changes: 4 additions & 13 deletions src/components/EntryForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useEffect, useState, useMemo } from 'react';
import styled from '@emotion/styled';
import {
useForm,
Controller,
Expand Down Expand Up @@ -27,6 +26,7 @@ import crosshair from '../../public/crosshair-small.svg';
import { useMapState } from './MapState';
import Icon from '../design-system/components/Icon';
import { css } from '@emotion/react';
import TextArea from '../design-system/components/TextArea';

type OpeningDayStates =
| `${Lowercase<Weekdays>}-is-open`
Expand All @@ -42,16 +42,6 @@ const openingTimesFields = WEEKDAYS.flatMap((day): OpeningDayStates[] => {
];
});

const Textarea = styled.textarea`
display: block;
height: 10rem;
width: 100%;
margin-top: ${(props) => props.theme.space[1]}px;
padding: ${(props) => props.theme.space[2]}px;
color: ${(props) => props.theme.colors.primary};
border: 1px solid ${(props) => props.theme.colors.primary};
`;

interface Question {
field: string;
subQuestion: string | React.ReactElement;
Expand Down Expand Up @@ -783,10 +773,11 @@ const EntryForm = ({ title, loo, children, ...props }) => {

<Spacer mt={4} />

<label htmlFor="notes">
<label>
7. Notes
<Textarea
<TextArea
name="notes"
rows={6}
defaultValue={loo.notes || ''}
data-testid="notes"
placeholder="Add any other useful information about the toilet here"
Expand Down
2 changes: 0 additions & 2 deletions src/design-system/components/TextArea/TextArea.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
.text-area {
display: block;
height: 10rem;
width: 100%;
margin-top: var(--space-3xs);
padding: var(--space-2xs);
color: var(--color-blue);
border: 1px solid var(--color-blue);
Expand Down
13 changes: 5 additions & 8 deletions src/pages/loos/[id]/remove.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { GetServerSideProps } from 'next';
import NotFound from '../../404.page';
import { css } from '@emotion/react';
import { useMapState } from '../../../components/MapState';
import TextArea from '../../../design-system/components/TextArea';

const RemovePage: PageFindLooByIdComp | React.FC<{ notFound?: boolean }> =
function (props) {
Expand Down Expand Up @@ -58,7 +59,7 @@ const RemovePage: PageFindLooByIdComp | React.FC<{ notFound?: boolean }> =
setMapState({ searchLocation: undefined });
// redirect to updated toilet entry page
router.push(
`/api/loos/${removeData.submitRemovalReport.loo.id}/revalidate?message=removed`
`/api/loos/${removeData.submitRemovalReport.loo.id}/revalidate?message=removed`,
);
}
}, [removeData, router, setMapState]);
Expand Down Expand Up @@ -138,16 +139,12 @@ const RemovePage: PageFindLooByIdComp | React.FC<{ notFound?: boolean }> =
<form onSubmit={onSubmit}>
<label>
<b>Reason for removal</b>
<textarea
type="text"
<TextArea
rows={4}
name="reason"
value={reason}
onChange={updateReason}
required
css={{
height: '100px',
width: '100%',
}}
/>
</label>

Expand Down Expand Up @@ -179,7 +176,7 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
{
variables: { id: ctx.params.id as string },
},
ctx
ctx,
);

if (res.props.error || !res.props.data) {
Expand Down

0 comments on commit 895b835

Please sign in to comment.