@medplum/react 2.0.12 → 2.0.13

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.
@@ -2671,7 +2671,7 @@
2671
2671
 
2672
2672
  const daysOfWeek = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
2673
2673
  function TimingInput(props) {
2674
- const [value, setValue] = React.useState(props.defaultValue || {});
2674
+ const [value, setValue] = React.useState(props.defaultValue);
2675
2675
  const [open, setOpen] = React.useState(false);
2676
2676
  const valueRef = React.useRef();
2677
2677
  valueRef.current = value;
@@ -2687,8 +2687,14 @@
2687
2687
  setOpen(false);
2688
2688
  }, onCancel: () => setOpen(false) })));
2689
2689
  }
2690
+ const defaultValue = {
2691
+ repeat: {
2692
+ period: 1,
2693
+ periodUnit: 'd',
2694
+ },
2695
+ };
2690
2696
  function TimingEditorDialog(props) {
2691
- const [value, setValue] = React.useState(props.defaultValue || {});
2697
+ const [value, setValue] = React.useState(props.defaultValue || defaultValue);
2692
2698
  const valueRef = React.useRef();
2693
2699
  valueRef.current = value;
2694
2700
  function setStart(newStart) {
@@ -2703,44 +2709,32 @@
2703
2709
  function setPeriodUnit(newPeriodUnit) {
2704
2710
  setRepeat({ ...valueRef.current?.repeat, periodUnit: newPeriodUnit });
2705
2711
  }
2706
- function setDayOfWeek(day, enabled) {
2707
- if (enabled) {
2708
- addDayOfWeek(day);
2709
- }
2710
- else {
2711
- removeDayOfWeek(day);
2712
- }
2713
- }
2714
- function addDayOfWeek(day) {
2715
- const existing = valueRef.current?.repeat?.dayOfWeek || [];
2716
- if (!existing.includes(day)) {
2717
- setRepeat({ ...valueRef.current?.repeat, dayOfWeek: [...existing, day] });
2718
- }
2719
- }
2720
- function removeDayOfWeek(day) {
2721
- const existing = valueRef.current?.repeat?.dayOfWeek || [];
2722
- if (existing.includes(day)) {
2723
- setRepeat({ ...valueRef.current?.repeat, dayOfWeek: existing.filter((d) => d !== day) });
2724
- }
2712
+ function setDaysOfWeek(newDaysOfWeek) {
2713
+ setRepeat({ ...valueRef.current?.repeat, dayOfWeek: newDaysOfWeek });
2725
2714
  }
2726
2715
  return (React.createElement(core$1.Modal, { title: "Timing", closeButtonProps: { 'aria-label': 'Close' }, opened: props.visible, onClose: () => props.onCancel() },
2727
- React.createElement("div", { style: { padding: '5px 20px', textAlign: 'left' } },
2716
+ React.createElement(core$1.Stack, null,
2728
2717
  React.createElement(FormSection, { title: "Starts on", htmlFor: 'timing-dialog-start' },
2729
2718
  React.createElement(DateTimeInput, { name: 'timing-dialog-start', onChange: (newValue) => setStart(newValue) })),
2730
- React.createElement(FormSection, { title: "Repeat every", htmlFor: 'timing-dialog-period' },
2731
- React.createElement(core$1.Group, { spacing: "xs", grow: true, noWrap: true },
2732
- React.createElement(core$1.TextInput, { type: "number", step: 1, id: "timing-dialog-period", name: "timing-dialog-period", defaultValue: value?.repeat?.period, onChange: (e) => setPeriod(parseInt(e.currentTarget.value)) }),
2733
- React.createElement(core$1.NativeSelect, { id: "timing-dialog-periodUnit", name: "timing-dialog-periodUnit", defaultValue: value?.repeat?.periodUnit, onChange: (e) => setPeriodUnit(e.currentTarget.value), data: [
2734
- { label: 'day', value: 'd' },
2735
- { label: 'week', value: 'wk' },
2736
- { label: 'month', value: 'mo' },
2737
- { label: 'year', value: 'a' },
2738
- ] }))),
2739
- React.createElement(FormSection, { title: "Repeat on" },
2740
- React.createElement(core$1.Group, { spacing: "xs", grow: true, noWrap: true }, daysOfWeek.map((day) => (React.createElement(React.Fragment, { key: day },
2741
- React.createElement("label", { htmlFor: 'timing-dialog-repeat-' + day }, day.charAt(0).toUpperCase()),
2742
- React.createElement(core$1.Checkbox, { id: 'timing-dialog-repeat-' + day, name: 'timing-dialog-repeat-' + day, onChange: (e) => setDayOfWeek(day, e.currentTarget.checked) }))))))),
2743
- React.createElement(core$1.Button, { onClick: () => props.onOk(value) }, "OK")));
2719
+ React.createElement(core$1.Switch, { label: "Repeat", checked: !!value.repeat, onChange: (e) => setRepeat(e.currentTarget.checked ? defaultValue.repeat : undefined) }),
2720
+ value.repeat && (React.createElement(React.Fragment, null,
2721
+ React.createElement(FormSection, { title: "Repeat every", htmlFor: 'timing-dialog-period' },
2722
+ React.createElement(core$1.Group, { spacing: "xs", grow: true, noWrap: true },
2723
+ React.createElement(core$1.TextInput, { type: "number", step: 1, id: "timing-dialog-period", name: "timing-dialog-period", defaultValue: value?.repeat?.period || 1, onChange: (e) => setPeriod(parseInt(e.currentTarget.value) || 1) }),
2724
+ React.createElement(core$1.NativeSelect, { id: "timing-dialog-periodUnit", name: "timing-dialog-periodUnit", defaultValue: value?.repeat?.periodUnit, onChange: (e) => setPeriodUnit(e.currentTarget.value), data: [
2725
+ { label: 'second', value: 's' },
2726
+ { label: 'minute', value: 'min' },
2727
+ { label: 'hour', value: 'h' },
2728
+ { label: 'day', value: 'd' },
2729
+ { label: 'week', value: 'wk' },
2730
+ { label: 'month', value: 'mo' },
2731
+ { label: 'year', value: 'a' },
2732
+ ] }))),
2733
+ value.repeat?.periodUnit === 'wk' && (React.createElement(FormSection, { title: "Repeat on" },
2734
+ React.createElement(core$1.Chip.Group, { multiple: true, onChange: setDaysOfWeek },
2735
+ React.createElement(core$1.Group, { position: "apart", mt: "md", spacing: "xs" }, daysOfWeek.map((day) => (React.createElement(core$1.Chip, { key: day, value: day, size: "xs", radius: "xl" }, day.charAt(0).toUpperCase()))))))))),
2736
+ React.createElement(core$1.Group, { position: "right" },
2737
+ React.createElement(core$1.Button, { onClick: () => props.onOk(value) }, "OK")))));
2744
2738
  }
2745
2739
 
2746
2740
  function ResourcePropertyInput(props) {