@drawbridge/components 0.1.16 → 0.1.18

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.
@@ -43,10 +43,10 @@ var import_missions = require("@drawbridge/drawbridge-utils/missions");
43
43
  var import_button = __toESM(require("../shared/button"));
44
44
  var import_copy_to_clipboard = __toESM(require("../shared/copy-to-clipboard"));
45
45
  var import_error = __toESM(require("../shared/error"));
46
+ var import_form = __toESM(require("../shared/form"));
46
47
  var import_check = __toESM(require("../icons/check"));
47
48
  var import_chevron_left = __toESM(require("../icons/chevron-left"));
48
49
  var import_chevron_right = __toESM(require("../icons/chevron-right"));
49
- var import_loader = __toESM(require("../icons/loader"));
50
50
  var import_input_group = __toESM(require("../input-group"));
51
51
  var import_input_code = __toESM(require("../input-code"));
52
52
  var import_share_button = __toESM(require("./share-button"));
@@ -107,7 +107,7 @@ const Back = ({ onClick, style }) => {
107
107
  reverse: true,
108
108
  variant: "link"
109
109
  },
110
- children: "Back to missions"
110
+ children: "Back"
111
111
  }
112
112
  )
113
113
  }
@@ -131,29 +131,54 @@ const Strong = ({ children, className }) => /* @__PURE__ */ (0, import_jsx_runti
131
131
  children
132
132
  }
133
133
  );
134
- const CodeStep = ({ disabled, error, onComplete, style }) => {
134
+ const CodeStep = ({ busy, error, onSubmit, style }) => {
135
135
  const [code, setCode] = (0, import_react.useState)("");
136
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
137
- import_input_group.default,
136
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
137
+ import_form.default,
138
138
  {
139
139
  ...{
140
- error,
141
- input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
142
- import_input_code.default,
140
+ className: "space-y-6",
141
+ onSubmit: (event) => {
142
+ event.preventDefault();
143
+ onSubmit(code);
144
+ }
145
+ },
146
+ children: [
147
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
148
+ import_input_group.default,
143
149
  {
144
150
  ...{
145
- autoFocus: true,
146
- disabled,
147
- onChange: setCode,
148
- onComplete,
149
- style,
150
- value: code
151
+ error,
152
+ input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
153
+ import_input_code.default,
154
+ {
155
+ ...{
156
+ autoFocus: true,
157
+ disabled: busy,
158
+ onChange: setCode,
159
+ style,
160
+ value: code
161
+ }
162
+ }
163
+ ),
164
+ label: "Verification code",
165
+ style
151
166
  }
152
167
  }
153
168
  ),
154
- label: "Verification code",
155
- style
156
- }
169
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
170
+ import_button.default,
171
+ {
172
+ ...{
173
+ disabled: code.length !== 6,
174
+ loading: busy,
175
+ style,
176
+ type: "submit"
177
+ },
178
+ children: "Confirm"
179
+ }
180
+ )
181
+ ]
157
182
  }
158
183
  );
159
184
  };
@@ -288,30 +313,14 @@ const FormSubdomainMissions = ({
288
313
  CodeStep,
289
314
  {
290
315
  ...{
291
- disabled: busy,
316
+ busy,
292
317
  error,
293
- onComplete: confirm,
318
+ onSubmit: confirm,
294
319
  style
295
320
  }
296
321
  },
297
322
  attempt
298
323
  ),
299
- busy && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
300
- "div",
301
- {
302
- ...{
303
- className: "flex justify-center"
304
- },
305
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
306
- import_loader.default,
307
- {
308
- ...{
309
- className: "w-5 h-5 animate-spin"
310
- }
311
- }
312
- )
313
- }
314
- ),
315
324
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
316
325
  "p",
317
326
  {
@@ -403,14 +412,12 @@ const FormSubdomainMissions = ({
403
412
  children: [
404
413
  header("Thank you!"),
405
414
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Back, { ...{ onClick: back, style } }),
406
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Centre, { children: [
407
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Strong, { children: "Mission accomplished!" }),
408
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: "Your bonus entries are in. Go back to missions to earn more." })
409
- ] })
415
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Centre, { children: Number(item == null ? void 0 : item.entries) > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Strong, { children: "You've earned " + (0, import_missions.entriesText)(item.entries) }) })
410
416
  ]
411
417
  }
412
418
  );
