@jsb188/calendar 1.1.2

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.
@@ -0,0 +1,67 @@
1
+ import { memo } from 'react';
2
+ import { MiniCalendar } from '../modules/MiniCalendar.tsx';
3
+
4
+ const FILE_CONSTANTS = {
5
+ gridStyle: {
6
+ display: 'grid' as const,
7
+ // Three across on a laptop, collapsing to one on a phone,
8
+ // without a media query or a new class
9
+ gridTemplateColumns: 'repeat(auto-fill, minmax(200px, 1fr))',
10
+ gap: 16,
11
+ padding: 16,
12
+ },
13
+ };
14
+
15
+ /**
16
+ * The year view: twelve mini month grids.
17
+ *
18
+ * This is a NAVIGATION surface, not a display one. It deliberately draws no
19
+ * events — a year of shifts is far more than any window query should return,
20
+ * and a grid built from a truncated list would quietly show empty days that
21
+ * are not empty. Clicking a day jumps into it, which is what a year view is
22
+ * actually for.
23
+ *
24
+ * Each month is a <MiniCalendar>, which draws its own grid from a single date.
25
+ * That is the same component the calendar page's sidebar uses, so the two can
26
+ * never drift apart on which day a month starts under.
27
+ */
28
+
29
+ export interface CalendarYearMonthObj {
30
+ // Localized month name
31
+ label: string;
32
+ // Any instant inside the month; the mini grid derives the rest
33
+ monthDate: Date;
34
+ }
35
+
36
+ export interface CalendarYearUIProps {
37
+ months: CalendarYearMonthObj[];
38
+ timeZone?: string | null;
39
+ locale?: string | null;
40
+ weekStartsOn?: number;
41
+ todayDateKey?: string | null;
42
+ onSelectDay: (dateKey: string) => void;
43
+ }
44
+
45
+ export const CalendarYearUI = memo((p: CalendarYearUIProps) => {
46
+ const { months, timeZone, locale, weekStartsOn, todayDateKey, onSelectDay } =
47
+ p;
48
+
49
+ return (
50
+ <div className="f h_0 app_scr auto_y">
51
+ <div style={FILE_CONSTANTS.gridStyle}>
52
+ {months.map((month) => (
53
+ <MiniCalendar
54
+ key={month.label}
55
+ title={month.label}
56
+ monthDate={month.monthDate}
57
+ timeZone={timeZone}
58
+ locale={locale}
59
+ weekStartsOn={weekStartsOn}
60
+ todayDateKey={todayDateKey}
61
+ onSelectDay={onSelectDay}
62
+ />
63
+ ))}
64
+ </div>
65
+ </div>
66
+ );
67
+ });
@@ -0,0 +1,273 @@
1
+ import i18n from '@jsb188/app/i18n/index.ts';
2
+ import { cn } from '@jsb188/app/utils/string.ts';
3
+ import { memo } from 'react';
4
+ import type { RosterLayoutObj } from '../libs/roster-layout.ts';
5
+
6
+ /* Render an accessible people-by-day grid with one row per worker and visible open staffing seats. */
7
+ export const RosterUI = memo(
8
+ (p: {
9
+ layout: RosterLayoutObj;
10
+ editable: boolean;
11
+ narrow?: boolean;
12
+ selectedDay?: string;
13
+ onSelectDay: (dateKey: string) => void;
14
+ onSelectOccurrence: (id: string) => void;
15
+ onCreate: (
16
+ dateKey: string,
17
+ resourceId: string | null,
18
+ roomId: string | null,
19
+ ) => void;
20
+ onReassign?: (
21
+ occurrenceId: string,
22
+ assignmentId: string,
23
+ resourceId: string,
24
+ ) => void;
25
+ onOpenShifts: (roomId: string | null, dateKey: string) => void;
26
+ }) => {
27
+ const indexes = p.narrow
28
+ ? [
29
+ Math.max(
30
+ 0,
31
+ p.layout.days.findIndex((day) => day.dateKey === p.selectedDay),
32
+ ),
33
+ ]
34
+ : p.layout.days.map((_, index) => index);
35
+ return (
36
+ <div className="f h_0 auto_x auto_y app_scr">
37
+ {p.narrow ? (
38
+ <div className="h_item gap_xs p_8">
39
+ {p.layout.days.map((day) => (
40
+ <button
41
+ key={day.dateKey}
42
+ type="button"
43
+ className={cn(
44
+ 'f p_8 r_sm',
45
+ day.dateKey === p.selectedDay ? 'bg_active' : 'bg_alt',
46
+ )}
47
+ onClick={() => p.onSelectDay(day.dateKey)}
48
+ >
49
+ {day.label}
50
+ </button>
51
+ ))}
52
+ </div>
53
+ ) : null}
54
+ <div
55
+ role="grid"
56
+ aria-label={i18n.t('calendar.roster')}
57
+ style={{
58
+ display: 'grid',
59
+ gridTemplateColumns: p.narrow
60
+ ? '114px minmax(160px,1fr) 56px'
61
+ : `200px repeat(${indexes.length},minmax(130px,1fr)) 64px`,
62
+ minWidth: p.narrow ? 0 : 1000,
63
+ }}
64
+ >
65
+ <div className="sticky_top sticky_left bg z3 p_8 ft_bold">
66
+ {i18n.t('schedule.resources')}
67
+ </div>
68
+ {indexes.map((index) => (
69
+ <button
70
+ key={index}
71
+ className="sticky_top bg z2 p_8 bd_b_1 bd_b_bd"
72
+ type="button"
73
+ onClick={() => p.onSelectDay(p.layout.days[index].dateKey)}
74
+ >
75
+ <span className="ft_bold">{p.layout.days[index].label}</span>
76
+ <span
77
+ className={cn(
78
+ 'bl ft_xxs',
79
+ p.layout.days[index].breach === 'BLOCK' ? 'cl_err' : 'cl_md',
80
+ )}
81
+ >
82
+ {i18n.t('calendar.staff_count', {
83
+ count: p.layout.days[index].staffCount,
84
+ })}{' '}
85
+ ·{' '}
86
+ {i18n.t('calendar.open_count', {
87
+ count: p.layout.days[index].openCount,
88
+ })}
89
+ </span>
90
+ </button>
91
+ ))}
92
+ <div
93
+ className="sticky_top bg z2 p_4 ft_xxs"
94
+ style={{ whiteSpace: 'nowrap' }}
95
+ >
96
+ {i18n.t('calendar.hours_week')}
97
+ </div>
98
+ {p.layout.rows.map((row) => (
99
+ <div
100
+ key={row.key}
101
+ role="row"
102
+ style={{ display: 'contents' }}
103
+ >
104
+ <div
105
+ role="rowheader"
106
+ style={{ top: 'auto', bottom: 'auto' }}
107
+ className={cn(
108
+ 'sticky_left bg z1 p_8 bd_b_1 bd_b_bd ellip',
109
+ row.kind === 'GROUP' ? 'ft_bold bg_alt' : 'ft_sm',
110
+ row.breach === 'BLOCK'
111
+ ? 'cl_err'
112
+ : row.breach === 'WARN'
113
+ ? 'cl_warn'
114
+ : '',
115
+ )}
116
+ >
117
+ {row.kind === 'OPEN'
118
+ ? i18n.t('calendar.roster_open_row')
119
+ : row.name || i18n.t('calendar.no_room')}
120
+ </div>
121
+ {indexes.map((index) => {
122
+ const cell = row.cells[index];
123
+ return (
124
+ <div
125
+ key={cell.dateKey}
126
+ role="gridcell"
127
+ onDragOver={(event) => {
128
+ if (p.editable && row.kind === 'PERSON')
129
+ event.preventDefault();
130
+ }}
131
+ onDrop={(event) => {
132
+ event.preventDefault();
133
+ if (!p.editable || !row.resourceId) return;
134
+ try {
135
+ const drag = JSON.parse(
136
+ event.dataTransfer.getData(
137
+ 'application/x-schedule-assignment',
138
+ ),
139
+ );
140
+ if (
141
+ drag.dateKey === cell.dateKey &&
142
+ drag.resourceId !== row.resourceId &&
143
+ typeof drag.occurrenceId === 'string' &&
144
+ typeof drag.assignmentId === 'string'
145
+ )
146
+ p.onReassign?.(
147
+ drag.occurrenceId,
148
+ drag.assignmentId,
149
+ row.resourceId,
150
+ );
151
+ } catch {}
152
+ }}
153
+ className={cn(
154
+ 'p_4 bd_b_1 bd_b_bd bd_l_1 bd_l_bd',
155
+ row.kind === 'GROUP' ? 'bg_alt' : '',
156
+ cell.timeOff?.status === 'APPROVED'
157
+ ? 'bg_alt'
158
+ : cell.timeOff
159
+ ? 'pattern_stripes medium_bf rel'
160
+ : '',
161
+ )}
162
+ style={{ minHeight: 48 }}
163
+ >
164
+ {cell.timeOff ? (
165
+ <span className="bl ft_xxs cl_md">
166
+ {i18n.t('schedule.time_off')}
167
+ </span>
168
+ ) : null}
169
+ {row.kind === 'OPEN' ? (
170
+ cell.openCount > 0 ? (
171
+ <button
172
+ type="button"
173
+ className={cn(
174
+ 'pill p_8',
175
+ cell.breach === 'BLOCK'
176
+ ? 'bg_red_alt_lt'
177
+ : 'bg_amber_alt_lt',
178
+ )}
179
+ onClick={() =>
180
+ p.onOpenShifts(row.roomId, cell.dateKey)
181
+ }
182
+ >
183
+ {i18n.t('calendar.open_count', {
184
+ count: cell.openCount,
185
+ })}
186
+ </button>
187
+ ) : null
188
+ ) : (
189
+ cell.chips.map((chip) => (
190
+ <button
191
+ type="button"
192
+ key={chip.assignmentId || chip.occurrenceId}
193
+ draggable={
194
+ p.editable &&
195
+ !!chip.assignmentId &&
196
+ chip.status !== 'CANCELED'
197
+ }
198
+ onDragStart={(event) => {
199
+ event.dataTransfer.setData(
200
+ 'application/x-schedule-assignment',
201
+ JSON.stringify({
202
+ occurrenceId: chip.occurrenceId,
203
+ assignmentId: chip.assignmentId,
204
+ resourceId: row.resourceId,
205
+ dateKey: cell.dateKey,
206
+ }),
207
+ );
208
+ event.dataTransfer.effectAllowed = 'move';
209
+ }}
210
+ className={cn(
211
+ 'bl w_f a_l r_sm px_4 py_2 ft_xxs bd_1 bd_bd',
212
+ chip.status === 'DRAFT'
213
+ ? 'pattern_stripes medium_bf rel'
214
+ : '',
215
+ chip.status === 'CANCELED'
216
+ ? 'strikethrough op_50'
217
+ : '',
218
+ chip.isMine ? 'bg_active' : 'bg_alt',
219
+ chip.breach === 'BLOCK'
220
+ ? 'bd_red_md'
221
+ : chip.breach === 'WARN'
222
+ ? 'bd_amber_md'
223
+ : '',
224
+ )}
225
+ onClick={() =>
226
+ p.onSelectOccurrence(chip.occurrenceId)
227
+ }
228
+ >
229
+ <span className="bl ellip ft_bold">{chip.title}</span>
230
+ <span>
231
+ {chip.startLabel}–{chip.endLabel}
232
+ {chip.overnight ? ' →' : ''}
233
+ </span>
234
+ {chip.roomName ? (
235
+ <span className="bl ellip cl_md">
236
+ {chip.roomName}
237
+ </span>
238
+ ) : null}
239
+ </button>
240
+ ))
241
+ )}
242
+ {row.kind === 'PERSON' &&
243
+ p.editable &&
244
+ !cell.chips.length ? (
245
+ <button
246
+ type="button"
247
+ className="w_f p_8 cl_lt"
248
+ aria-label={i18n.t('calendar.new_shift')}
249
+ onClick={() =>
250
+ p.onCreate(cell.dateKey, row.resourceId, row.roomId)
251
+ }
252
+ >
253
+ +
254
+ </button>
255
+ ) : null}
256
+ </div>
257
+ );
258
+ })}
259
+ <div
260
+ className={cn(
261
+ 'p_8 bd_b_1 bd_b_bd ft_xxs',
262
+ row.kind === 'GROUP' ? 'bg_alt' : '',
263
+ )}
264
+ >
265
+ {row.kind === 'PERSON' ? (row.weekMinutes / 60).toFixed(1) : ''}
266
+ </div>
267
+ </div>
268
+ ))}
269
+ </div>
270
+ </div>
271
+ );
272
+ },
273
+ );
@@ -0,0 +1,333 @@
1
+ import i18n from '@jsb188/app/i18n/index.ts';
2
+ import type { ScheduleResourceGQL } from '@jsb188/graphql/schedule.d';
3
+ import type { ShiftFormValues } from '../types/shift-form.d.ts';
4
+ import { memo } from 'react';
5
+
6
+ /* Render a local-time shift editor with structured slots and a bounded recurrence form. */
7
+ export const ShiftFormUI = memo(
8
+ (p: {
9
+ values: ShiftFormValues;
10
+ rooms: ScheduleResourceGQL[];
11
+ existing: boolean;
12
+ series: boolean;
13
+ busy: boolean;
14
+ error: string | null;
15
+ onChange: (values: ShiftFormValues) => void;
16
+ onSave: () => void;
17
+ }) => {
18
+ const v = p.values;
19
+ /* Change one controlled form value without mutating the caller's draft. */
20
+ const change = (key: keyof ShiftFormValues, value: unknown) =>
21
+ p.onChange({ ...v, [key]: value });
22
+ return (
23
+ <form
24
+ className="v_stretch gap_sm p_12"
25
+ onSubmit={(event) => {
26
+ event.preventDefault();
27
+ p.onSave();
28
+ }}
29
+ >
30
+ {!p.existing ? (
31
+ <label>
32
+ {i18n.t('calendar.kind_' + v.kind)}
33
+ <select
34
+ className="bl w_f p_8 bd_1 bd_bd r_sm"
35
+ value={v.kind}
36
+ onChange={(e) => change('kind', e.target.value)}
37
+ >
38
+ {['SHIFT', 'EVENT', 'BLOCK'].map((kind) => (
39
+ <option
40
+ key={kind}
41
+ value={kind}
42
+ >
43
+ {i18n.t('calendar.kind_' + kind)}
44
+ </option>
45
+ ))}
46
+ </select>
47
+ </label>
48
+ ) : null}
49
+ <label>
50
+ {i18n.t('calendar.title')}
51
+ <input
52
+ required
53
+ className="bl w_f p_8 bd_1 bd_bd r_sm"
54
+ value={v.title}
55
+ onChange={(e) => change('title', e.target.value)}
56
+ />
57
+ </label>
58
+ <label>
59
+ {i18n.t('calendar.room')}
60
+ <select
61
+ className="bl w_f p_8 bd_1 bd_bd r_sm"
62
+ value={v.roomId}
63
+ onChange={(e) => change('roomId', e.target.value)}
64
+ >
65
+ <option value="">{i18n.t('calendar.no_room')}</option>
66
+ {p.rooms.map((room) => (
67
+ <option
68
+ key={room.id}
69
+ value={room.id}
70
+ >
71
+ {room.name}
72
+ </option>
73
+ ))}
74
+ </select>
75
+ </label>
76
+ {(['start', 'end'] as const).map((key) => (
77
+ <label key={key}>
78
+ {i18n.t('calendar.' + key)}
79
+ <input
80
+ required
81
+ type="datetime-local"
82
+ className="bl w_f p_8 bd_1 bd_bd r_sm"
83
+ value={v[key]}
84
+ onChange={(e) => change(key, e.target.value)}
85
+ />
86
+ </label>
87
+ ))}
88
+ {v.kind !== 'SHIFT' ? (
89
+ <label>
90
+ <input
91
+ type="checkbox"
92
+ checked={v.allDay}
93
+ onChange={(e) => change('allDay', e.target.checked)}
94
+ />{' '}
95
+ {i18n.t('calendar.all_day')}
96
+ </label>
97
+ ) : null}
98
+ {(['location', 'note'] as const).map((key) => (
99
+ <label key={key}>
100
+ {i18n.t('calendar.' + key)}
101
+ <input
102
+ className="bl w_f p_8 bd_1 bd_bd r_sm"
103
+ value={v[key]}
104
+ onChange={(e) => change(key, e.target.value)}
105
+ />
106
+ </label>
107
+ ))}
108
+ {v.kind === 'SHIFT' ? (
109
+ <fieldset className="v_stretch gap_sm">
110
+ <legend>{i18n.t('calendar.slots')}</legend>
111
+ {v.slots.map((slot, index) => (
112
+ <div
113
+ className="v_stretch gap_xs bd_1 bd_bd p_8 r_sm"
114
+ key={slot.key}
115
+ >
116
+ <label>
117
+ {i18n.t('calendar.slot_label')}
118
+ <input
119
+ className="w_f p_4 bd_1 bd_bd"
120
+ value={slot.label || ''}
121
+ onChange={(e) =>
122
+ change(
123
+ 'slots',
124
+ v.slots.map((row, i) =>
125
+ i === index ? { ...row, label: e.target.value } : row,
126
+ ),
127
+ )
128
+ }
129
+ />
130
+ </label>
131
+ <label>
132
+ {i18n.t('calendar.required_count')}
133
+ <input
134
+ type="number"
135
+ min="1"
136
+ max="500"
137
+ className="w_f p_4 bd_1 bd_bd"
138
+ value={slot.requiredCount}
139
+ onChange={(e) =>
140
+ change(
141
+ 'slots',
142
+ v.slots.map((row, i) =>
143
+ i === index
144
+ ? { ...row, requiredCount: Number(e.target.value) }
145
+ : row,
146
+ ),
147
+ )
148
+ }
149
+ />
150
+ </label>
151
+ {(['roles', 'qualifications', 'tags'] as const).map((key) => (
152
+ <label key={key}>
153
+ {i18n.t('calendar.predicate_' + key)}
154
+ <input
155
+ className="w_f p_4 bd_1 bd_bd"
156
+ defaultValue={slot.predicate?.[key]?.join(', ') || ''}
157
+ onBlur={(e) =>
158
+ change(
159
+ 'slots',
160
+ v.slots.map((row, i) =>
161
+ i === index
162
+ ? {
163
+ ...row,
164
+ predicate: {
165
+ ...row.predicate,
166
+ [key]: e.target.value
167
+ .split(',')
168
+ .map((part) => part.trim())
169
+ .filter(Boolean),
170
+ },
171
+ }
172
+ : row,
173
+ ),
174
+ )
175
+ }
176
+ />
177
+ </label>
178
+ ))}
179
+ <button
180
+ type="button"
181
+ className="cl_err a_l p_4"
182
+ onClick={() =>
183
+ change(
184
+ 'slots',
185
+ v.slots.filter((_, i) => i !== index),
186
+ )
187
+ }
188
+ >
189
+ {i18n.t('calendar.remove')}
190
+ </button>
191
+ </div>
192
+ ))}
193
+ <button
194
+ type="button"
195
+ className="p_8 bg_alt r_sm"
196
+ onClick={() => {
197
+ let n = v.slots.length + 1;
198
+ while (v.slots.some((slot) => slot.key === `S${n}`)) n++;
199
+ change('slots', [
200
+ ...v.slots,
201
+ {
202
+ key: `S${n}`,
203
+ label: '',
204
+ requiredCount: 1,
205
+ predicate: { roles: [], qualifications: [], tags: [] },
206
+ ordinal: v.slots.length,
207
+ },
208
+ ]);
209
+ }}
210
+ >
211
+ {i18n.t('calendar.add_slot')}
212
+ </button>
213
+ </fieldset>
214
+ ) : null}
215
+ {!p.existing ? (
216
+ <>
217
+ <label>
218
+ {i18n.t('calendar.repeat')}
219
+ <select
220
+ className="bl w_f p_8 bd_1 bd_bd"
221
+ value={v.repeat}
222
+ onChange={(e) => change('repeat', e.target.value)}
223
+ >
224
+ <option value="">{i18n.t('calendar.none')}</option>
225
+ {['DAILY', 'WEEKLY', 'MONTHLY'].map((freq) => (
226
+ <option
227
+ key={freq}
228
+ value={freq}
229
+ >
230
+ {i18n.t('calendar.repeat_' + freq)}
231
+ </option>
232
+ ))}
233
+ </select>
234
+ </label>
235
+ {v.repeat ? (
236
+ <>
237
+ <label>
238
+ {i18n.t('calendar.interval')}
239
+ <input
240
+ type="number"
241
+ min="1"
242
+ max="365"
243
+ value={v.interval}
244
+ onChange={(e) => change('interval', Number(e.target.value))}
245
+ />
246
+ </label>
247
+ {v.repeat === 'WEEKLY' ? (
248
+ <div className="h_item f_wrap gap_sm">
249
+ {Array.from({ length: 7 }, (_, day) => (
250
+ <label key={day}>
251
+ <input
252
+ type="checkbox"
253
+ checked={v.weekdays.includes(day)}
254
+ onChange={(e) =>
255
+ change(
256
+ 'weekdays',
257
+ e.target.checked
258
+ ? [...v.weekdays, day]
259
+ : v.weekdays.filter((value) => value !== day),
260
+ )
261
+ }
262
+ />
263
+ {new Intl.DateTimeFormat(undefined, {
264
+ weekday: 'short',
265
+ timeZone: 'UTC',
266
+ }).format(new Date(Date.UTC(2026, 0, 4 + day)))}
267
+ </label>
268
+ ))}
269
+ </div>
270
+ ) : null}
271
+ {v.repeat === 'MONTHLY' ? (
272
+ <label>
273
+ {i18n.t('calendar.month_day')}
274
+ <input
275
+ type="number"
276
+ min="1"
277
+ max="31"
278
+ value={v.monthDay}
279
+ onChange={(e) =>
280
+ change('monthDay', Number(e.target.value))
281
+ }
282
+ />
283
+ </label>
284
+ ) : null}
285
+ <label>
286
+ {i18n.t('calendar.repeat_count')}
287
+ <input
288
+ type="number"
289
+ min="1"
290
+ value={v.count}
291
+ onChange={(e) => change('count', e.target.value)}
292
+ />
293
+ </label>
294
+ <label>
295
+ {i18n.t('calendar.repeat_until')}
296
+ <input
297
+ type="date"
298
+ value={v.until}
299
+ onChange={(e) => change('until', e.target.value)}
300
+ />
301
+ </label>
302
+ </>
303
+ ) : null}
304
+ </>
305
+ ) : null}
306
+ {p.series ? (
307
+ <label>
308
+ <input
309
+ type="checkbox"
310
+ checked={v.future}
311
+ onChange={(e) => change('future', e.target.checked)}
312
+ />{' '}
313
+ {i18n.t('calendar.series_this_and_future')}
314
+ </label>
315
+ ) : null}
316
+ {p.error ? (
317
+ <p
318
+ role="alert"
319
+ className="cl_err ft_sm"
320
+ >
321
+ {p.error}
322
+ </p>
323
+ ) : null}
324
+ <button
325
+ className="p_12 bg_primary cl_white r_sm"
326
+ disabled={p.busy}
327
+ >
328
+ {i18n.t('calendar.save')}
329
+ </button>
330
+ </form>
331
+ );
332
+ },
333
+ );