@selfcommunity/react-ui 0.10.2-alpha.6 → 0.10.2-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -114,7 +114,7 @@ const Root = (0, styles_1.styled)(material_1.Box, {
114
114
  * @param inProps
115
115
  */
116
116
  function EventForm(inProps) {
117
- var _a, _b, _c, _d;
117
+ var _a, _b, _c;
118
118
  //PROPS
119
119
  const props = (0, system_1.useThemeProps)({
120
120
  props: inProps,
@@ -142,7 +142,7 @@ function EventForm(inProps) {
142
142
  recurring: (event === null || event === void 0 ? void 0 : event.recurring) || types_1.SCEventRecurrenceType.NEVER,
143
143
  name: (event === null || event === void 0 ? void 0 : event.name) || '',
144
144
  description: event ? event.description : '',
145
- isPublic: (_a = (event === null || event === void 0 ? void 0 : event.privacy) === types_1.SCEventPrivacyType.PUBLIC) !== null && _a !== void 0 ? _a : true,
145
+ isPublic: (event === null || event === void 0 ? void 0 : event.privacy) === types_1.SCEventPrivacyType.PUBLIC || true,
146
146
  isSubmitting: false
147
147
  };
148
148
  // STATE
@@ -227,9 +227,7 @@ function EventForm(inProps) {
227
227
  })
228
228
  .catch((e) => {
229
229
  const _error = (0, api_services_1.formatHttpErrorCode)(e);
230
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore,@typescript-eslint/ban-ts-comment
231
- // @ts-ignore
232
- if (Object.values(_error)[0].error === 'unique') {
230
+ if (Object.values(_error)[0]['error'] === 'unique') {
233
231
  setError(Object.assign(Object.assign({}, error), { ['nameError']: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.eventForm.name.error.unique", defaultMessage: "ui.eventForm.name.error.unique" }) }));
234
232
  }
235
233
  else {
@@ -239,7 +237,7 @@ function EventForm(inProps) {
239
237
  utils_1.Logger.error(Errors_1.SCOPE_SC_UI, e);
240
238
  onError === null || onError === void 0 ? void 0 : onError(e);
241
239
  });
242
- }, [field, privateEnabled, visibilityEnabled, onSuccess, onError]);
240
+ }, [field, privateEnabled, visibilityEnabled, onSuccess, onError, notifyChanges]);
243
241
  const handleChange = (0, react_1.useCallback)((event) => {
244
242
  const { name, value } = event.target;
245
243
  setField((prev) => (Object.assign(Object.assign({}, prev), { [name]: value })));
@@ -247,7 +245,7 @@ function EventForm(inProps) {
247
245
  delete error[`${name}Error`];
248
246
  setError(error);
249
247
  }
250
- }, [error]);
248
+ }, [setField, error]);
251
249
  const handleChangeDateTime = (0, react_1.useCallback)((value, name) => {
252
250
  setField((prev) => (Object.assign(Object.assign({}, prev), { [name]: value })));
253
251
  if (error[`${name}Error`]) {
@@ -258,29 +256,26 @@ function EventForm(inProps) {
258
256
  delete error['endDateError'];
259
257
  setError(error);
260
258
  }
261
- }, [error]);
262
- const shouldDisabledDate = (0, react_1.useCallback)((date) => {
259
+ }, [setField, error]);
260
+ const shouldDisableDate = (0, react_1.useCallback)((date) => {
263
261
  let disabled = false;
264
262
  switch (field.recurring) {
265
263
  case types_1.SCEventRecurrenceType.DAILY:
266
- disabled = date.getTime() > (0, utils_2.getLaterDaysDate)(constants_1.DAILY_LATER_DAYS).getTime();
264
+ disabled = date.getTime() > (0, utils_2.getLaterDaysDate)(constants_1.DAILY_LATER_DAYS, field.startDate).getTime();
267
265
  break;
268
266
  case types_1.SCEventRecurrenceType.WEEKLY:
269
- disabled = date.getTime() > (0, utils_2.getLaterDaysDate)(constants_1.WEEKLY_LATER_DAYS).getTime();
267
+ disabled = date.getTime() > (0, utils_2.getLaterDaysDate)(constants_1.WEEKLY_LATER_DAYS, field.startDate).getTime();
270
268
  break;
271
269
  case types_1.SCEventRecurrenceType.MONTHLY:
272
- disabled = date.getTime() > (0, utils_2.getLaterDaysDate)(constants_1.MONTHLY_LATER_DAYS).getTime();
270
+ disabled = date.getTime() > (0, utils_2.getLaterDaysDate)(constants_1.MONTHLY_LATER_DAYS, field.startDate).getTime();
273
271
  break;
274
272
  case types_1.SCEventRecurrenceType.NEVER:
275
273
  default:
276
- disabled = date.getTime() > (0, utils_2.getLaterDaysDate)(constants_1.NEVER_LATER_DAYS).getTime();
277
- }
278
- if (field.startDate.getDate() > date.getDate()) {
279
- disabled = true;
274
+ disabled = date.getTime() > (0, utils_2.getLaterDaysDate)(constants_1.NEVER_LATER_DAYS, field.startDate).getTime();
280
275
  }
281
276
  return disabled;
282
277
  }, [field]);
283
- const shouldDisabledTime = (0, react_1.useCallback)((date, _view) => field.startTime.getTime() > date.getTime(), [field]);
278
+ const shouldDisableTime = (0, react_1.useCallback)((date) => field.startTime.getTime() > date.getTime(), [field]);
284
279
  /**
285
280
  * Renders root object
286
281
  */
@@ -307,24 +302,36 @@ function EventForm(inProps) {
307
302
  return (0, jsx_runtime_1.jsx)("em", { children: `${intl.formatMessage(messages.frequencyPlaceholder)}` });
308
303
  }
309
304
  return ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: `ui.eventForm.frequency.${selected}.placeholder`, defaultMessage: `ui.eventForm.frequency.${selected}.placeholder` }));
310
- }, startAdornment: (0, jsx_runtime_1.jsx)(material_1.InputAdornment, Object.assign({ position: "start" }, { children: (0, jsx_runtime_1.jsx)(material_1.IconButton, { children: (0, jsx_runtime_1.jsx)(material_1.Icon, { children: "frequency" }) }) })) }, { children: Object.values(types_1.SCEventRecurrenceType).map((f) => ((0, jsx_runtime_1.jsx)(material_1.MenuItem, Object.assign({ value: f }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: `ui.eventForm.frequency.${f}.placeholder`, defaultMessage: `ui.eventForm.frequency.${f}.placeholder` }) }), f))) }))] })), (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.dateTime }, { children: (0, jsx_runtime_1.jsxs)(x_date_pickers_1.LocalizationProvider, Object.assign({ dateAdapter: AdapterDateFns_1.AdapterDateFns, adapterLocale: scContext.settings.locale.default === 'it' ? it_1.default : en_US_1.default }, { children: [(0, jsx_runtime_1.jsx)(x_date_pickers_1.MobileDatePicker, { className: classes.picker, disablePast: true, minDate: field.startDate, label: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.eventForm.date.end.placeholder", defaultMessage: "ui.eventForm.date.end.placeholder" }), value: field.endDate, slots: {
305
+ }, startAdornment: (0, jsx_runtime_1.jsx)(material_1.InputAdornment, Object.assign({ position: "start" }, { children: (0, jsx_runtime_1.jsx)(material_1.IconButton, { children: (0, jsx_runtime_1.jsx)(material_1.Icon, { children: "frequency" }) }) })) }, { children: Object.values(types_1.SCEventRecurrenceType).map((f) => ((0, jsx_runtime_1.jsx)(material_1.MenuItem, Object.assign({ value: f }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: `ui.eventForm.frequency.${f}.placeholder`, defaultMessage: `ui.eventForm.frequency.${f}.placeholder` }) }), f))) }))] })), (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.dateTime }, { children: (0, jsx_runtime_1.jsxs)(x_date_pickers_1.LocalizationProvider, Object.assign({ dateAdapter: AdapterDateFns_1.AdapterDateFns, adapterLocale: scContext.settings.locale.default === 'it' ? it_1.default : en_US_1.default }, { children: [(0, jsx_runtime_1.jsx)(x_date_pickers_1.MobileDatePicker, { className: classes.picker, minDate: field.startDate, label: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.eventForm.date.end.placeholder", defaultMessage: "ui.eventForm.date.end.placeholder" }), value: field.endDate, slots: {
311
306
  textField: (params) => ((0, jsx_runtime_1.jsx)(material_1.TextField, Object.assign({}, params, { InputProps: Object.assign(Object.assign({}, params.InputProps), { placeholder: `${intl.formatMessage(messages.endDate)}`, startAdornment: ((0, jsx_runtime_1.jsx)(material_1.InputAdornment, Object.assign({ position: "start" }, { children: (0, jsx_runtime_1.jsx)(material_1.IconButton, { children: (0, jsx_runtime_1.jsx)(material_1.Icon, { children: "calendar_off" }) }) }))) }) })))
312
- }, onChange: (value) => handleChangeDateTime(value, 'endDate'), shouldDisableDate: shouldDisabledDate }), (0, jsx_runtime_1.jsx)(x_date_pickers_1.MobileTimePicker, { className: classes.picker, disablePast: disablePastEndTime, label: field.endTime && (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.eventForm.time.end.placeholder", defaultMessage: "ui.eventForm.time.end.placeholder" }), value: field.endTime, slots: {
307
+ }, slotProps: {
308
+ toolbar: {
309
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore,@typescript-eslint/ban-ts-comment
310
+ // @ts-ignore
311
+ toolbarTitle: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.eventForm.date.title", defaultMessage: "ui.eventForm.date.title" })
312
+ }
313
+ }, onChange: (value) => handleChangeDateTime(value, 'endDate'), shouldDisableDate: shouldDisableDate }), (0, jsx_runtime_1.jsx)(x_date_pickers_1.MobileTimePicker, { className: classes.picker, disablePast: disablePastEndTime, label: field.endTime && (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.eventForm.time.end.placeholder", defaultMessage: "ui.eventForm.time.end.placeholder" }), value: field.endTime, slots: {
313
314
  textField: (params) => {
314
315
  var _a;
315
316
  return ((0, jsx_runtime_1.jsx)(material_1.TextField, Object.assign({}, params, { InputProps: Object.assign(Object.assign({}, params.InputProps), { placeholder: `${intl.formatMessage(messages.endTime)}`, startAdornment: ((0, jsx_runtime_1.jsx)(material_1.InputAdornment, Object.assign({ position: "start" }, { children: (0, jsx_runtime_1.jsx)(material_1.IconButton, { children: (0, jsx_runtime_1.jsx)(material_1.Icon, { children: "access_time" }) }) }))) }), error: Boolean(error['endDateError']), helperText: ((_a = error['endDateError']) === null || _a === void 0 ? void 0 : _a.error) ? ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.eventForm.time.end.error.invalid", defaultMessage: "ui.eventForm.time.end.error.invalid" })) : null })));
316
317
  }
317
- }, onChange: (value) => handleChangeDateTime(value, 'endTime'), shouldDisableTime: shouldDisabledTime })] })) })), (0, jsx_runtime_1.jsx)(EventAddress_1.default, { forwardGeolocationData: handleGeoData, event: event !== null && event !== void 0 ? event : null }), privateEnabled && ((0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ className: classes.privacySection }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Stack, Object.assign({ direction: "row", spacing: 1, alignItems: "center", justifyContent: "center" }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Typography, Object.assign({ className: (0, classnames_1.default)(classes.switchLabel, { [classes.active]: !field.isPublic }) }, { children: [(0, jsx_runtime_1.jsx)(material_1.Icon, { children: "private" }), (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.eventForm.privacy.private", defaultMessage: "ui.eventForm.privacy.private" })] })), (0, jsx_runtime_1.jsx)(material_1.Switch, { className: classes.switch, checked: field.isPublic, onChange: () => setField((prev) => (Object.assign(Object.assign({}, prev), { ['isPublic']: !field.isPublic }))), disabled: event && !field.isPublic }), (0, jsx_runtime_1.jsxs)(material_1.Typography, Object.assign({ className: (0, classnames_1.default)(classes.switchLabel, { [classes.active]: field.isPublic }) }, { children: [(0, jsx_runtime_1.jsx)(material_1.Icon, { children: "public" }), (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.eventForm.privacy.public", defaultMessage: "ui.eventForm.privacy.public" })] }))] })), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2", textAlign: "center", className: classes.privacySectionInfo }, { children: field.isPublic ? ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.eventForm.privacy.public.info", defaultMessage: "ui.eventForm.privacy.public.info", values: {
318
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
319
- // @ts-ignore
318
+ }, slotProps: {
319
+ toolbar: {
320
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore,@typescript-eslint/ban-ts-comment
321
+ // @ts-ignore
322
+ toolbarTitle: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.eventForm.time.title", defaultMessage: "ui.eventForm.time.title" })
323
+ }
324
+ }, onChange: (value) => handleChangeDateTime(value, 'endTime'), shouldDisableTime: shouldDisableTime })] })) })), (0, jsx_runtime_1.jsx)(EventAddress_1.default, { forwardGeolocationData: handleGeoData, event: event !== null && event !== void 0 ? event : null }), privateEnabled && ((0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ className: classes.privacySection }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Stack, Object.assign({ direction: "row", spacing: 1, alignItems: "center", justifyContent: "center" }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Typography, Object.assign({ className: (0, classnames_1.default)(classes.switchLabel, { [classes.active]: !field.isPublic }) }, { children: [(0, jsx_runtime_1.jsx)(material_1.Icon, { children: "private" }), (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.eventForm.privacy.private", defaultMessage: "ui.eventForm.privacy.private" })] })), (0, jsx_runtime_1.jsx)(material_1.Switch, { className: classes.switch, checked: field.isPublic, onChange: () => setField((prev) => (Object.assign(Object.assign({}, prev), { ['isPublic']: !field.isPublic }))), disabled: event && !field.isPublic }), (0, jsx_runtime_1.jsxs)(material_1.Typography, Object.assign({ className: (0, classnames_1.default)(classes.switchLabel, { [classes.active]: field.isPublic }) }, { children: [(0, jsx_runtime_1.jsx)(material_1.Icon, { children: "public" }), (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.eventForm.privacy.public", defaultMessage: "ui.eventForm.privacy.public" })] }))] })), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2", textAlign: "center", className: classes.privacySectionInfo }, { children: field.isPublic ? ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.eventForm.privacy.public.info", defaultMessage: "ui.eventForm.privacy.public.info", values: {
325
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore,@typescript-eslint/ban-ts-comment
326
+ // @ts-ignores
320
327
  b: (chunks) => (0, jsx_runtime_1.jsx)("strong", { children: chunks })
321
328
  } })) : ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.eventForm.privacy.private.info", defaultMessage: "ui.eventForm.private.public.info", values: {
