Add an accommodations reservations module (#188)
All checks were successful
continuous-integration/drone/push Build is passing

Add a new module to enable accommodations reservation

![](https://gitea.communiquons.org/attachments/de1f5b12-0a93-40f8-b29d-97665daa6fd5)

Reviewed-on: #188
This commit is contained in:
2024-06-22 21:30:26 +00:00
parent 8ecacbe622
commit 1a890844ef
54 changed files with 4230 additions and 33 deletions

View File

@ -5,16 +5,20 @@ export function PropCheckbox(p: {
label: string;
checked: boolean | undefined;
onValueChange: (v: boolean) => void;
checkboxAlwaysVisible?: boolean;
}): React.ReactElement {
if (!p.editable && p.checked)
return <Typography variant="body2">{p.label}</Typography>;
if (!p.checkboxAlwaysVisible) {
if (!p.editable && p.checked)
return <Typography variant="body2">{p.label}</Typography>;
if (!p.editable) return <></>;
if (!p.editable) return <></>;
}
return (
<FormControlLabel
control={
<Checkbox
disabled={!p.editable}
checked={p.checked}
onChange={(e) => p.onValueChange(e.target.checked)}
/>

View File

@ -0,0 +1,24 @@
import { MuiColorInput } from "mui-color-input";
import { PropEdit } from "./PropEdit";
export function PropColorPicker(p: {
editable: boolean;
label: string;
value?: string;
onChange: (v: string | undefined) => void;
}): React.ReactElement {
if (!p.editable) {
if (!p.value) return <></>;
return <PropEdit editable={false} label={p.label} value={`#${p.value}`} />;
}
return (
<MuiColorInput
value={"#" + (p.value ?? "")}
fallbackValue="#ffffff"
format="hex"
onChange={(_v, c) => p.onChange(c.hex.substring(1))}
/>
);
}

View File

@ -0,0 +1,103 @@
import { LocalizationProvider } from "@mui/x-date-pickers";
import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs";
import { DatePicker } from "@mui/x-date-pickers/DatePicker";
import dayjs from "dayjs";
import "dayjs/locale/fr";
import { fmtUnixDate } from "../../utils/time_utils";
import { PropEdit } from "./PropEdit";
import { Checkbox, FormControlLabel } from "@mui/material";
export function PropDateInput(p: {
editable: boolean;
label: string;
value: number | undefined;
onChange: (v: number | undefined) => void;
lastSecOfDay?: boolean;
minDate?: number;
maxDate?: number;
canSetMiddleDay?: boolean;
}): React.ReactElement {
// Check for mid-day value
let isMidDay = false;
if (p.value) {
const d = new Date(p.value * 1000);
isMidDay =
d.getHours() === 12 && d.getMinutes() === 0 && d.getSeconds() === 0;
}
// Shift value
let shiftV = p.value;
if (shiftV && p.lastSecOfDay) {
const d = new Date(shiftV * 1000);
if (d.getHours() === 0) {
shiftV -= 1;
}
}
if (!p.editable) {
if (!shiftV) return <></>;
return (
<PropEdit editable={false} label={p.label} value={fmtUnixDate(shiftV)} />
);
}
const value = dayjs(
shiftV && p.value! > 0 ? new Date(shiftV * 1000) : undefined
);
const minDate = p.minDate ? dayjs(new Date(p.minDate * 1000)) : undefined;
const maxDate = p.maxDate ? dayjs(new Date(p.maxDate * 1000)) : undefined;
return (
<>
<div style={{ height: "10px" }}></div>
<LocalizationProvider dateAdapter={AdapterDayjs} adapterLocale="fr">
<DatePicker
label={p.label}
value={value}
onChange={(v) => {
if (v && p.lastSecOfDay) {
v = v.set("hours", 23);
v = v.set("minutes", 59);
v = v.set("seconds", 59);
}
p.onChange?.(v ? v.unix() : undefined);
}}
minDate={minDate}
maxDate={maxDate}
/>
</LocalizationProvider>
{p.canSetMiddleDay && (
<FormControlLabel
disabled={!p.value}
control={
<Checkbox
checked={isMidDay}
onChange={(_ev, midDay) => {
let v = value;
if (midDay) {
v = v.set("hours", 12);
v = v.set("minutes", 0);
v = v.set("seconds", 0);
} else if (p.lastSecOfDay) {
v = v.set("hours", 23);
v = v.set("minutes", 59);
v = v.set("seconds", 59);
} else {
v = v.set("hours", 0);
v = v.set("minutes", 0);
v = v.set("seconds", 0);
}
p.onChange(v.unix());
}}
/>
}
label="Mi-journée"
/>
)}
<div style={{ height: "30px" }}></div>
</>
);
}

View File

@ -14,6 +14,7 @@ export function PropEdit(p: {
multiline?: boolean;
minRows?: number;
maxRows?: number;
helperText?: string;
}): React.ReactElement {
if (((!p.editable && p.value) ?? "") === "") return <></>;
@ -44,6 +45,7 @@ export function PropEdit(p: {
!p.checkValue(p.value)) ||
false
}
helperText={p.helperText}
/>
);
}

View File

@ -2,7 +2,7 @@ import { FormControl, InputLabel, MenuItem, Select } from "@mui/material";
import { PropEdit } from "./PropEdit";
export interface SelectOption {
value: string;
value: string | undefined;
label: string;
}
@ -19,6 +19,7 @@ export function PropSelect(p: {
const value = p.options.find((o) => o.value === p.value)?.label;
return <PropEdit label={p.label} editable={p.editing} value={value} />;
}
return (
<FormControl fullWidth variant="filled" style={{ marginBottom: "15px" }}>
<InputLabel>{p.label}</InputLabel>