Skip to content

Commit 4a5d10a

Browse files
authored
Fix and update create/edit blacklist record (#1041)
* Fix and update create/edit blacklist record Should fix #887 and act more like the add player to blacklist player action * Fix Blacklist expiresAt to not be an empty string Caused "Error: TypeError, value.isValid is not a function" Also update expiresAt to be now when the create new record dialog is opened.
1 parent 44ff613 commit 4a5d10a

File tree

1 file changed

+51
-29
lines changed

1 file changed

+51
-29
lines changed

rcongui/src/components/Blacklist/BlacklistRecordCreateDialog.js

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,20 @@ import DialogActions from "@mui/material/DialogActions";
55
import DialogContent from "@mui/material/DialogContent";
66
import DialogContentText from "@mui/material/DialogContentText";
77
import DialogTitle from "@mui/material/DialogTitle";
8-
import { FormControl, InputLabel, MenuItem, Select, Typography } from "@mui/material";
8+
import { Alert, FormControl, InputLabel, MenuItem, Select, Typography } from "@mui/material";
99
import moment from "moment";
1010
import { getServerStatus, getSharedMessages } from "@/utils/fetchUtils";
1111
import TextHistory from "../textHistory";
1212
import { TimePickerButtons } from "@/components/shared/TimePickerButtons";
1313
import Grid from "@mui/material/Grid2";
1414
import {Fragment, useEffect, useState} from "react";
15+
import dayjs from 'dayjs';
16+
import { DesktopDateTimePicker } from '@mui/x-date-pickers/DesktopDateTimePicker';
17+
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
18+
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
1519

1620
const presetTimes = [
17-
[1, "hour"],
21+
[2, "hours"],
1822
[1, "day"],
1923
[1, "week"],
2024
[1, "month"],
@@ -67,7 +71,7 @@ export default function BlacklistRecordCreateDialog({
6771
}) {
6872
const [blacklist, setBlacklist] = useState("");
6973
const [playerId, setPlayerId] = useState("");
70-
const [expiresAt, setExpiresAt] = useState("");
74+
const [expiresAt, setExpiresAt] = useState(dayjs());
7175
const [reason, setReason] = useState("");
7276
const [currentServer, setCurrentServer] = useState({});
7377
const [punishMessages, setPunishMessages] = useState([]);
@@ -102,14 +106,15 @@ export default function BlacklistRecordCreateDialog({
102106
);
103107
if (blacklist) setBlacklist(blacklist);
104108
}
105-
if (initialValues.playerId !== undefined)
106-
setPlayerId(initialValues.playerId);
109+
if (initialValues.playerId !== undefined) setPlayerId(initialValues.playerId);
107110
if (initialValues.expiresAt !== undefined) {
108111
setExpiresAt(
109-
initialValues.expiresAt === null ? "" : initialValues.expiresAt
112+
initialValues.expiresAt === null ? null : dayjs(initialValues.expiresAt)
110113
);
111114
}
112115
if (initialValues.reason !== undefined) setReason(initialValues.reason);
116+
} else {
117+
setExpiresAt(dayjs());
113118
}
114119
}, [open]);
115120

@@ -123,7 +128,7 @@ export default function BlacklistRecordCreateDialog({
123128
setOpen(false);
124129
setBlacklist("");
125130
setPlayerId("");
126-
setExpiresAt("");
131+
setExpiresAt(dayjs());
127132
setReason("");
128133
};
129134

@@ -138,8 +143,7 @@ export default function BlacklistRecordCreateDialog({
138143
const data = {
139144
blacklistId: blacklist.id,
140145
playerId,
141-
expiresAt:
142-
expiresAt === "" ? null : moment(expiresAt).utc().toISOString(),
146+
expiresAt,
143147
reason,
144148
};
145149
onSubmit(data);
@@ -193,36 +197,54 @@ export default function BlacklistRecordCreateDialog({
193197
{/* EXPIRY */}
194198
<Grid container spacing={2} alignItems="center">
195199
<Grid size={12}>
196-
<TextField
197-
margin="dense"
198-
id="expiresAt"
199-
name="expiresAt"
200-
label="Expires At (empty for never)"
201-
InputLabelProps={{
202-
shrink: true,
203-
}}
204-
type="datetime-local"
205-
value={expiresAt}
206-
onChange={(e) => setExpiresAt(e.target.value)}
207-
fullWidth
208-
variant="standard"
209-
/>
200+
{expiresAt !== null ? (
201+
<LocalizationProvider dateAdapter={AdapterDayjs}>
202+
<DesktopDateTimePicker
203+
onChange={(value) => setExpiresAt(value)}
204+
value={expiresAt}
205+
id="expiresAt"
206+
name="expiresAt"
207+
format='LLL'
208+
ampm={false}
209+
slotProps={{
210+
textField: {
211+
helperText: 'The date this action will expire.',
212+
fullWidth: true,
213+
},
214+
}}
215+
maxDate={dayjs("3000-01-01T00:00:00+00:00")}
216+
disablePast={!disablePlayerId}
217+
/>
218+
</LocalizationProvider>
219+
) : (
220+
<>
221+
<Alert severity="info">
222+
Selected players will be blacklisted indefinitely.
223+
</Alert>
224+
<input type="hidden" name="expiresAt" value={null} />
225+
</>
226+
)}
210227
</Grid>
211228
<Grid size={12}>
212229
{presetTimes.map(([amount, unit], index) => (
213230
<TimePickerButtons
214231
key={unit + index}
215232
amount={amount}
216233
unit={unit}
217-
expirationTimestamp={expiresAt}
218-
setExpirationTimestamp={(timestamp) => {
219-
setExpiresAt(
220-
moment(timestamp).format("YYYY-MM-DDTHH:mm")
221-
);
222-
}}
234+
expirationTimestamp={expiresAt ?? dayjs()}
235+
setExpirationTimestamp={(value) => setExpiresAt(value)}
223236
/>
224237
))}
225238
</Grid>
239+
<Button
240+
variant="outlined"
241+
size="small"
242+
color="secondary"
243+
style={{ display: "block", width: "100%" }}
244+
onClick={() => setExpiresAt(null)}
245+
>
246+
Never expires
247+
</Button>
226248
</Grid>
227249
{/* REASON */}
228250
<Grid container spacing={2} alignItems="top">

0 commit comments

Comments
 (0)