322
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
329
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore,@typescript-eslint/ban-ts-comment
323
330
  // @ts-ignore
324
331
  b: (chunks) => (0, jsx_runtime_1.jsx)("strong", { children: chunks })
325
332
  } })) }))] }))), (0, jsx_runtime_1.jsx)(material_1.TextField, { multiline: true, className: classes.description, placeholder: `${intl.formatMessage(messages.description)}`, margin: "normal", value: field.description, name: "description", onChange: handleChange, InputProps: {
326
- endAdornment: ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2" }, { children: ((_b = field.description) === null || _b === void 0 ? void 0 : _b.length) ? Event_1.EVENT_DESCRIPTION_MAX_LENGTH - field.description.length : Event_1.EVENT_DESCRIPTION_MAX_LENGTH })))
327
- }, error: Boolean(((_c = field.description) === null || _c === void 0 ? void 0 : _c.length) > Event_1.EVENT_DESCRIPTION_MAX_LENGTH), helperText: ((_d = field.description) === null || _d === void 0 ? void 0 : _d.length) > Event_1.EVENT_DESCRIPTION_MAX_LENGTH ? ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.eventForm.description.error.maxLength", defaultMessage: "ui.eventForm.description.error.maxLength" })) : null }), (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.actions }, { children: (0, jsx_runtime_1.jsx)(lab_1.LoadingButton, Object.assign({ loading: field.isSubmitting, disabled: !field.name ||
333
+ endAdornment: ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2" }, { children: ((_a = field.description) === null || _a === void 0 ? void 0 : _a.length) ? Event_1.EVENT_DESCRIPTION_MAX_LENGTH - field.description.length : Event_1.EVENT_DESCRIPTION_MAX_LENGTH })))
334
+ }, error: Boolean(((_b = field.description) === null || _b === void 0 ? void 0 : _b.length) > Event_1.EVENT_DESCRIPTION_MAX_LENGTH), helperText: ((_c = field.description) === null || _c === void 0 ? void 0 : _c.length) > Event_1.EVENT_DESCRIPTION_MAX_LENGTH ? ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.eventForm.description.error.maxLength", defaultMessage: "ui.eventForm.description.error.maxLength" })) : null }), (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.actions }, { children: (0, jsx_runtime_1.jsx)(lab_1.LoadingButton, Object.assign({ loading: field.isSubmitting, disabled: !field.name ||
328
335
  !field.startDate ||
329
336
  !field.startTime ||
330
337
  !field.endDate ||
@@ -1,5 +1,5 @@
1
1
  export declare const PREFIX = "SCEventForm";
2
- export declare const NEVER_LATER_DAYS = 14;
3
- export declare const DAILY_LATER_DAYS = 60;
4
- export declare const WEEKLY_LATER_DAYS = 360;
5
- export declare const MONTHLY_LATER_DAYS = 730;
2
+ export declare const NEVER_LATER_DAYS = 13;
3
+ export declare const DAILY_LATER_DAYS = 59;
4
+ export declare const WEEKLY_LATER_DAYS = 359;
5
+ export declare const MONTHLY_LATER_DAYS = 729;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MONTHLY_LATER_DAYS = exports.WEEKLY_LATER_DAYS = exports.DAILY_LATER_DAYS = exports.NEVER_LATER_DAYS = exports.PREFIX = void 0;
4
4
  exports.PREFIX = 'SCEventForm';
5
- exports.NEVER_LATER_DAYS = 14;
6
- exports.DAILY_LATER_DAYS = 60;
7
- exports.WEEKLY_LATER_DAYS = 360;
8
- exports.MONTHLY_LATER_DAYS = 730;
5
+ exports.NEVER_LATER_DAYS = 13; // 2 weeks less 1 day
6
+ exports.DAILY_LATER_DAYS = 59; // 60 days less 1 day
7
+ exports.WEEKLY_LATER_DAYS = 359; // 360 days less 1 day
8
+ exports.MONTHLY_LATER_DAYS = 729; // 2 years less 1 day
@@ -1,4 +1,4 @@
1
- export declare function getNewDate(date?: string): Date;
2
- export declare function getLaterHoursDate(h: number): Date;
3
- export declare function getLaterDaysDate(d: number): Date;
1
+ export declare function getNewDate(date?: string | Date): Date;
2
+ export declare function getLaterHoursDate(hours: number, date?: Date): Date;
3
+ export declare function getLaterDaysDate(days: number, date?: Date): Date;
4
4
  export declare const combineDateAndTime: (date: Date, time: Date) => string;
@@ -4,17 +4,20 @@ exports.combineDateAndTime = exports.getLaterDaysDate = exports.getLaterHoursDat
4
4
  const date_fns_1 = require("date-fns");
5
5
  function getNewDate(date) {
6
6
  if (date) {
7
- return new Date(date);
7
+ if (typeof date === 'string') {
8
+ return new Date(date);
9
+ }
10
+ return date;
8
11
  }
9
12
  return new Date();
10
13
  }
11
14
  exports.getNewDate = getNewDate;
12
- function getLaterHoursDate(h) {
13
- return (0, date_fns_1.addHours)(getNewDate(), h);
15
+ function getLaterHoursDate(hours, date) {
16
+ return (0, date_fns_1.addHours)(getNewDate(date), hours);
14
17
  }
15
18
  exports.getLaterHoursDate = getLaterHoursDate;
16
- function getLaterDaysDate(d) {
17
- return (0, date_fns_1.addDays)(getNewDate(), d);
19
+ function getLaterDaysDate(days, date) {
20
+ return (0, date_fns_1.addDays)(getNewDate(date), days);
18
21
  }
19
22
  exports.getLaterDaysDate = getLaterDaysDate;
20
23
  const combineDateAndTime = (date, time) => {
@@ -112,7 +112,7 @@ const Root = styled(Box, {
112
112
  * @param inProps
113
113
  */
114
114
  export default function EventForm(inProps) {
115
- var _a, _b, _c, _d;
115
+ var _a, _b, _c;
116
116
  //PROPS
117
117
  const props = useThemeProps({
118
118
  props: inProps,
@@ -140,7 +140,7 @@ export default function EventForm(inProps) {
140
140
  recurring: (event === null || event === void 0 ? void 0 : event.recurring) || SCEventRecurrenceType.NEVER,
141
141
  name: (event === null || event === void 0 ? void 0 : event.name) || '',
142
142
  description: event ? event.description : '',
143
- isPublic: (_a = (event === null || event === void 0 ? void 0 : event.privacy) === SCEventPrivacyType.PUBLIC) !== null && _a !== void 0 ? _a : true,
143
+ isPublic: (event === null || event === void 0 ? void 0 : event.privacy) === SCEventPrivacyType.PUBLIC || true,
144
144
  isSubmitting: false
145
145
  };
146
146
  // STATE
@@ -225,9 +225,7 @@ export default function EventForm(inProps) {
225
225
  })
226
226
  .catch((e) => {
227
227
  const _error = formatHttpErrorCode(e);
228
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore,@typescript-eslint/ban-ts-comment
229
- // @ts-ignore
230
- if (Object.values(_error)[0].error === 'unique') {
228
+ if (Object.values(_error)[0]['error'] === 'unique') {
231
229
  setError(Object.assign(Object.assign({}, error), { ['nameError']: _jsx(FormattedMessage, { id: "ui.eventForm.name.error.unique", defaultMessage: "ui.eventForm.name.error.unique" }) }));
232
230
  }
233
231
  else {
@@ -237,7 +235,7 @@ export default function EventForm(inProps) {
237
235
  Logger.error(SCOPE_SC_UI, e);
238
236
  onError === null || onError === void 0 ? void 0 : onError(e);
239
237
  });
240
- }, [field, privateEnabled, visibilityEnabled, onSuccess, onError]);
238
+ }, [field, privateEnabled, visibilityEnabled, onSuccess, onError, notifyChanges]);
241
239
  const handleChange = useCallback((event) => {
242
240
  const { name, value } = event.target;
243
241
  setField((prev) => (Object.assign(Object.assign({}, prev), { [name]: value })));
@@ -245,7 +243,7 @@ export default function EventForm(inProps) {
245
243
  delete error[`${name}Error`];
246
244
  setError(error);
247
245
  }
248
- }, [error]);
246
+ }, [setField, error]);
249
247
  const handleChangeDateTime = useCallback((value, name) => {
250
248
  setField((prev) => (Object.assign(Object.assign({}, prev), { [name]: value })));
251
249
  if (error[`${name}Error`]) {
@@ -256,29 +254,26 @@ export default function EventForm(inProps) {
256
254
  delete error['endDateError'];
257
255
  setError(error);
258
256
  }
259
- }, [error]);
260
- const shouldDisabledDate = useCallback((date) => {
257
+ }, [setField, error]);
258
+ const shouldDisableDate = useCallback((date) => {
261
259
  let disabled = false;
262
260
  switch (field.recurring) {
263
261
  case SCEventRecurrenceType.DAILY:
264
- disabled = date.getTime() > getLaterDaysDate(DAILY_LATER_DAYS).getTime();
262
+ disabled = date.getTime() > getLaterDaysDate(DAILY_LATER_DAYS, field.startDate).getTime();
265
263
  break;
266
264
  case SCEventRecurrenceType.WEEKLY:
267
- disabled = date.getTime() > getLaterDaysDate(WEEKLY_LATER_DAYS).getTime();
265
+ disabled = date.getTime() > getLaterDaysDate(WEEKLY_LATER_DAYS, field.startDate).getTime();
268
266
  break;
269
267
  case SCEventRecurrenceType.MONTHLY:
270
- disabled = date.getTime() > getLaterDaysDate(MONTHLY_LATER_DAYS).getTime();
268
+ disabled = date.getTime() > getLaterDaysDate(MONTHLY_LATER_DAYS, field.startDate).getTime();
271
269
  break;
272
270
  case SCEventRecurrenceType.NEVER:
273
271
  default:
274
- disabled = date.getTime() > getLaterDaysDate(NEVER_LATER_DAYS).getTime();
275
- }
276
- if (field.startDate.getDate() > date.getDate()) {
277
- disabled = true;
272
+ disabled = date.getTime() > getLaterDaysDate(NEVER_LATER_DAYS, field.startDate).getTime();
278
273
  }
279
274
  return disabled;
280
275
  }, [field]);
281
- const shouldDisabledTime = useCallback((date, _view) => field.startTime.getTime() > date.getTime(), [field]);
276
+ const shouldDisableTime = useCallback((date) => field.startTime.getTime() > date.getTime(), [field]);
282
277
  /**
283
278
  * Renders root object
284
279
  */
@@ -305,24 +300,36 @@ export default function EventForm(inProps) {
305
300
  return _jsx("em", { children: `${intl.formatMessage(messages.frequencyPlaceholder)}` });
306
301
  }
307
302
  return (_jsx(FormattedMessage, { id: `ui.eventForm.frequency.${selected}.placeholder`, defaultMessage: `ui.eventForm.frequency.${selected}.placeholder` }));
308
- }, startAdornment: _jsx(InputAdornment, Object.assign({ position: "start" }, { children: _jsx(IconButton, { children: _jsx(Icon, { children: "frequency" }) }) })) }, { children: Object.values(SCEventRecurrenceType).map((f) => (_jsx(MenuItem, Object.assign({ value: f }, { children: _jsx(FormattedMessage, { id: `ui.eventForm.frequency.${f}.placeholder`, defaultMessage: `ui.eventForm.frequency.${f}.placeholder` }) }), f))) }))] })), _jsx(Box, Object.assign({ className: classes.dateTime }, { children: _jsxs(LocalizationProvider, Object.assign({ dateAdapter: AdapterDateFns, adapterLocale: scContext.settings.locale.default === 'it' ? itLocale : enLocale }, { children: [_jsx(MobileDatePicker, { className: classes.picker, disablePast: true, minDate: field.startDate, label: _jsx(FormattedMessage, { id: "ui.eventForm.date.end.placeholder", defaultMessage: "ui.eventForm.date.end.placeholder" }), value: field.endDate, slots: {
303
+ }, startAdornment: _jsx(InputAdornment, Object.assign({ position: "start" }, { children: _jsx(IconButton, { children: _jsx(Icon, { children: "frequency" }) }) })) }, { children: Object.values(SCEventRecurrenceType).map((f) => (_jsx(MenuItem, Object.assign({ value: f }, { children: _jsx(FormattedMessage, { id: `ui.eventForm.frequency.${f}.placeholder`, defaultMessage: `ui.eventForm.frequency.${f}.placeholder` }) }), f))) }))] })), _jsx(Box, Object.assign({ className: classes.dateTime }, { children: _jsxs(LocalizationProvider, Object.assign({ dateAdapter: AdapterDateFns, adapterLocale: scContext.settings.locale.default === 'it' ? itLocale : enLocale }, { children: [_jsx(MobileDatePicker, { className: classes.picker, minDate: field.startDate, label: _jsx(FormattedMessage, { id: "ui.eventForm.date.end.placeholder", defaultMessage: "ui.eventForm.date.end.placeholder" }), value: field.endDate, slots: {
309
304
  textField: (params) => (_jsx(TextField, Object.assign({}, params, { InputProps: Object.assign(Object.assign({}, params.InputProps), { placeholder: `${intl.formatMessage(messages.endDate)}`, startAdornment: (_jsx(InputAdornment, Object.assign({ position: "start" }, { children: _jsx(IconButton, { children: _jsx(Icon, { children: "calendar_off" }) }) }))) }) })))
310
- }, onChange: (value) => handleChangeDateTime(value, 'endDate'), shouldDisableDate: shouldDisabledDate }), _jsx(MobileTimePicker, { className: classes.picker, disablePast: disablePastEndTime, label: field.endTime && _jsx(FormattedMessage, { id: "ui.eventForm.time.end.placeholder", defaultMessage: "ui.eventForm.time.end.placeholder" }), value: field.endTime, slots: {
305
+ }, slotProps: {
306
+ toolbar: {
307
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore,@typescript-eslint/ban-ts-comment
308
+ // @ts-ignore
309
+ toolbarTitle: _jsx(FormattedMessage, { id: "ui.eventForm.date.title", defaultMessage: "ui.eventForm.date.title" })
310
+ }
311
+ }, onChange: (value) => handleChangeDateTime(value, 'endDate'), shouldDisableDate: shouldDisableDate }), _jsx(MobileTimePicker, { className: classes.picker, disablePast: disablePastEndTime, label: field.endTime && _jsx(FormattedMessage, { id: "ui.eventForm.time.end.placeholder", defaultMessage: "ui.eventForm.time.end.placeholder" }), value: field.endTime, slots: {
311
312
  textField: (params) => {
312
313
  var _a;
313
314
  return (_jsx(TextField, Object.assign({}, params, { InputProps: Object.assign(Object.assign({}, params.InputProps), { placeholder: `${intl.formatMessage(messages.endTime)}`, startAdornment: (_jsx(InputAdornment, Object.assign({ position: "start" }, { children: _jsx(IconButton, { children: _jsx(Icon, { children: "access_time" }) }) }))) }), error: Boolean(error['endDateError']), helperText: ((_a = error['endDateError']) === null || _a === void 0 ? void 0 : _a.error) ? (_jsx(FormattedMessage, { id: "ui.eventForm.time.end.error.invalid", defaultMessage: "ui.eventForm.time.end.error.invalid" })) : null })));
314
315
  }
315
- }, onChange: (value) => handleChangeDateTime(value, 'endTime'), shouldDisableTime: shouldDisabledTime })] })) })), _jsx(EventAddress, { forwardGeolocationData: handleGeoData, event: event !== null && event !== void 0 ? event : null }), privateEnabled && (_jsxs(Box, Object.assign({ className: classes.privacySection }, { children: [_jsxs(Stack, Object.assign({ direction: "row", spacing: 1, alignItems: "center", justifyContent: "center" }, { children: [_jsxs(Typography, Object.assign({ className: classNames(classes.switchLabel, { [classes.active]: !field.isPublic }) }, { children: [_jsx(Icon, { children: "private" }), _jsx(FormattedMessage, { id: "ui.eventForm.privacy.private", defaultMessage: "ui.eventForm.privacy.private" })] })), _jsx(Switch, { className: classes.switch, checked: field.isPublic, onChange: () => setField((prev) => (Object.assign(Object.assign({}, prev), { ['isPublic']: !field.isPublic }))), disabled: event && !field.isPublic }), _jsxs(Typography, Object.assign({ className: classNames(classes.switchLabel, { [classes.active]: field.isPublic }) }, { children: [_jsx(Icon, { children: "public" }), _jsx(FormattedMessage, { id: "ui.eventForm.privacy.public", defaultMessage: "ui.eventForm.privacy.public" })] }))] })), _jsx(Typography, Object.assign({ variant: "body2", textAlign: "center", className: classes.privacySectionInfo }, { children: field.isPublic ? (_jsx(FormattedMessage, { id: "ui.eventForm.privacy.public.info", defaultMessage: "ui.eventForm.privacy.public.info", values: {
316
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
317
- // @ts-ignore
316
+ }, slotProps: {
317
+ toolbar: {
318
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore,@typescript-eslint/ban-ts-comment
319
+ // @ts-ignore
320
+ toolbarTitle: _jsx(FormattedMessage, { id: "ui.eventForm.time.title", defaultMessage: "ui.eventForm.time.title" })
321
+ }
322
+ }, onChange: (value) => handleChangeDateTime(value, 'endTime'), shouldDisableTime: shouldDisableTime })] })) })), _jsx(EventAddress, { forwardGeolocationData: handleGeoData, event: event !== null && event !== void 0 ? event : null }), privateEnabled && (_jsxs(Box, Object.assign({ className: classes.privacySection }, { children: [_jsxs(Stack, Object.assign({ direction: "row", spacing: 1, alignItems: "center", justifyContent: "center" }, { children: [_jsxs(Typography, Object.assign({ className: classNames(classes.switchLabel, { [classes.active]: !field.isPublic }) }, { children: [_jsx(Icon, { children: "private" }), _jsx(FormattedMessage, { id: "ui.eventForm.privacy.private", defaultMessage: "ui.eventForm.privacy.private" })] })), _jsx(Switch, { className: classes.switch, checked: field.isPublic, onChange: () => setField((prev) => (Object.assign(Object.assign({}, prev), { ['isPublic']: !field.isPublic }))), disabled: event && !field.isPublic }), _jsxs(Typography, Object.assign({ className: classNames(classes.switchLabel, { [classes.active]: field.isPublic }) }, { children: [_jsx(Icon, { children: "public" }), _jsx(FormattedMessage, { id: "ui.eventForm.privacy.public", defaultMessage: "ui.eventForm.privacy.public" })] }))] })), _jsx(Typography, Object.assign({ variant: "body2", textAlign: "center", className: classes.privacySectionInfo }, { children: field.isPublic ? (_jsx(FormattedMessage, { id: "ui.eventForm.privacy.public.info", defaultMessage: "ui.eventForm.privacy.public.info", values: {
323
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore,@typescript-eslint/ban-ts-comment
324
+ // @ts-ignores
318
325
  b: (chunks) => _jsx("strong", { children: chunks })
319
326
  } })) : (_jsx(FormattedMessage, { id: "ui.eventForm.privacy.private.info", defaultMessage: "ui.eventForm.private.public.info", values: {
320
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
327
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore,@typescript-eslint/ban-ts-comment
321
328
  // @ts-ignore
322
329
  b: (chunks) => _jsx("strong", { children: chunks })
323
330
  } })) }))] }))), _jsx(TextField, { multiline: true, className: classes.description, placeholder: `${intl.formatMessage(messages.description)}`, margin: "normal", value: field.description, name: "description", onChange: handleChange, InputProps: {
324
- endAdornment: (_jsx(Typography, Object.assign({ variant: "body2" }, { children: ((_b = field.description) === null || _b === void 0 ? void 0 : _b.length) ? EVENT_DESCRIPTION_MAX_LENGTH - field.description.length : EVENT_DESCRIPTION_MAX_LENGTH })))
325
- }, error: Boolean(((_c = field.description) === null || _c === void 0 ? void 0 : _c.length) > EVENT_DESCRIPTION_MAX_LENGTH), helperText: ((_d = field.description) === null || _d === void 0 ? void 0 : _d.length) > EVENT_DESCRIPTION_MAX_LENGTH ? (_jsx(FormattedMessage, { id: "ui.eventForm.description.error.maxLength", defaultMessage: "ui.eventForm.description.error.maxLength" })) : null }), _jsx(Box, Object.assign({ className: classes.actions }, { children: _jsx(LoadingButton, Object.assign({ loading: field.isSubmitting, disabled: !field.name ||
331
+ endAdornment: (_jsx(Typography, Object.assign({ variant: "body2" }, { children: ((_a = field.description) === null || _a === void 0 ? void 0 : _a.length) ? EVENT_DESCRIPTION_MAX_LENGTH - field.description.length : EVENT_DESCRIPTION_MAX_LENGTH })))
332
+ }, error: Boolean(((_b = field.description) === null || _b === void 0 ? void 0 : _b.length) > EVENT_DESCRIPTION_MAX_LENGTH), helperText: ((_c = field.description) === null || _c === void 0 ? void 0 : _c.length) > EVENT_DESCRIPTION_MAX_LENGTH ? (_jsx(FormattedMessage, { id: "ui.eventForm.description.error.maxLength", defaultMessage: "ui.eventForm.description.error.maxLength" })) : null }), _jsx(Box, Object.assign({ className: classes.actions }, { children: _jsx(LoadingButton, Object.assign({ loading: field.isSubmitting, disabled: !field.name ||
326
333
  !field.startDate ||
327
334
  !field.startTime ||
328
335
  !field.endDate ||
@@ -1,5 +1,5 @@
1
1
  export declare const PREFIX = "SCEventForm";
2
- export declare const NEVER_LATER_DAYS = 14;
3
- export declare const DAILY_LATER_DAYS = 60;
4
- export declare const WEEKLY_LATER_DAYS = 360;
5
- export declare const MONTHLY_LATER_DAYS = 730;
2
+ export declare const NEVER_LATER_DAYS = 13;
3
+ export declare const DAILY_LATER_DAYS = 59;
4
+ export declare const WEEKLY_LATER_DAYS = 359;
5
+ export declare const MONTHLY_LATER_DAYS = 729;
@@ -1,5 +1,5 @@
1
1
  export const PREFIX = 'SCEventForm';
2
- export const NEVER_LATER_DAYS = 14;
3
- export const DAILY_LATER_DAYS = 60;
4
- export const WEEKLY_LATER_DAYS = 360;
5
- export const MONTHLY_LATER_DAYS = 730;
2
+ export const NEVER_LATER_DAYS = 13; // 2 weeks less 1 day
3
+ export const DAILY_LATER_DAYS = 59; // 60 days less 1 day
4
+ export const WEEKLY_LATER_DAYS = 359; // 360 days less 1 day
5
+ export const MONTHLY_LATER_DAYS = 729; // 2 years less 1 day
@@ -1,4 +1,4 @@
1
- export declare function getNewDate(date?: string): Date;
2
- export declare function getLaterHoursDate(h: number): Date;
3
- export declare function getLaterDaysDate(d: number): Date;
1
+ export declare function getNewDate(date?: string | Date): Date;
2
+ export declare function getLaterHoursDate(hours: number, date?: Date): Date;
3
+ export declare function getLaterDaysDate(days: number, date?: Date): Date;
4
4
  export declare const combineDateAndTime: (date: Date, time: Date) => string;
@@ -1,15 +1,18 @@
1
1
  import { addDays, addHours } from 'date-fns';
2
2
  export function getNewDate(date) {
3
3
  if (date) {
4
- return new Date(date);
4
+ if (typeof date === 'string') {
5
+ return new Date(date);
6
+ }
7
+ return date;
5
8
  }
6
9
  return new Date();
7
10
  }
8
- export function getLaterHoursDate(h) {
9
- return addHours(getNewDate(), h);
11
+ export function getLaterHoursDate(hours, date) {
12
+ return addHours(getNewDate(date), hours);
10
13
  }
11
- export function getLaterDaysDate(d) {
12
- return addDays(getNewDate(), d);
14
+ export function getLaterDaysDate(days, date) {
15
+ return addDays(getNewDate(date), days);
13
16
  }
14
17
  export const combineDateAndTime = (date, time) => {
15
18
  const combined = date;