@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.
@@ -1,537 +0,0 @@
1
- import { cn } from '@jsb188/app/utils/string.ts';
2
- import { Input } from '@jsb188/react-web/modules/Form';
3
- import { TooltipClickToCopy } from '@jsb188/react-web/modules/PopOver';
4
- import { Icon } from '@jsb188/react-web/svgs/Icon';
5
- import { AvatarImg } from '@jsb188/react-web/ui/Avatar';
6
- import { Button, SimpleLabel } from '@jsb188/react-web/ui/Button';
7
- import { memo } from 'react';
8
-
9
- /**
10
- * The request surfaces: claiming an open shift, deciding somebody else's
11
- * request, and subscribing a calendar app to a feed.
12
- *
13
- * All three are stateless. Every string is a prop and every value arrives
14
- * already formatted, because this package has no copy and no locale: the page
15
- * owns both, and that is what keeps the same board usable for a daycare and a
16
- * packhouse without either one leaking into the other.
17
- *
18
- * The one idea worth stating out loud is how losing a claim is drawn. Open
19
- * shifts are first-come-first-claim, so two people pressing Claim within the
20
- * same second is the system working, not failing. The loser gets "Taken" as a
21
- * neutral label on a dimmed row — the same treatment a filled shift would
22
- * get — and never an error. A red banner would teach people that racing is
23
- * dangerous, and the whole point of the board is that it is not.
24
- */
25
-
26
- // Which button on a queue row is waiting on the server
27
- export type CalendarRequestDecisionEnum = 'APPROVE' | 'DENY';
28
-
29
- /**
30
- * The shared empty state. No empty-state component exists in the kit, so this
31
- * is the app's inline pattern (a textured panel behind a centered card) kept
32
- * in one place rather than pasted into all three lists.
33
- */
34
-
35
- const CalendarRequestEmpty = memo((p: { text: string }) => {
36
- return (
37
- <div className='pattern_texture main_bf px_md py_lg rel v_center r_sm of'>
38
- <p className='rel z2 bg r px_25 py_sm cl_lt a_c ft_sm'>
39
- {p.text}
40
- </p>
41
- </div>
42
- );
43
- });
44
-
45
- /**
46
- * One claimable shift. Every label is pre-composed by the page so this file
47
- * never joins two translated strings together.
48
- */
49
-
50
- export interface CalendarOpenShiftObj {
51
- id: string;
52
- title: string;
53
- // The whole range on one line, e.g. "Wed, Jul 22 · 8:00 AM – 4:00 PM"
54
- timeLabel: string;
55
- // Who gave the shift up, e.g. "Released by Dana"; null when it was never
56
- // assigned to anybody and the shift is simply short-staffed
57
- releasedByLabel?: string | null;
58
- releasedByPhotoUri?: string | null;
59
- releasedByName?: string | null;
60
- // How many people are still needed, e.g. "2 needed"
61
- openCountLabel?: string | null;
62
- location?: string | null;
63
- // Somebody else won the race. Ordinary news, not an error
64
- taken?: boolean;
65
- // Who won, e.g. "Claimed by Sam" — optional, because the server may not
66
- // tell a worker who beat them
67
- takenLabel?: string | null;
68
- }
69
-
70
- export interface CalendarOpenShiftsUIProps {
71
- shifts: CalendarOpenShiftObj[];
72
- // The shift whose claim is in flight. One at a time: while this is set
73
- // every other Claim button goes inert, which is what stops a double press
74
- // from opening two requests
75
- pendingShiftId?: string | null;
76
- claimText: string;
77
- claimingText: string;
78
- takenText: string;
79
- emptyText: string;
80
- className?: string;
81
- onClaim: (shiftId: string) => void;
82
- }
83
-
84
- /**
85
- * The open-shift board.
86
- *
87
- * A flat list of shifts anybody may take. Taken rows stay in place rather than
88
- * disappearing: a row vanishing under somebody's cursor is how a person ends
89
- * up clicking the wrong thing, and seeing "Taken" is also the answer to "did
90
- * my click do anything?".
91
- */
92
-
93
- export const CalendarOpenShiftsUI = memo((p: CalendarOpenShiftsUIProps) => {
94
- const { shifts, pendingShiftId, claimText, claimingText, takenText, emptyText, className, onClaim } = p;
95
-
96
- if (!shifts.length) {
97
- return (
98
- <div className={cn('p_df', className)}>
99
- <CalendarRequestEmpty text={emptyText} />
100
- </div>
101
- );
102
- }
103
-
104
- return (
105
- <div className={cn('f h_0 app_scr auto_y', className)}>
106
- {shifts.map((shift) => {
107
- const isPending = pendingShiftId === shift.id;
108
- const isTaken = !!shift.taken;
109
-
110
- return (
111
- <div
112
- key={shift.id}
113
- className={cn('h_item gap_sm bd_t_1 bd_t_bd', isTaken ? 'op_50' : '')}
114
- style={{ paddingLeft: 12, paddingRight: 12, paddingTop: 8, paddingBottom: 8 }}
115
- >
116
- <div className='f h_0'>
117
- <div className='h_item gap_xs'>
118
- <span className='ellip ft_sm ft_bold'>{shift.title}</span>
119
-
120
- {!shift.openCountLabel ? null : (
121
- <SimpleLabel
122
- preset='outline'
123
- color='medium'
124
- text={shift.openCountLabel}
125
- />
126
- )}
127
- </div>
128
-
129
- <div className='ft_tn cl_lt ellip'>{shift.timeLabel}</div>
130
-
131
- {!shift.location ? null : (
132
- <div className='ft_tn cl_lt ellip'>{shift.location}</div>
133
- )}
134
-
135
- {!shift.releasedByLabel ? null : (
136
- <div className='h_item gap_xs ft_tn cl_lt'>
137
- <AvatarImg
138
- square
139
- size='xtiny'
140
- displayName={shift.releasedByName || ''}
141
- urlPath={shift.releasedByPhotoUri || undefined}
142
- />
143
- <span className='ellip'>{shift.releasedByLabel}</span>
144
- </div>
145
- )}
146
- </div>
147
-
148
- {isTaken
149
- ? (
150
- <div className='no_shrink a_r'>
151
- <SimpleLabel
152
- preset='outline'
153
- color='medium'
154
- text={takenText}
155
- />
156
-
157
- {!shift.takenLabel ? null : (
158
- <div className='ft_tn cl_lt ellip'>{shift.takenLabel}</div>
159
- )}
160
- </div>
161
- )
162
- : (
163
- <Button
164
- className='no_shrink'
165
- preset='bg_primary'
166
- size='sm'
167
- // Any claim in flight freezes the whole board, so a
168
- // second press cannot open a second request
169
- disabled={!!pendingShiftId}
170
- text={isPending ? claimingText : claimText}
171
- onClick={() => onClaim(shift.id)}
172
- />
173
- )}
174
- </div>
175
- );
176
- })}
177
- </div>
178
- );
179
- });
180
-
181
- /**
182
- * One request waiting on a manager. `kind` stays the raw enum so the row can
183
- * be styled or filtered by it; `kindLabel` is what a person reads.
184
- */
185
-
186
- export interface CalendarRequestRowObj {
187
- id: string;
188
- // RELEASE | SWAP | CLAIM | TIME_OFF
189
- kind: string;
190
- // The translated word for the kind, e.g. "Swap"
191
- kindLabel: string;
192
- // A color name the kit understands, e.g. 'blue'; falls back to neutral
193
- kindColor?: string | null;
194
- requesterName: string;
195
- requesterPhotoUri?: string | null;
196
- // The shift the request is about. Null for a TIME_OFF request that covers
197
- // a stretch of days rather than one assignment
198
- shiftTitle?: string | null;
199
- // The whole range on one line, formatted by the page
200
- timeLabel?: string | null;
201
- reason?: string | null;
202
- // e.g. "Requested 2 hours ago"
203
- submittedLabel?: string | null;
204
- }
205
-
206
- export interface CalendarApprovalQueueUIProps {
207
- requests: CalendarRequestRowObj[];
208
- // The request whose decision is in flight, and which button is waiting
209
- pendingRequestId?: string | null;
210
- pendingDecision?: CalendarRequestDecisionEnum | null;
211
- approveText: string;
212
- approvingText: string;
213
- denyText: string;
214
- denyingText: string;
215
- // The manager's note, keyed by request. Pass `onChangeNote` to turn the
216
- // note input on at all — a queue that does not collect notes should not
217
- // draw an input nobody reads
218
- noteByRequestId?: Map<string, string>;
219
- notePlaceholder?: string;
220
- emptyText: string;
221
- className?: string;
222
- onApprove: (requestId: string) => void;
223
- onDeny: (requestId: string) => void;
224
- onChangeNote?: (requestId: string, value: string) => void;
225
- }
226
-
227
- /**
228
- * The manager's approval queue.
229
- *
230
- * Each row carries everything a decision needs — who asked, for what, when,
231
- * and why — so approving does not require opening anything. Both buttons stay
232
- * mounted while a decision is in flight and only the pressed one changes its
233
- * word, so the row does not reflow under the pointer mid-click.
234
- */
235
-
236
- export const CalendarApprovalQueueUI = memo((p: CalendarApprovalQueueUIProps) => {
237
- const {
238
- requests,
239
- pendingRequestId,
240
- pendingDecision,
241
- approveText,
242
- approvingText,
243
- denyText,
244
- denyingText,
245
- noteByRequestId,
246
- notePlaceholder,
247
- emptyText,
248
- className,
249
- onApprove,
250
- onDeny,
251
- onChangeNote,
252
- } = p;
253
-
254
- if (!requests.length) {
255
- return (
256
- <div className={cn('p_df', className)}>
257
- <CalendarRequestEmpty text={emptyText} />
258
- </div>
259
- );
260
- }
261
-
262
- return (
263
- <div className={cn('f h_0 app_scr auto_y', className)}>
264
- {requests.map((request) => {
265
- const isPending = pendingRequestId === request.id;
266
- const isApproving = isPending && pendingDecision === 'APPROVE';
267
- const isDenying = isPending && pendingDecision === 'DENY';
268
-
269
- return (
270
- <div
271
- key={request.id}
272
- className={cn('bd_t_1 bd_t_bd', isPending ? 'op_50' : '')}
273
- style={{ paddingLeft: 12, paddingRight: 12, paddingTop: 8, paddingBottom: 8 }}
274
- >
275
- <div className='h_item gap_sm'>
276
- <div className='f h_0'>
277
- <div className='h_item gap_xs'>
278
- <SimpleLabel
279
- preset='outline'
280
- color={request.kindColor || 'medium'}
281
- text={request.kindLabel}
282
- />
283
-
284
- <AvatarImg
285
- square
286
- size='xtiny'
287
- displayName={request.requesterName}
288
- urlPath={request.requesterPhotoUri || undefined}
289
- />
290
-
291
- <span className='ellip ft_sm ft_bold'>{request.requesterName}</span>
292
- </div>
293
-
294
- {!request.shiftTitle ? null : (
295
- <div className='ft_sm ellip'>{request.shiftTitle}</div>
296
- )}
297
-
298
- {!request.timeLabel ? null : (
299
- <div className='ft_tn cl_lt ellip'>{request.timeLabel}</div>
300
- )}
301
-
302
- {!request.reason ? null : (
303
- <div className='ft_tn cl_md pre_wrap'>{request.reason}</div>
304
- )}
305
-
306
- {!request.submittedLabel ? null : (
307
- <div className='ft_tn cl_lt ellip'>{request.submittedLabel}</div>
308
- )}
309
- </div>
310
-
311
- <div className='no_shrink h_item gap_xs'>
312
- <Button
313
- preset='bg_primary'
314
- size='sm'
315
- disabled={isPending}
316
- text={isApproving ? approvingText : approveText}
317
- onClick={() => onApprove(request.id)}
318
- />
319
-
320
- <Button
321
- preset='outline'
322
- size='sm'
323
- disabled={isPending}
324
- text={isDenying ? denyingText : denyText}
325
- onClick={() => onDeny(request.id)}
326
- />
327
- </div>
328
- </div>
329
-
330
- {!onChangeNote ? null : (
331
- <Input
332
- fullWidth
333
- className='mt_sm ft_tn'
334
- preset='subtle'
335
- name={`schedule_request_note_${request.id}`}
336
- placeholder={notePlaceholder}
337
- disabled={isPending}
338
- value={noteByRequestId?.get(request.id) || ''}
339
- onInput={(e) => onChangeNote(request.id, (e.currentTarget as HTMLInputElement).value)}
340
- />
341
- )}
342
- </div>
343
- );
344
- })}
345
- </div>
346
- );
347
- });
348
-
349
- /**
350
- * One live subscription. There is no token here on purpose: the server stores
351
- * only a hash, so an existing row genuinely cannot show one.
352
- */
353
-
354
- export interface CalendarSubscriptionObj {
355
- id: string;
356
- // What the subscription covers, e.g. the calendar's name
357
- name: string;
358
- // MINE or CALENDAR, already turned into a word
359
- scopeLabel: string;
360
- createdLabel?: string | null;
361
- // e.g. "Last synced 20 minutes ago"; null when no calendar app has fetched
362
- // it yet, which is the usual sign a paste went wrong
363
- lastFetchedLabel?: string | null;
364
- }
365
-
366
- /**
367
- * A subscription that was just created. The URL carries the only copy of the
368
- * token that will ever exist outside the subscriber's calendar app.
369
- */
370
-
371
- export interface CalendarIssuedSubscriptionObj {
372
- id: string;
373
- // The full feed URL with the token already in it, ready to paste
374
- url: string;
375
- }
376
-
377
- export interface CalendarSubscribeUIProps {
378
- subscriptions: CalendarSubscriptionObj[];
379
- // Set for exactly as long as the page holds the freshly issued URL in
380
- // memory. Clearing it is what makes "shown once" true
381
- issued?: CalendarIssuedSubscriptionObj | null;
382
- issuedTitleText: string;
383
- // Must say plainly that the URL cannot be recovered
384
- issuedWarningText: string;
385
- copyText: string;
386
- doneText: string;
387
- createText: string;
388
- creatingText: string;
389
- creating?: boolean;
390
- revokeText: string;
391
- revokingText: string;
392
- pendingRevokeId?: string | null;
393
- emptyText: string;
394
- className?: string;
395
- onCreate: () => void;
396
- onRevoke: (subscriptionId: string) => void;
397
- onDismissIssued: () => void;
398
- }
399
-
400
- /**
401
- * The ICS subscription panel.
402
- *
403
- * A subscription is a bearer URL, so the whole surface is built around the one
404
- * moment it exists in readable form: the issued block is loud, sits above
405
- * everything, carries its own warning, and does not go away on its own —
406
- * dismissing it is a deliberate act, because the page cannot get the URL back
407
- * and neither can the server.
408
- */
409
-
410
- export const CalendarSubscribeUI = memo((p: CalendarSubscribeUIProps) => {
411
- const {
412
- subscriptions,
413
- issued,
414
- issuedTitleText,
415
- issuedWarningText,
416
- copyText,
417
- doneText,
418
- createText,
419
- creatingText,
420
- creating,
421
- revokeText,
422
- revokingText,
423
- pendingRevokeId,
424
- emptyText,
425
- className,
426
- onCreate,
427
- onRevoke,
428
- onDismissIssued,
429
- } = p;
430
-
431
- return (
432
- <div className={cn('f h_0 app_scr auto_y', className)}>
433
- {!issued ? null : (
434
- <div
435
- className='bg_alt r_sm bd_1 bd_bd'
436
- style={{ margin: 12, padding: 12 }}
437
- >
438
- <div className='h_item gap_xs ft_sm ft_bold'>
439
- <Icon name='alert-circle' />
440
- <span className='f ellip'>{issuedTitleText}</span>
441
- </div>
442
-
443
- <p className='ft_tn cl_err mt_sm'>{issuedWarningText}</p>
444
-
445
- {/* A <div> already breaks long unbroken strings globally, which is
446
- what lets the whole token stay visible instead of clipping */}
447
- <div
448
- className='bg r_xs bd_1 bd_bd ft_tn mt_sm'
449
- style={{ padding: 8 }}
450
- >
451
- {issued.url}
452
- </div>
453
-
454
- <div className='h_item gap_xs mt_sm'>
455
- {/* TooltipClickToCopy owns the clipboard write and its own
456
- "copied" feedback, so nothing about it needs page state */}
457
- <TooltipClickToCopy
458
- className='h_item gap_xs ft_tn link'
459
- position='top'
460
- textToCopy={issued.url}
461
- >
462
- <Icon name='copy-1' />
463
- <span>{copyText}</span>
464
- </TooltipClickToCopy>
465
-
466
- <span className='f' />
467
-
468
- <Button
469
- preset='outline'
470
- size='sm'
471
- text={doneText}
472
- onClick={onDismissIssued}
473
- />
474
- </div>
475
- </div>
476
- )}
477
-
478
- {!subscriptions.length
479
- ? (
480
- <div className='p_df'>
481
- <CalendarRequestEmpty text={emptyText} />
482
- </div>
483
- )
484
- : subscriptions.map((subscription) => {
485
- const isRevoking = pendingRevokeId === subscription.id;
486
-
487
- return (
488
- <div
489
- key={subscription.id}
490
- className={cn('h_item gap_sm bd_t_1 bd_t_bd', isRevoking ? 'op_50' : '')}
491
- style={{ paddingLeft: 12, paddingRight: 12, paddingTop: 8, paddingBottom: 8 }}
492
- >
493
- <div className='f h_0'>
494
- <div className='h_item gap_xs'>
495
- <span className='ellip ft_sm ft_bold'>{subscription.name}</span>
496
-
497
- <SimpleLabel
498
- preset='outline'
499
- color='medium'
500
- text={subscription.scopeLabel}
501
- />
502
- </div>
503
-
504
- {!subscription.createdLabel ? null : (
505
- <div className='ft_tn cl_lt ellip'>{subscription.createdLabel}</div>
506
- )}
507
-
508
- {!subscription.lastFetchedLabel ? null : (
509
- <div className='ft_tn cl_lt ellip'>{subscription.lastFetchedLabel}</div>
510
- )}
511
- </div>
512
-
513
- <Button
514
- className='no_shrink'
515
- preset='outline'
516
- size='sm'
517
- disabled={isRevoking}
518
- text={isRevoking ? revokingText : revokeText}
519
- onClick={() => onRevoke(subscription.id)}
520
- />
521
- </div>
522
- );
523
- })}
524
-
525
- <div className='bd_t_1 bd_t_bd' style={{ padding: 12 }}>
526
- <Button
527
- preset='bg_secondary'
528
- size='sm'
529
- leftIconName='link'
530
- disabled={!!creating}
531
- text={creating ? creatingText : createText}
532
- onClick={onCreate}
533
- />
534
- </div>
535
- </div>
536
- );
537
- });