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