413
- if (screen === "start") {
419
+ const finished = screen === "start" && !message && !bonusText(items, completed);
420
+ if (screen === "start" && !finished) {
414
421
  const bonus = bonusText(items, completed);
415
422
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
416
423
  "div",
@@ -482,7 +489,7 @@ const FormSubdomainMissions = ({
482
489
  className: "space-y-6"
483
490
  },
484
491
  children: [
485
- header("Earn more entries", { onClick: () => go("start") }),
492
+ finished ? header(title) : header("Earn more entries", { onClick: () => go("start") }),
486
493
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
487
494
  "ul",
488
495
  {
@@ -494,9 +501,9 @@ const FormSubdomainMissions = ({
494
501
  },
495
502
  children: items.filter((row) => import_missions.missions[row.type]).map((row, index) => {
496
503
  var _a2;
497
- const finished = completed.includes(row.type);
504
+ const done = completed.includes(row.type);
498
505
  const opens = screenFor(row.type);
499
- const Mark = finished ? import_check.default : import_chevron_right.default;
506
+ const Mark = done ? import_check.default : import_chevron_right.default;
500
507
  const content = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
501
508
  "span",
502
509
  {
@@ -508,10 +515,10 @@ const FormSubdomainMissions = ({
508
515
  "span",
509
516
  {
510
517
  ...{
511
- className: "flex items-center gap-4 flex-1 min-w-0" + (finished ? " opacity-40" : "")
518
+ className: "flex items-center gap-4 flex-1 min-w-0" + (done ? " opacity-40" : "")
512
519
  },
513
520
  children: [
514
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Pill, { ...{ style }, children: pillText(row, finished) }),
521
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Pill, { ...{ style }, children: pillText(row, done) }),
515
522
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
516
523
  "span",
517
524
  {
@@ -524,7 +531,7 @@ const FormSubdomainMissions = ({
524
531
  ]
525
532
  }
526
533
  ),
527
- (finished || opens !== "missions") && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Pill, { ...{ style }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
534
+ (done || opens !== "missions") && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Pill, { ...{ style }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
528
535
  Mark,
529
536
  {
530
537
  ...{
@@ -544,7 +551,7 @@ const FormSubdomainMissions = ({
544
551
  borderColor: "inherit"
545
552
  }
546
553
  },
547
- children: finished || opens === "missions" ? content : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
554
+ children: done || opens === "missions" ? content : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
548
555
  import_button.default,
549
556
  {
550
557
  ...{
@@ -6,10 +6,10 @@ import { CODE_CHANNELS, COMPLETIONS, entriesText, missions as manifests } from "
6
6
  import Button from "../shared/button.mjs";
7
7
  import CopyToClipboard from "../shared/copy-to-clipboard.mjs";
8
8
  import Error from "../shared/error.mjs";
9
+ import Form from "../shared/form.mjs";
9
10
  import Check from "../icons/check.mjs";
10
11
  import ChevronLeft from "../icons/chevron-left.mjs";
11
12
  import ChevronRight from "../icons/chevron-right.mjs";
12
- import Loader from "../icons/loader.mjs";
13
13
  import InputGroup from "../input-group.mjs";
14
14
  import InputCode from "../input-code.mjs";
15
15
  import ShareButton from "./share-button.mjs";
@@ -70,7 +70,7 @@ const Back = ({ onClick, style }) => {
70
70
  reverse: true,
71
71
  variant: "link"
72
72
  },
73
- children: "Back to missions"
73
+ children: "Back"
74
74
  }
75
75
  )
76
76
  }
@@ -94,29 +94,54 @@ const Strong = ({ children, className }) => /* @__PURE__ */ jsx(
94
94
  children
95
95
  }
96
96
  );
97
- const CodeStep = ({ disabled, error, onComplete, style }) => {
97
+ const CodeStep = ({ busy, error, onSubmit, style }) => {
98
98
  const [code, setCode] = useState("");
99
- return /* @__PURE__ */ jsx(
100
- InputGroup,
99
+ return /* @__PURE__ */ jsxs(
100
+ Form,
101
101
  {
102
102
  ...{
103
- error,
104
- input: /* @__PURE__ */ jsx(
105
- InputCode,
103
+ className: "space-y-6",
104
+ onSubmit: (event) => {
105
+ event.preventDefault();
106
+ onSubmit(code);
107
+ }
108
+ },
109
+ children: [
110
+ /* @__PURE__ */ jsx(
111
+ InputGroup,
106
112
  {
107
113
  ...{
108
- autoFocus: true,
109
- disabled,
110
- onChange: setCode,
111
- onComplete,
112
- style,
113
- value: code
114
+ error,
115
+ input: /* @__PURE__ */ jsx(
116
+ InputCode,
117
+ {
118
+ ...{
119
+ autoFocus: true,
120
+ disabled: busy,
121
+ onChange: setCode,
122
+ style,
123
+ value: code
124
+ }
125
+ }
126
+ ),
127
+ label: "Verification code",
128
+ style
114
129
  }
115
130
  }
116
131
  ),
117
- label: "Verification code",
118
- style
119
- }
132
+ /* @__PURE__ */ jsx(
133
+ Button,
134
+ {
135
+ ...{
136
+ disabled: code.length !== 6,
137
+ loading: busy,
138
+ style,
139
+ type: "submit"
140
+ },
141
+ children: "Confirm"
142
+ }
143
+ )
144
+ ]
120
145
  }
121
146
  );
122
147
  };
@@ -251,30 +276,14 @@ const FormSubdomainMissions = ({
251
276
  CodeStep,
252
277
  {
253
278
  ...{
254
- disabled: busy,
279
+ busy,
255
280
  error,
256
- onComplete: confirm,
281
+ onSubmit: confirm,
257
282
  style
258
283
  }
259
284
  },
260
285
  attempt
261
286
  ),
262
- busy && /* @__PURE__ */ jsx(
263
- "div",
264
- {
265
- ...{
266
- className: "flex justify-center"
267
- },
268
- children: /* @__PURE__ */ jsx(
269
- Loader,
270
- {
271
- ...{
272
- className: "w-5 h-5 animate-spin"
273
- }
274
- }
275
- )
276
- }
277
- ),
278
287
  /* @__PURE__ */ jsxs(
279
288
  "p",
280
289
  {
@@ -366,14 +375,12 @@ const FormSubdomainMissions = ({
366
375
  children: [
367
376
  header("Thank you!"),
368
377
  /* @__PURE__ */ jsx(Back, { ...{ onClick: back, style } }),
369
- /* @__PURE__ */ jsxs(Centre, { children: [
370
- /* @__PURE__ */ jsx(Strong, { children: "Mission accomplished!" }),
371
- /* @__PURE__ */ jsx("p", { children: "Your bonus entries are in. Go back to missions to earn more." })
372
- ] })
378
+ /* @__PURE__ */ jsx(Centre, { children: Number(item == null ? void 0 : item.entries) > 0 && /* @__PURE__ */ jsx(Strong, { children: "You've earned " + entriesText(item.entries) }) })
373
379
  ]
374
380
  }
375
381
  );
376
- if (screen === "start") {
382
+ const finished = screen === "start" && !message && !bonusText(items, completed);
383
+ if (screen === "start" && !finished) {
377
384
  const bonus = bonusText(items, completed);
378
385
  return /* @__PURE__ */ jsxs(
379
386
  "div",
@@ -445,7 +452,7 @@ const FormSubdomainMissions = ({
445
452
  className: "space-y-6"
446
453
  },
447
454
  children: [
448
- header("Earn more entries", { onClick: () => go("start") }),
455
+ finished ? header(title) : header("Earn more entries", { onClick: () => go("start") }),
449
456
  /* @__PURE__ */ jsx(
450
457
  "ul",
451
458
  {
@@ -457,9 +464,9 @@ const FormSubdomainMissions = ({
457
464
  },
458
465
  children: items.filter((row) => manifests[row.type]).map((row, index) => {
459
466
  var _a2;
460
- const finished = completed.includes(row.type);
467
+ const done = completed.includes(row.type);
461
468
  const opens = screenFor(row.type);
462
- const Mark = finished ? Check : ChevronRight;
469
+ const Mark = done ? Check : ChevronRight;
463
470
  const content = /* @__PURE__ */ jsxs(
464
471
  "span",
465
472
  {
@@ -471,10 +478,10 @@ const FormSubdomainMissions = ({
471
478
  "span",
472
479
  {
473
480
  ...{
474
- className: "flex items-center gap-4 flex-1 min-w-0" + (finished ? " opacity-40" : "")
481
+ className: "flex items-center gap-4 flex-1 min-w-0" + (done ? " opacity-40" : "")
475
482
  },
476
483
  children: [
477
- /* @__PURE__ */ jsx(Pill, { ...{ style }, children: pillText(row, finished) }),
484
+ /* @__PURE__ */ jsx(Pill, { ...{ style }, children: pillText(row, done) }),
478
485
  /* @__PURE__ */ jsx(
479
486
  "span",
480
487
  {
@@ -487,7 +494,7 @@ const FormSubdomainMissions = ({
487
494
  ]
488
495
  }
489
496
  ),
490
- (finished || opens !== "missions") && /* @__PURE__ */ jsx(Pill, { ...{ style }, children: /* @__PURE__ */ jsx(
497
+ (done || opens !== "missions") && /* @__PURE__ */ jsx(Pill, { ...{ style }, children: /* @__PURE__ */ jsx(
491
498
  Mark,
492
499
  {
493
500
  ...{
@@ -507,7 +514,7 @@ const FormSubdomainMissions = ({
507
514
  borderColor: "inherit"
508
515
  }
509
516
  },
510
- children: finished || opens === "missions" ? content : /* @__PURE__ */ jsx(
517
+ children: done || opens === "missions" ? content : /* @__PURE__ */ jsx(
511
518
  Button,
512
519
  {
513
520
  ...{
@@ -393,7 +393,7 @@ const TemplateLayout = ({
393
393
  },
394
394
  [affiliate, data, params, preview, style]
395
395
  );
396
- const leadMission = searchParams.get("mission");
396
+ const leadMission = searchParams.get("open");
397
397
  const leadUrl = submissionId ? null : (0, import_url.leadEndpoint)({ code: searchParams.get("m"), slug: params == null ? void 0 : params.slug, subdomain: params == null ? void 0 : params.subdomain, token });
398
398
  (0, import_react.useEffect)(
399
399
  () => {
@@ -361,7 +361,7 @@ const TemplateLayout = ({
361
361
  },
362
362
  [affiliate, data, params, preview, style]
363
363
  );
364
- const leadMission = searchParams.get("mission");
364
+ const leadMission = searchParams.get("open");
365
365
  const leadUrl = submissionId ? null : leadEndpoint({ code: searchParams.get("m"), slug: params == null ? void 0 : params.slug, subdomain: params == null ? void 0 : params.subdomain, token });
366
366
  useEffect(
367
367
  () => {
@@ -158,7 +158,7 @@ const TemplateModal = ({
158
158
  );
159
159
  // @story public-entry/lead-link
160
160
  // Opened by the lead's own link while entries are being awarded:
161
- // the missions panel, at the mission a `&mission=` asked for. With
161
+ // the missions panel, at the mission a `&open=` asked for. With
162
162
  // no missions the link opens no panel (template-layout.js).
163
163
  case "lead":
164
164
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -126,7 +126,7 @@ const TemplateModal = ({
126
126
  );
127
127
  // @story public-entry/lead-link
128
128
  // Opened by the lead's own link while entries are being awarded:
129
- // the missions panel, at the mission a `&mission=` asked for. With
129
+ // the missions panel, at the mission a `&open=` asked for. With
130
130
  // no missions the link opens no panel (template-layout.js).
131
131
  case "lead":
132
132
  return /* @__PURE__ */ jsx(
@@ -64,7 +64,7 @@ const FormOrganizationCampaignAgreement = ({
64
64
  params
65
65
  }) => {
66
66
  const ids = Object.keys(agreements);
67
- const { control, handleSubmit, formState, reset } = (0, import_form.useForm)({
67
+ const { control, getValues, handleSubmit, formState, reset } = (0, import_form.useForm)({
68
68
  defaultValues: Object.fromEntries(ids.map((id) => {
69
69
  var _a;
70
70
  return [id, ((_a = agreements[id]) == null ? void 0 : _a.values) || {}];
@@ -106,7 +106,7 @@ const FormOrganizationCampaignAgreement = ({
106
106
  });
107
107
  }
108
108
  ;
109
- reset(values);
109
+ reset(getValues());
110
110
  if (response) onSuccess(response);
111
111
  } catch (error) {
112
112
  onError(error);
@@ -32,7 +32,7 @@ const FormOrganizationCampaignAgreement = ({
32
32
  params
33
33
  }) => {
34
34
  const ids = Object.keys(agreements);
35
- const { control, handleSubmit, formState, reset } = useForm({
35
+ const { control, getValues, handleSubmit, formState, reset } = useForm({
36
36
  defaultValues: Object.fromEntries(ids.map((id) => {
37
37
  var _a;
38
38
  return [id, ((_a = agreements[id]) == null ? void 0 : _a.values) || {}];
@@ -74,7 +74,7 @@ const FormOrganizationCampaignAgreement = ({
74
74
  });
75
75
  }
76
76
  ;
77
- reset(values);
77
+ reset(getValues());
78
78
  if (response) onSuccess(response);
79
79
  } catch (error) {
80
80
  onError(error);