Skip to content

Commit c0ef916

Browse files
pvk05yrjarv
andcommitted
Squashed commit of pr/99
Co-Authored-By: Yrjar V <[email protected]>
1 parent b22911d commit c0ef916

File tree

5 files changed

+66
-22
lines changed

5 files changed

+66
-22
lines changed

app/(pages)/(main)/volunteering/logs/voucherLogInput.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { Box, Button, Grid, Skeleton, Stack, TextField, Typography } from "@mui/material";
33
import { useState } from "react";
44
import CustomNumberInput from "@/app/components/input/CustomNumberInput";
5+
import TextFieldWithX from "@/app/components/input/TextFieldWithX";
56

67
export default function voucherLogInput(
78
session,
@@ -132,12 +133,14 @@ export default function voucherLogInput(
132133
check={(data) => data.match(/[^0-9]/)}
133134
error={numVouchersError}
134135
/>
135-
<TextField
136+
<TextFieldWithX
136137
label="Description"
138+
name="voucherdescription"
139+
value={descriptionVoucher}
140+
setValue={setDescriptionVoucher}
137141
size="small"
138142
multiline
139143
InputLabelProps={{ shrink: true }}
140-
value={descriptionVoucher}
141144
error={descriptionVoucherError}
142145
onChange={(e) => setDescriptionVoucher(e.target.value)}
143146
/>

app/(pages)/(main)/volunteering/logs/workLogInput.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import CustomAutoComplete from "@/app/components/input/CustomAutocomplete";
77
import CustomNumberInput from "@/app/components/input/CustomNumberInput";
88
import locale from "date-fns/locale/en-GB";
99
import { CalendarToday, PunchClock } from "@mui/icons-material";
10+
import TextFieldWithX from "@/app/components/input/TextFieldWithX";
1011

1112
export default function workLogInput(
1213
session,
@@ -177,12 +178,14 @@ export default function workLogInput(
177178
</Fab>
178179
</Tooltip>
179180
</Stack>
180-
<TextField
181+
<TextFieldWithX
181182
label="Description"
183+
name="worklogdescription"
184+
value={description}
185+
setValue={setDescription}
182186
size="small"
183187
multiline
184188
InputLabelProps={{ shrink: true }}
185-
value={description}
186189
onChange={(e) => setDescription(e.target.value)}
187190
error={descriptionError}
188191
/>

app/(pages)/(main)/volunteering/membership/page.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import authWrapper from "@/app/middleware/authWrapper";
1616
import { format, parseISO } from "date-fns";
1717
import { useSession } from "next-auth/react";
1818
import { useEffect, useState } from "react";
19+
import TextFieldWithX from "@/app/components/input/TextFieldWithX";
1920

2021
const MEMBERSHIP_TABLE_HEADERS = [
2122
{
@@ -125,23 +126,17 @@ function MembershipPage() {
125126
<Card elevation={3}>
126127
<CardContent>
127128
<Stack direction="column" spacing={2}>
128-
<TextField
129-
variant="outlined"
130-
size="small"
129+
<TextFieldWithX
131130
label="new member"
132-
fullWidth
133-
InputLabelProps={{ shrink: true }}
131+
name="membername"
134132
value={newMemberName}
135-
onChange={(e) => setNewMemberName(e.target.value)}
133+
setValue={setNewMemberName}
136134
/>
137-
<TextField
138-
variant="outlined"
139-
size="small"
135+
<TextFieldWithX
140136
label="comment"
141-
fullWidth
142-
InputLabelProps={{ shrink: true }}
137+
name="membercomment"
143138
value={newMemberComment}
144-
onChange={(e) => setNewMemberComment(e.target.value)}
139+
setValue={setNewMemberComment}
145140
/>
146141
<Button
147142
fullWidth

app/components/CustomTable.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import CustomAutoComplete from "./input/CustomAutocomplete";
2626
import { DateTimePicker, LocalizationProvider } from "@mui/x-date-pickers";
2727
import { AdapterDateFns } from "@mui/x-date-pickers/AdapterDateFnsV3";
2828
import locale from "date-fns/locale/en-GB";
29+
import TextFieldWithX from "./input/TextFieldWithX";
2930

3031
// Styled table component
3132
const TableStyle = styled(Table)(({ theme }) => ({
@@ -180,14 +181,12 @@ function CustomTable({ headers, data, defaultFilterBy=null }) {
180181
}
181182

182183
let searchComponent = (
183-
<TextField
184+
<TextFieldWithX
184185
label="Search string"
185-
size="small"
186-
fullWidth
187-
onKeyDown={(e) => (e.key === "Enter" ? setRefresh(!refresh) : null)}
188-
InputLabelProps={{ shrink: true }}
186+
name="searchString"
189187
value={searchString}
190-
onChange={(e) => setSearchString(e.target.value)}
188+
setValue={setSearchString}
189+
onKeyDown={(e) => (e.key === "Enter" ? setRefresh(!refresh) : null)}
191190
/>
192191
);
193192

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import {
2+
TextField,
3+
InputAdornment,
4+
Tooltip,
5+
} from "@mui/material";
6+
import { Component } from "react";
7+
8+
export default class TextFieldWithX extends Component {
9+
render() {
10+
const { label, name, value, setValue} = this.props;
11+
12+
return (
13+
<TextField
14+
variant="outlined"
15+
size="small"
16+
label={label}
17+
name={name}
18+
fullWidth
19+
InputLabelProps={{ shrink: true }}
20+
value={value}
21+
onChange={(e) => setValue(e.target.value)}
22+
InputProps={{
23+
endAdornment: (
24+
<Tooltip title="Clear">
25+
<InputAdornment
26+
position="end"
27+
onClick={() => {
28+
setValue("");
29+
document.querySelector(`[name="${name}"]`).focus();
30+
}}
31+
sx={{
32+
cursor: 'pointer',
33+
padding: 1.5,
34+
margin: -1.5,
35+
}}
36+
></InputAdornment>
37+
</Tooltip>
38+
),
39+
}}
40+
{...this.props}
41+
/>
42+
);
43+
}
44+
}

0 commit comments

Comments
 (0)