Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | 133x 133x 133x 133x 133x 3x 3x 3x 133x 41x 133x 5x 4x 1x 128x 45x 133x 133x 133x 133x 133x 2x 2x 2x 2x 2x 2x 133x 3x 3x 133x 133x 3x 45x 45x | import { Box, FormControlLabel, Grid, Stack } from "@mui/material";
import { usePayBuilderForm } from "@sections/PayBuilder/provider/PayBuilderFormProvider";
import TabSection from "./TabSection";
import LocationSection from "./LocationSection";
import { ControlledDatePicker } from "./components/ControlledDatePicker";
import GiveCheckbox from "@shared/GiveCheckbox/GiveCheckbox";
import { ControlledAutoCompleteTime } from "./components/Timers/ControlledAutoCompleteTime";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import { useCallback, useEffect } from "react";
function TimeInputs({ timeActiveTab, includeTime }: any) {
const { methods } = usePayBuilderForm();
const { watch, trigger, getValues } = methods;
const [startsAt, endsAt] = watch([
"DateLocation.startsAt",
"DateLocation.endsAt",
]);
const { isMobileView, isDesktopView } = useCustomThemeV2();
const validateTimeFieldsOnDateChange = useCallback(() => {
const [startsAtTime, endsAtTime] = getValues([
"DateLocation.startsAtTime",
"DateLocation.endsAtTime",
]);
Iif (startsAt && startsAtTime) {
trigger("DateLocation.startsAtTime");
}
Iif (endsAt && endsAtTime) {
trigger("DateLocation.endsAtTime");
}
}, [startsAt, endsAt]);
useEffect(() => {
if (includeTime) validateTimeFieldsOnDateChange();
}, [includeTime, startsAt, endsAt]);
if (includeTime) {
if (timeActiveTab === "single") {
return <ControlledAutoCompleteTime name="DateLocation.startsAtTime" />;
} else {
return (
<Grid
container
gap={isMobileView || isDesktopView ? 2 : 0}
justifyContent="space-between"
>
<Grid item sx={{ width: isMobileView ? "100%" : "48%" }}>
<ControlledAutoCompleteTime name="DateLocation.startsAtTime" />
</Grid>
<Grid item sx={{ width: isMobileView ? "100%" : "48%" }}>
<ControlledAutoCompleteTime name="DateLocation.endsAtTime" />
</Grid>
</Grid>
);
}
}
return null;
}
export const DateAndLocation = ({ isEdit }: { isEdit?: boolean }) => {
const { methods } = usePayBuilderForm();
const { setValue, watch, trigger } = methods;
const { isMobileView, isDesktopView } = useCustomThemeV2();
const values = watch();
const onClickTimeTab = useCallback((e: any) => {
setValue("DateLocation.timeActiveTab", e);
setValue("DateLocation.startsAt", null);
setValue("DateLocation.endsAt", null);
setValue("DateLocation.includeTime", false);
methods.clearErrors("DateLocation.startsAt");
methods.clearErrors("DateLocation.endsAt");
}, []);
const onClickLocationTab = useCallback((e: any) => {
setValue("DateLocation.locationPosition", e, {
shouldValidate: true,
});
methods.clearErrors("DateLocation.locationURL");
}, []);
const onChangeCustom = useCallback(() => {
trigger("DateLocation.endsAt");
}, []);
return (
<Box pb="20px">
<Stack gap="40px">
<Stack gap="16px">
<TabSection
title="When is the event?"
onClick={onClickTimeTab}
tabItems={timeTabs}
selectedTab={values.DateLocation?.timeActiveTab}
/>
<Grid
id="time_section"
container
gap={2}
justifyContent="space-between"
>
{values.DateLocation.timeActiveTab === "single" ? (
<ControlledDatePicker
name="DateLocation.startsAt"
disablePast
useUTCMoment
/>
) : (
<Grid
container
gap={isMobileView || isDesktopView ? 2 : 0}
justifyContent="space-between"
>
<Grid item sx={{ width: isMobileView ? "100%" : "48%" }}>
<ControlledDatePicker
label="Start"
name="DateLocation.startsAt"
onChangeCustom={onChangeCustom}
disablePast
useUTCMoment
isValidateForm
/>
</Grid>
<Grid item sx={{ width: isMobileView ? "100%" : "48%" }}>
<ControlledDatePicker
label="End"
name="DateLocation.endsAt"
disablePast
useUTCMoment
isValidateForm
/>
</Grid>
</Grid>
)}
<FormControlLabel
sx={{
margin: 0,
gap: "12px",
}}
label="Include Time"
control={
<GiveCheckbox
checked={watch("DateLocation.includeTime")}
onChange={(e) => {
setValue("DateLocation.includeTime", e.target.checked);
}}
/>
}
/>
<TimeInputs
timeActiveTab={values.DateLocation.timeActiveTab}
includeTime={values.DateLocation.includeTime}
/>
</Grid>
</Stack>
<Stack gap="16px">
<TabSection
title="Where is the event?"
tabItems={locationTabs}
selectedTab={values.DateLocation.locationPosition}
onClick={onClickLocationTab}
/>
<LocationSection
locationPosition={values.DateLocation?.locationPosition}
/>
</Stack>
</Stack>
</Box>
);
};
const locationTabs = [
{
label: "On-site",
value: "onsite",
},
{
label: "Online",
value: "online",
},
];
const timeTabs = [
{
label: "On a day",
value: "single",
},
{
label: "Period",
value: "range",
},
];
|