@jsb188/calendar 1.1.10 → 1.1.12
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.
- package/package.json +16 -15
- package/src/constants/calendar.ts +17 -3
- package/src/libs/calendar-geometry.ts +165 -91
- package/src/libs/calendar-gesture.ts +58 -15
- package/src/libs/calendar-now.ts +39 -0
- package/src/libs/calendar-range.ts +88 -27
- package/src/libs/calendar-state.ts +21 -156
- package/src/libs/calendar-url.ts +55 -8
- package/src/libs/roster-layout.ts +388 -0
- package/src/main.ts +3 -0
- package/src/modules/Calendar.tsx +375 -287
- package/src/modules/MiniCalendar.tsx +376 -0
- package/src/types/calendar.d.ts +7 -1
- package/src/types/shift-form.d.ts +19 -0
- package/src/ui/CalendarAgendaUI.tsx +43 -14
- package/src/ui/CalendarMonthUI.tsx +38 -26
- package/src/ui/CalendarToolbarUI.tsx +50 -27
- package/src/ui/CalendarUI.tsx +280 -226
- package/src/ui/CalendarYearUI.tsx +36 -50
- package/src/ui/RosterUI.tsx +273 -0
- package/src/ui/ShiftFormUI.tsx +333 -0
- package/tests/calendar-geometry.test.ts +230 -84
- package/tests/calendar-gesture.test.ts +43 -12
- package/tests/calendar-range.test.ts +159 -33
- package/tests/calendar-url.test.ts +77 -12
- package/tests/roster-layout.test.ts +210 -0
- package/src/ui/CalendarCoverageUI.tsx +0 -199
- package/src/ui/CalendarEventDetailUI.tsx +0 -260
- package/src/ui/CalendarEventFormUI.tsx +0 -239
- package/src/ui/CalendarRailUI.tsx +0 -282
- package/src/ui/CalendarRequestUI.tsx +0 -537
- package/src/ui/CalendarViolationUI.tsx +0 -207
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import { cn } from '@jsb188/app/utils/string.ts';
|
|
2
|
-
import { memo } from 'react';
|
|
3
|
-
import { CALENDAR_DRAFT_PATTERN_CLASS_NAME } from '../constants/calendar.ts';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* The coverage board.
|
|
7
|
-
*
|
|
8
|
-
* A manager staffing a week does not want a list of shifts, they want the one
|
|
9
|
-
* question answered everywhere at once: where am I short? So this is a matrix
|
|
10
|
-
* — resources down, time buckets across — and every cell says the same two
|
|
11
|
-
* numbers, "how many are on" over "how many are needed".
|
|
12
|
-
*
|
|
13
|
-
* Three things it deliberately does NOT do:
|
|
14
|
-
*
|
|
15
|
-
* - **It does not compute anything.** Buckets, counts, shortfalls, severities
|
|
16
|
-
* and every label arrive as props. The same board draws an hour-by-hour day
|
|
17
|
-
* and a day-by-day month purely by being handed different buckets.
|
|
18
|
-
*
|
|
19
|
-
* - **It does not hide a fully-staffed cell.** A blank grid with a few red
|
|
20
|
-
* squares reads as "loading"; a full grid with a few red squares reads as
|
|
21
|
-
* "checked, and here is the problem".
|
|
22
|
-
*
|
|
23
|
-
* - **It does not fold draft into published.** Unpublished coverage is drawn
|
|
24
|
-
* with the same stripe pattern the grid uses for draft entries, so nobody
|
|
25
|
-
* counts staff who have not actually been told they are working.
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* One column: a slice of the visible window.
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
export interface CalendarCoverageBucketObj {
|
|
33
|
-
key: string;
|
|
34
|
-
// Localized column heading, e.g. "8a" or "Mon"
|
|
35
|
-
label: string;
|
|
36
|
-
// Optional second heading line, e.g. the date under the weekday
|
|
37
|
-
subLabel?: string | null;
|
|
38
|
-
// Outside the operating window — drawn dimmer, because being "short" in a
|
|
39
|
-
// bucket nobody operates in is not a fact worth alarming anyone with
|
|
40
|
-
isMuted?: boolean;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* One resource × one bucket.
|
|
45
|
-
*/
|
|
46
|
-
|
|
47
|
-
export interface CalendarCoverageCellObj {
|
|
48
|
-
key: string;
|
|
49
|
-
bucketKey: string;
|
|
50
|
-
required: number;
|
|
51
|
-
actual: number;
|
|
52
|
-
// Nothing at all is scheduled here; drawn blank rather than as "0/0"
|
|
53
|
-
isEmpty?: boolean;
|
|
54
|
-
// Every occurrence behind this cell is still unpublished
|
|
55
|
-
isDraft?: boolean;
|
|
56
|
-
// The violation strip's entry this cell belongs to, when there is one
|
|
57
|
-
violationKey?: string | null;
|
|
58
|
-
// BLOCK | WARN | null — decides red versus amber when the cell is short
|
|
59
|
-
severity?: string | null;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* One row: a room, a position, a vehicle — whatever this calendar staffs.
|
|
64
|
-
*/
|
|
65
|
-
|
|
66
|
-
export interface CalendarCoverageRowObj {
|
|
67
|
-
resourceId: string;
|
|
68
|
-
name: string;
|
|
69
|
-
// Optional second line under the name, e.g. a location or a capacity
|
|
70
|
-
subName?: string | null;
|
|
71
|
-
// Aligned index-for-index with `buckets`
|
|
72
|
-
cells: CalendarCoverageCellObj[];
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export interface CalendarCoverageUIProps {
|
|
76
|
-
rows: CalendarCoverageRowObj[];
|
|
77
|
-
buckets: CalendarCoverageBucketObj[];
|
|
78
|
-
// Heading of the left-hand column, e.g. "Resource"
|
|
79
|
-
resourceHeaderText: string;
|
|
80
|
-
emptyText: string;
|
|
81
|
-
// Formats a cell, e.g. "2/3". The package holds no copy, so even the
|
|
82
|
-
// separator is the caller's decision
|
|
83
|
-
countText: (actual: number, required: number) => string;
|
|
84
|
-
// Geometry, in px. The caller sizes the board to its container and to how
|
|
85
|
-
// many buckets the window produced
|
|
86
|
-
resourceColumnWidth?: number;
|
|
87
|
-
bucketWidth?: number;
|
|
88
|
-
rowHeight?: number;
|
|
89
|
-
// Highlights every cell belonging to the violation the strip has selected
|
|
90
|
-
selectedViolationKey?: string | null;
|
|
91
|
-
onSelectCell?: (resourceId: string, cell: CalendarCoverageCellObj) => void;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export const CalendarCoverageUI = memo((p: CalendarCoverageUIProps) => {
|
|
95
|
-
const {
|
|
96
|
-
rows,
|
|
97
|
-
buckets,
|
|
98
|
-
resourceHeaderText,
|
|
99
|
-
emptyText,
|
|
100
|
-
countText,
|
|
101
|
-
resourceColumnWidth = 168,
|
|
102
|
-
bucketWidth = 56,
|
|
103
|
-
rowHeight = 34,
|
|
104
|
-
selectedViolationKey,
|
|
105
|
-
onSelectCell,
|
|
106
|
-
} = p;
|
|
107
|
-
|
|
108
|
-
if (!rows.length || !buckets.length) {
|
|
109
|
-
return (
|
|
110
|
-
<div className='f h_0 v_center a_c'>
|
|
111
|
-
<span className='ft_sm cl_lt'>{emptyText}</span>
|
|
112
|
-
</div>
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// The board is wider than its container by design; the scroller needs a
|
|
117
|
-
// real width to scroll to, and both sticky edges hang off it
|
|
118
|
-
const boardWidth = resourceColumnWidth + (buckets.length * bucketWidth);
|
|
119
|
-
|
|
120
|
-
return (
|
|
121
|
-
<div className='f h_0 w_f app_scr of_x auto_x auto_y'>
|
|
122
|
-
<div className='v_stretch' style={{ width: boardWidth }}>
|
|
123
|
-
<div
|
|
124
|
-
className='no_shrink h_item sticky bg bd_b_1 bd_b_bd'
|
|
125
|
-
style={{ top: 0, zIndex: 30 }}
|
|
126
|
-
>
|
|
127
|
-
<div
|
|
128
|
-
className='no_shrink v_stretch sticky bg ellip bd_r_1 bd_r_bd'
|
|
129
|
-
style={{ left: 0, width: resourceColumnWidth, zIndex: 20, paddingLeft: 8 }}
|
|
130
|
-
>
|
|
131
|
-
<span className='ellip ft_tn cl_lt'>{resourceHeaderText}</span>
|
|
132
|
-
</div>
|
|
133
|
-
|
|
134
|
-
{buckets.map((bucket) => (
|
|
135
|
-
<div
|
|
136
|
-
key={bucket.key}
|
|
137
|
-
className={cn('no_shrink v_stretch a_c of', bucket.isMuted ? 'bg_alt' : '')}
|
|
138
|
-
style={{ width: bucketWidth, paddingTop: 3, paddingBottom: 3 }}
|
|
139
|
-
>
|
|
140
|
-
<span className={cn('ellip ft_tn', bucket.isMuted ? 'cl_lt' : 'cl_md')}>
|
|
141
|
-
{bucket.label}
|
|
142
|
-
</span>
|
|
143
|
-
|
|
144
|
-
{bucket.subLabel ? <span className='ellip ft_tn cl_lt'>{bucket.subLabel}</span> : null}
|
|
145
|
-
</div>
|
|
146
|
-
))}
|
|
147
|
-
</div>
|
|
148
|
-
|
|
149
|
-
{rows.map((row) => (
|
|
150
|
-
<div key={row.resourceId} className='no_shrink h_item bd_b_1 bd_b_bd' style={{ height: rowHeight }}>
|
|
151
|
-
<div
|
|
152
|
-
className='no_shrink v_center h_f sticky bg of bd_r_1 bd_r_bd'
|
|
153
|
-
style={{ left: 0, width: resourceColumnWidth, zIndex: 20, paddingLeft: 8, paddingRight: 6 }}
|
|
154
|
-
>
|
|
155
|
-
<span className='w_f ellip ft_tn'>{row.name}</span>
|
|
156
|
-
|
|
157
|
-
{row.subName ? <span className='w_f ellip ft_tn cl_lt'>{row.subName}</span> : null}
|
|
158
|
-
</div>
|
|
159
|
-
|
|
160
|
-
{row.cells.map((cell) => {
|
|
161
|
-
// Short is short whatever the engine called it; the
|
|
162
|
-
// severity only decides how loudly it is said
|
|
163
|
-
const isShort = !cell.isEmpty && cell.actual < cell.required;
|
|
164
|
-
const isBlocking = isShort && cell.severity === 'BLOCK';
|
|
165
|
-
const isSelected = !!selectedViolationKey && cell.violationKey === selectedViolationKey;
|
|
166
|
-
|
|
167
|
-
return (
|
|
168
|
-
<button
|
|
169
|
-
key={cell.key}
|
|
170
|
-
type='button'
|
|
171
|
-
className={cn(
|
|
172
|
-
'no_shrink h_center h_f rel bd_l_1 bd_l_bd',
|
|
173
|
-
isBlocking ? 'bg_red_alt_lt' : isShort ? 'bg_amber_alt_lt' : '',
|
|
174
|
-
// The stripe needs a relative parent and a colour
|
|
175
|
-
// for its overlay; `medium_bf` is the neutral one
|
|
176
|
-
cell.isDraft ? `${CALENDAR_DRAFT_PATTERN_CLASS_NAME} medium_bf` : '',
|
|
177
|
-
isSelected ? 'ol_primary' : '',
|
|
178
|
-
)}
|
|
179
|
-
style={{ width: bucketWidth }}
|
|
180
|
-
onClick={onSelectCell ? () => onSelectCell(row.resourceId, cell) : undefined}
|
|
181
|
-
>
|
|
182
|
-
{/* Positioned so it paints above the stripe overlay */}
|
|
183
|
-
<span
|
|
184
|
-
className={cn(
|
|
185
|
-
'rel ellip ft_tn',
|
|
186
|
-
isBlocking ? 'cl_err ft_bold' : isShort ? 'cl_warn ft_bold' : 'cl_md',
|
|
187
|
-
)}
|
|
188
|
-
>
|
|
189
|
-
{cell.isEmpty ? '' : countText(cell.actual, cell.required)}
|
|
190
|
-
</span>
|
|
191
|
-
</button>
|
|
192
|
-
);
|
|
193
|
-
})}
|
|
194
|
-
</div>
|
|
195
|
-
))}
|
|
196
|
-
</div>
|
|
197
|
-
</div>
|
|
198
|
-
);
|
|
199
|
-
});
|
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
import { cn } from '@jsb188/app/utils/string.ts';
|
|
2
|
-
import { AvatarImg } from '@jsb188/react-web/ui/Avatar';
|
|
3
|
-
import { Button, SimpleLabel } from '@jsb188/react-web/ui/Button';
|
|
4
|
-
import { Icon } from '@jsb188/react-web/svgs/Icon';
|
|
5
|
-
import { memo } from 'react';
|
|
6
|
-
import { CALENDAR_DRAFT_PATTERN_CLASS_NAME } from '../constants/calendar.ts';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* The bubble that opens when one occurrence is selected.
|
|
10
|
-
*
|
|
11
|
-
* Everything arrives already formatted — no Date, no zone, no plural rules
|
|
12
|
-
* cross this boundary. The grid and this bubble must agree about what "9:00 AM
|
|
13
|
-
* – 5:00 PM" means, and the only way to guarantee that is for one place to do
|
|
14
|
-
* the formatting and both to render the same string.
|
|
15
|
-
*
|
|
16
|
-
* Actions are opt-in: a button appears only when its handler was passed. That
|
|
17
|
-
* is what lets the same bubble serve a manager (edit, cancel, delete) and a
|
|
18
|
-
* worker (give away this shift) without either of them being handed a control
|
|
19
|
-
* that would fail on the server.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
export interface CalendarEventDetailUIProps {
|
|
23
|
-
className?: string;
|
|
24
|
-
title: string;
|
|
25
|
-
// e.g. "Wed, Jul 22 · 9:00 AM – 5:00 PM", or the all-day wording
|
|
26
|
-
timeRangeText: string;
|
|
27
|
-
// DRAFT | PUBLISHED | CANCELED — drives the strike-through and the stripes
|
|
28
|
-
status: string;
|
|
29
|
-
statusText: string;
|
|
30
|
-
// A ColorEnum name; SimpleLabel only honors this on its outline preset
|
|
31
|
-
statusColor?: string | null;
|
|
32
|
-
location?: string | null;
|
|
33
|
-
note?: string | null;
|
|
34
|
-
// Display names, already resolved from the assignee account ids
|
|
35
|
-
assigneeNames: string[];
|
|
36
|
-
// Rendered only when there are open slots left, e.g. "2 spots open"
|
|
37
|
-
openCountText?: string | null;
|
|
38
|
-
closeText: string;
|
|
39
|
-
editText: string;
|
|
40
|
-
cancelOccurrenceText: string;
|
|
41
|
-
deleteText: string;
|
|
42
|
-
releaseText: string;
|
|
43
|
-
// Surfaced under the actions when the last mutation failed
|
|
44
|
-
errorText?: string | null;
|
|
45
|
-
// Disables every action while a mutation is in flight
|
|
46
|
-
busy?: boolean;
|
|
47
|
-
onEdit?: () => void;
|
|
48
|
-
onCancelOccurrence?: () => void;
|
|
49
|
-
onDelete?: () => void;
|
|
50
|
-
// "Give away this shift" — opens a release request rather than unassigning
|
|
51
|
-
onRelease?: () => void;
|
|
52
|
-
onClose: () => void;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* One labelled line inside the bubble: an icon in a fixed gutter, the value
|
|
57
|
-
* beside it. The caller decides whether a row exists at all, so an occurrence
|
|
58
|
-
* with no location leaves no empty line behind.
|
|
59
|
-
*/
|
|
60
|
-
|
|
61
|
-
function CalendarEventDetailRow(p: { iconName: string; children: React.ReactNode }) {
|
|
62
|
-
const { iconName, children } = p;
|
|
63
|
-
|
|
64
|
-
return (
|
|
65
|
-
<div className='h_item gap_sm' style={{ paddingTop: 3, paddingBottom: 3 }}>
|
|
66
|
-
<span className='no_shrink cl_lt h_center' style={{ width: 18 }}>
|
|
67
|
-
<Icon name={iconName} />
|
|
68
|
-
</span>
|
|
69
|
-
|
|
70
|
-
<span className='f ft_sm cl_df'>{children}</span>
|
|
71
|
-
</div>
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export const CalendarEventDetailUI = memo((p: CalendarEventDetailUIProps) => {
|
|
76
|
-
const {
|
|
77
|
-
className,
|
|
78
|
-
title,
|
|
79
|
-
timeRangeText,
|
|
80
|
-
status,
|
|
81
|
-
statusText,
|
|
82
|
-
statusColor,
|
|
83
|
-
location,
|
|
84
|
-
note,
|
|
85
|
-
assigneeNames,
|
|
86
|
-
openCountText,
|
|
87
|
-
closeText,
|
|
88
|
-
editText,
|
|
89
|
-
cancelOccurrenceText,
|
|
90
|
-
deleteText,
|
|
91
|
-
releaseText,
|
|
92
|
-
errorText,
|
|
93
|
-
busy,
|
|
94
|
-
onEdit,
|
|
95
|
-
onCancelOccurrence,
|
|
96
|
-
onDelete,
|
|
97
|
-
onRelease,
|
|
98
|
-
onClose,
|
|
99
|
-
} = p;
|
|
100
|
-
|
|
101
|
-
const hasActions = !!(onEdit || onCancelOccurrence || onDelete || onRelease);
|
|
102
|
-
|
|
103
|
-
return (
|
|
104
|
-
<div className={cn('bg bd_1 bd_bd r_df of', className)}>
|
|
105
|
-
<div
|
|
106
|
-
className='h_item gap_sm bd_b_1 bd_b_bd'
|
|
107
|
-
style={{ paddingLeft: 12, paddingRight: 8, paddingTop: 8, paddingBottom: 8 }}
|
|
108
|
-
>
|
|
109
|
-
<span
|
|
110
|
-
className={cn(
|
|
111
|
-
'f ft_md ft_bold ellip',
|
|
112
|
-
status === 'CANCELED' ? 'strikethrough cl_lt' : '',
|
|
113
|
-
)}
|
|
114
|
-
>
|
|
115
|
-
{title}
|
|
116
|
-
</span>
|
|
117
|
-
|
|
118
|
-
<SimpleLabel
|
|
119
|
-
className='no_shrink'
|
|
120
|
-
preset='outline'
|
|
121
|
-
color={statusColor || 'medium'}
|
|
122
|
-
text={statusText}
|
|
123
|
-
/>
|
|
124
|
-
|
|
125
|
-
{/* No IconButton exists in the kit, so this is the documented raw
|
|
126
|
-
pattern: a bare button wrapping an Icon */}
|
|
127
|
-
<button
|
|
128
|
-
type='button'
|
|
129
|
-
className='av_sm h_center no_shrink cl_lt'
|
|
130
|
-
aria-label={closeText}
|
|
131
|
-
title={closeText}
|
|
132
|
-
onClick={onClose}
|
|
133
|
-
>
|
|
134
|
-
<Icon name='x' />
|
|
135
|
-
</button>
|
|
136
|
-
</div>
|
|
137
|
-
|
|
138
|
-
<div style={{ paddingLeft: 12, paddingRight: 12, paddingTop: 8, paddingBottom: 8 }}>
|
|
139
|
-
<CalendarEventDetailRow iconName='clock-hour-4'>
|
|
140
|
-
<span className={cn(status === 'DRAFT' ? CALENDAR_DRAFT_PATTERN_CLASS_NAME : '')}>
|
|
141
|
-
{timeRangeText}
|
|
142
|
-
</span>
|
|
143
|
-
</CalendarEventDetailRow>
|
|
144
|
-
|
|
145
|
-
{location
|
|
146
|
-
? (
|
|
147
|
-
<CalendarEventDetailRow iconName='pin-location-1'>
|
|
148
|
-
{location}
|
|
149
|
-
</CalendarEventDetailRow>
|
|
150
|
-
)
|
|
151
|
-
: null}
|
|
152
|
-
|
|
153
|
-
{assigneeNames.length
|
|
154
|
-
? (
|
|
155
|
-
<CalendarEventDetailRow iconName='multiple-neutral-circle'>
|
|
156
|
-
{/* Wrapping is structural here: the chip count is data, so the
|
|
157
|
-
row has to be able to run onto a second line */}
|
|
158
|
-
<span className='h_item gap_sm' style={{ flexWrap: 'wrap' }}>
|
|
159
|
-
{assigneeNames.map((name) => (
|
|
160
|
-
<span key={name} className='h_item gap_xs no_shrink'>
|
|
161
|
-
<AvatarImg size='tiny' displayName={name} />
|
|
162
|
-
<span className='ellip'>{name}</span>
|
|
163
|
-
</span>
|
|
164
|
-
))}
|
|
165
|
-
</span>
|
|
166
|
-
</CalendarEventDetailRow>
|
|
167
|
-
)
|
|
168
|
-
: null}
|
|
169
|
-
|
|
170
|
-
{openCountText
|
|
171
|
-
? (
|
|
172
|
-
<CalendarEventDetailRow iconName='single-neutral-actions-add'>
|
|
173
|
-
<span className='cl_md'>{openCountText}</span>
|
|
174
|
-
</CalendarEventDetailRow>
|
|
175
|
-
)
|
|
176
|
-
: null}
|
|
177
|
-
|
|
178
|
-
{note
|
|
179
|
-
? (
|
|
180
|
-
<CalendarEventDetailRow iconName='notes-paper-text'>
|
|
181
|
-
<span className='cl_md'>{note}</span>
|
|
182
|
-
</CalendarEventDetailRow>
|
|
183
|
-
)
|
|
184
|
-
: null}
|
|
185
|
-
</div>
|
|
186
|
-
|
|
187
|
-
{errorText
|
|
188
|
-
? (
|
|
189
|
-
<div
|
|
190
|
-
className='ft_xs cl_err'
|
|
191
|
-
style={{ paddingLeft: 12, paddingRight: 12, paddingBottom: 8 }}
|
|
192
|
-
>
|
|
193
|
-
{errorText}
|
|
194
|
-
</div>
|
|
195
|
-
)
|
|
196
|
-
: null}
|
|
197
|
-
|
|
198
|
-
{hasActions
|
|
199
|
-
? (
|
|
200
|
-
<div
|
|
201
|
-
className='h_item gap_sm bd_t_1 bd_t_bd'
|
|
202
|
-
style={{ paddingLeft: 8, paddingRight: 8, paddingTop: 8, paddingBottom: 8, flexWrap: 'wrap' }}
|
|
203
|
-
>
|
|
204
|
-
{onEdit
|
|
205
|
-
? (
|
|
206
|
-
<Button
|
|
207
|
-
preset='bg_secondary'
|
|
208
|
-
size='sm'
|
|
209
|
-
disabled={busy}
|
|
210
|
-
leftIconName='pencil-write-2'
|
|
211
|
-
text={editText}
|
|
212
|
-
onClick={onEdit}
|
|
213
|
-
/>
|
|
214
|
-
)
|
|
215
|
-
: null}
|
|
216
|
-
|
|
217
|
-
{onRelease
|
|
218
|
-
? (
|
|
219
|
-
<Button
|
|
220
|
-
preset='bg'
|
|
221
|
-
size='sm'
|
|
222
|
-
disabled={busy}
|
|
223
|
-
leftIconName='switch-account-1'
|
|
224
|
-
text={releaseText}
|
|
225
|
-
onClick={onRelease}
|
|
226
|
-
/>
|
|
227
|
-
)
|
|
228
|
-
: null}
|
|
229
|
-
|
|
230
|
-
{onCancelOccurrence
|
|
231
|
-
? (
|
|
232
|
-
<Button
|
|
233
|
-
preset='outline_subtle'
|
|
234
|
-
size='sm'
|
|
235
|
-
disabled={busy}
|
|
236
|
-
leftIconName='cancel'
|
|
237
|
-
text={cancelOccurrenceText}
|
|
238
|
-
onClick={onCancelOccurrence}
|
|
239
|
-
/>
|
|
240
|
-
)
|
|
241
|
-
: null}
|
|
242
|
-
|
|
243
|
-
{onDelete
|
|
244
|
-
? (
|
|
245
|
-
<Button
|
|
246
|
-
preset='cl_err'
|
|
247
|
-
size='sm'
|
|
248
|
-
disabled={busy}
|
|
249
|
-
leftIconName='bin'
|
|
250
|
-
text={deleteText}
|
|
251
|
-
onClick={onDelete}
|
|
252
|
-
/>
|
|
253
|
-
)
|
|
254
|
-
: null}
|
|
255
|
-
</div>
|
|
256
|
-
)
|
|
257
|
-
: null}
|
|
258
|
-
</div>
|
|
259
|
-
);
|
|
260
|
-
});
|
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
import { cn } from '@jsb188/app/utils/string.ts';
|
|
2
|
-
import { Input, Textarea } from '@jsb188/react-web/modules/Form';
|
|
3
|
-
import { Button } from '@jsb188/react-web/ui/Button';
|
|
4
|
-
import { ToggleSwitch } from '@jsb188/react-web/ui/Form';
|
|
5
|
-
import { memo } from 'react';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* The create / edit form for one occurrence.
|
|
9
|
-
*
|
|
10
|
-
* Fully controlled: every keystroke leaves through onChangeValue and comes
|
|
11
|
-
* back as a prop. The form owns no draft of its own, because the same draft
|
|
12
|
-
* has to survive the bubble closing, a drag on the grid moving the block, and
|
|
13
|
-
* the modal being reopened — none of which this component can see.
|
|
14
|
-
*
|
|
15
|
-
* Dates and times are kept as the browser's own wire formats ("yyyy-MM-dd" and
|
|
16
|
-
* "HH:mm") rather than as Date objects. There is no datetime picker in the UI
|
|
17
|
-
* kit, so these are native date/time inputs, and native inputs speak those two
|
|
18
|
-
* strings; keeping the props in the same shape means nothing here has to parse
|
|
19
|
-
* or re-serialize, and the zone stays the caller's problem — which is correct,
|
|
20
|
-
* since only the caller knows the calendar's display zone.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
export interface CalendarEventFormValuesObj {
|
|
24
|
-
title: string;
|
|
25
|
-
allDay: boolean;
|
|
26
|
-
// "yyyy-MM-dd", the value an <input type='date'> reads and writes
|
|
27
|
-
startDate: string;
|
|
28
|
-
// "HH:mm" in 24-hour time, the value an <input type='time'> reads and writes
|
|
29
|
-
startTime: string;
|
|
30
|
-
endDate: string;
|
|
31
|
-
endTime: string;
|
|
32
|
-
location: string;
|
|
33
|
-
note: string;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export type CalendarEventFormFieldEnum = keyof CalendarEventFormValuesObj;
|
|
37
|
-
|
|
38
|
-
export interface CalendarEventFormUIProps {
|
|
39
|
-
className?: string;
|
|
40
|
-
values: CalendarEventFormValuesObj;
|
|
41
|
-
headingText: string;
|
|
42
|
-
titleLabel: string;
|
|
43
|
-
titlePlaceholder: string;
|
|
44
|
-
allDayText: string;
|
|
45
|
-
startLabel: string;
|
|
46
|
-
endLabel: string;
|
|
47
|
-
locationLabel: string;
|
|
48
|
-
locationPlaceholder: string;
|
|
49
|
-
noteLabel: string;
|
|
50
|
-
notePlaceholder: string;
|
|
51
|
-
saveText: string;
|
|
52
|
-
// Swapped in for saveText while a save is in flight, if the caller has one
|
|
53
|
-
savingText?: string;
|
|
54
|
-
cancelText: string;
|
|
55
|
-
// Validation or mutation failure, already worded by the caller
|
|
56
|
-
errorText?: string | null;
|
|
57
|
-
saving?: boolean;
|
|
58
|
-
// Lets the caller veto a save the form cannot see is wrong — an end before
|
|
59
|
-
// its start, a slot that violates a rule
|
|
60
|
-
disableSave?: boolean;
|
|
61
|
-
onChangeValue: (field: CalendarEventFormFieldEnum, value: string | boolean) => void;
|
|
62
|
-
onSubmit: () => void;
|
|
63
|
-
onCancel: () => void;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export const CalendarEventFormUI = memo((p: CalendarEventFormUIProps) => {
|
|
67
|
-
const {
|
|
68
|
-
className,
|
|
69
|
-
values,
|
|
70
|
-
headingText,
|
|
71
|
-
titleLabel,
|
|
72
|
-
titlePlaceholder,
|
|
73
|
-
allDayText,
|
|
74
|
-
startLabel,
|
|
75
|
-
endLabel,
|
|
76
|
-
locationLabel,
|
|
77
|
-
locationPlaceholder,
|
|
78
|
-
noteLabel,
|
|
79
|
-
notePlaceholder,
|
|
80
|
-
saveText,
|
|
81
|
-
savingText,
|
|
82
|
-
cancelText,
|
|
83
|
-
errorText,
|
|
84
|
-
saving,
|
|
85
|
-
disableSave,
|
|
86
|
-
onChangeValue,
|
|
87
|
-
onSubmit,
|
|
88
|
-
onCancel,
|
|
89
|
-
} = p;
|
|
90
|
-
|
|
91
|
-
// An untitled occurrence is unreadable on the grid, so it is the one rule
|
|
92
|
-
// the form enforces by itself; everything else is the caller's to judge
|
|
93
|
-
const saveDisabled = !!saving || !!disableSave || !values.title.trim();
|
|
94
|
-
|
|
95
|
-
return (
|
|
96
|
-
<div className={cn('v_stretch of', className)}>
|
|
97
|
-
<div
|
|
98
|
-
className='no_shrink ft_md ft_bold bd_b_1 bd_b_bd'
|
|
99
|
-
style={{ paddingLeft: 12, paddingRight: 12, paddingTop: 8, paddingBottom: 8 }}
|
|
100
|
-
>
|
|
101
|
-
{headingText}
|
|
102
|
-
</div>
|
|
103
|
-
|
|
104
|
-
<div
|
|
105
|
-
className='f h_0 app_scr auto_y'
|
|
106
|
-
style={{ paddingLeft: 12, paddingRight: 12, paddingTop: 8, paddingBottom: 8 }}
|
|
107
|
-
>
|
|
108
|
-
<Input
|
|
109
|
-
fullWidth
|
|
110
|
-
autoFocus
|
|
111
|
-
preset='fill'
|
|
112
|
-
name='title'
|
|
113
|
-
label={titleLabel}
|
|
114
|
-
placeholder={titlePlaceholder}
|
|
115
|
-
disabled={saving}
|
|
116
|
-
value={values.title}
|
|
117
|
-
onChange={(e) => onChangeValue('title', e.currentTarget.value)}
|
|
118
|
-
/>
|
|
119
|
-
|
|
120
|
-
<label className='h_item gap_sm pointer unsel' style={{ paddingTop: 10, paddingBottom: 6 }}>
|
|
121
|
-
<ToggleSwitch
|
|
122
|
-
size='sm'
|
|
123
|
-
disabled={saving}
|
|
124
|
-
checked={values.allDay}
|
|
125
|
-
onChange={(e) => onChangeValue('allDay', e.currentTarget.checked)}
|
|
126
|
-
/>
|
|
127
|
-
<span className='ft_sm'>{allDayText}</span>
|
|
128
|
-
</label>
|
|
129
|
-
|
|
130
|
-
{/* The kit has no datetime control, so a row is a native date input
|
|
131
|
-
plus a native time input; the time half disappears for an all-day
|
|
132
|
-
entry rather than being disabled, because there is no time to edit */}
|
|
133
|
-
<div className='h_item gap_sm' style={{ paddingTop: 4, paddingBottom: 4 }}>
|
|
134
|
-
<Input
|
|
135
|
-
fullWidth
|
|
136
|
-
className='f'
|
|
137
|
-
preset='fill'
|
|
138
|
-
type='date'
|
|
139
|
-
name='startDate'
|
|
140
|
-
label={startLabel}
|
|
141
|
-
disabled={saving}
|
|
142
|
-
value={values.startDate}
|
|
143
|
-
onChange={(e) => onChangeValue('startDate', e.currentTarget.value)}
|
|
144
|
-
/>
|
|
145
|
-
|
|
146
|
-
{values.allDay
|
|
147
|
-
? null
|
|
148
|
-
: (
|
|
149
|
-
<Input
|
|
150
|
-
className='no_shrink'
|
|
151
|
-
preset='fill'
|
|
152
|
-
type='time'
|
|
153
|
-
name='startTime'
|
|
154
|
-
disabled={saving}
|
|
155
|
-
value={values.startTime}
|
|
156
|
-
onChange={(e) => onChangeValue('startTime', e.currentTarget.value)}
|
|
157
|
-
/>
|
|
158
|
-
)}
|
|
159
|
-
</div>
|
|
160
|
-
|
|
161
|
-
<div className='h_item gap_sm' style={{ paddingTop: 4, paddingBottom: 4 }}>
|
|
162
|
-
<Input
|
|
163
|
-
fullWidth
|
|
164
|
-
className='f'
|
|
165
|
-
preset='fill'
|
|
166
|
-
type='date'
|
|
167
|
-
name='endDate'
|
|
168
|
-
label={endLabel}
|
|
169
|
-
disabled={saving}
|
|
170
|
-
value={values.endDate}
|
|
171
|
-
onChange={(e) => onChangeValue('endDate', e.currentTarget.value)}
|
|
172
|
-
/>
|
|
173
|
-
|
|
174
|
-
{values.allDay
|
|
175
|
-
? null
|
|
176
|
-
: (
|
|
177
|
-
<Input
|
|
178
|
-
className='no_shrink'
|
|
179
|
-
preset='fill'
|
|
180
|
-
type='time'
|
|
181
|
-
name='endTime'
|
|
182
|
-
disabled={saving}
|
|
183
|
-
value={values.endTime}
|
|
184
|
-
onChange={(e) => onChangeValue('endTime', e.currentTarget.value)}
|
|
185
|
-
/>
|
|
186
|
-
)}
|
|
187
|
-
</div>
|
|
188
|
-
|
|
189
|
-
<Input
|
|
190
|
-
fullWidth
|
|
191
|
-
className='mt_xs'
|
|
192
|
-
preset='fill'
|
|
193
|
-
name='location'
|
|
194
|
-
label={locationLabel}
|
|
195
|
-
placeholder={locationPlaceholder}
|
|
196
|
-
disabled={saving}
|
|
197
|
-
value={values.location}
|
|
198
|
-
onChange={(e) => onChangeValue('location', e.currentTarget.value)}
|
|
199
|
-
/>
|
|
200
|
-
|
|
201
|
-
<Textarea
|
|
202
|
-
fullWidth
|
|
203
|
-
className='mt_xs'
|
|
204
|
-
preset='fill'
|
|
205
|
-
name='note'
|
|
206
|
-
label={noteLabel}
|
|
207
|
-
placeholder={notePlaceholder}
|
|
208
|
-
minHeight={80}
|
|
209
|
-
disabled={saving}
|
|
210
|
-
value={values.note}
|
|
211
|
-
onChange={(e) => onChangeValue('note', e.currentTarget.value)}
|
|
212
|
-
/>
|
|
213
|
-
|
|
214
|
-
{errorText ? <div className='ft_xs cl_err mt_xs'>{errorText}</div> : null}
|
|
215
|
-
</div>
|
|
216
|
-
|
|
217
|
-
<div
|
|
218
|
-
className='no_shrink h_right gap_sm bd_t_1 bd_t_bd'
|
|
219
|
-
style={{ paddingLeft: 12, paddingRight: 12, paddingTop: 8, paddingBottom: 8 }}
|
|
220
|
-
>
|
|
221
|
-
<Button
|
|
222
|
-
preset='bg'
|
|
223
|
-
size='sm'
|
|
224
|
-
disabled={saving}
|
|
225
|
-
text={cancelText}
|
|
226
|
-
onClick={onCancel}
|
|
227
|
-
/>
|
|
228
|
-
|
|
229
|
-
<Button
|
|
230
|
-
preset='bg_secondary'
|
|
231
|
-
size='sm'
|
|
232
|
-
disabled={saveDisabled}
|
|
233
|
-
text={saving && savingText ? savingText : saveText}
|
|
234
|
-
onClick={onSubmit}
|
|
235
|
-
/>
|
|
236
|
-
</div>
|
|
237
|
-
</div>
|
|
238
|
-
);
|
|
239
|
-
});
|