@joinskips/common 0.1.0-develop.144 → 0.1.0-develop.145

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.
@@ -6,6 +6,8 @@ export declare const CANCEL_COMMAND = "/treat-cancel";
6
6
  export declare function cancelCommand(uids: readonly string[], reason?: string | null): string;
7
7
  export declare const DISCONTINUE_COMMAND = "/treat-discontinue";
8
8
  export declare function discontinueCommand(uids: readonly string[], reason?: string | null): string;
9
+ /** The Orders menu's Send payment link: usrx sends the member the newest order's payment link, or stages it when their plan pays. */
10
+ export declare const PAYMENT_LINK_COMMAND = "/treat-payment-link";
9
11
  export declare const PHARMACY_ROLES: readonly string[];
10
12
  /** Whether a staff member's skips_role custom attribute lets them reach a pharmacy. */
11
13
  export declare function reachesPharmacy(role: string | null | undefined): boolean;
@@ -22,6 +22,8 @@ export const DISCONTINUE_COMMAND = '/treat-discontinue';
22
22
  export function discontinueCommand(uids, reason) {
23
23
  return withReason([DISCONTINUE_COMMAND, ...uids], reason);
24
24
  }
25
+ /** The Orders menu's Send payment link: usrx sends the member the newest order's payment link, or stages it when their plan pays. */
26
+ export const PAYMENT_LINK_COMMAND = '/treat-payment-link';
25
27
  // Only these Skips roles reach a pharmacy: usrx refuses a send or a cancel from anyone else (joinskips/usrx#11), so
26
28
  // their buttons show only for them (joinskips/skips-app#322).
27
29
  export const PHARMACY_ROLES = ['admin', 'provider'];
@@ -109,6 +109,10 @@ export interface OrdersMenuView {
109
109
  setReason: (reason: string) => void;
110
110
  cancelAction: () => void;
111
111
  runAction: () => void;
112
+ sendingPaymentLink: boolean;
113
+ /** The last Send payment link in this conversation did not post. */
114
+ paymentLinkFailed: boolean;
115
+ sendPaymentLink: () => void;
112
116
  }
113
117
  /** The Orders menu of a conversation: what Treat holds for it, and what staff can do from it. */
114
118
  export declare function useOrdersMenu(source: OrdersMenuSource): OrdersMenuView;
@@ -1,5 +1,5 @@
1
1
  import { useCallback, useEffect, useRef, useState } from 'react';
2
- import { deleteRefusal, reachesPharmacy } from "../helpers/cardNote.js";
2
+ import { deleteRefusal, PAYMENT_LINK_COMMAND, reachesPharmacy } from "../helpers/cardNote.js";
3
3
  import { isQueued, localDay, newestMessageId, newestUsrxNote, SHOWN_REF_LENGTH, } from "../helpers/medicationOrder.js";
4
4
  import { actionCommand, actionReason, cardKey, firstOf, orderLists, shownOrder, STATUS_LIST, tickedRows, } from "../helpers/ordersMenu.js";
5
5
  function failureRef(answer) {
@@ -94,8 +94,10 @@ export function useOrdersMenu(source) {
94
94
  const [reason, setReason] = useState('');
95
95
  const [acting, setActing] = useState(false);
96
96
  const [actionFailed, setActionFailed] = useState(false);
97
+ const [sendingPaymentLink, setSendingPaymentLink] = useState(false);
98
+ const [paymentLinkFailed, setPaymentLinkFailed] = useState(false);
97
99
  // Two taps can land before a button draws busy, and each would act, so each press holds until its call ends.
98
- const pressed = useRef({ delete: false, action: false, stage: false });
100
+ const pressed = useRef({ delete: false, action: false, stage: false, paymentLink: false });
99
101
  // The usrx notes a conversation already holds when it opens are not news.
100
102
  const [readAfter, setReadAfter] = useState({ conversationId, id: newestMessageId(messages) });
101
103
  useEffect(() => {
@@ -110,6 +112,9 @@ export function useOrdersMenu(source) {
110
112
  setToDelete(null);
111
113
  setPending(null);
112
114
  setStageFailed(null);
115
+ setPaymentLinkFailed(false);
116
+ setSendingPaymentLink(false);
117
+ pressed.current.paymentLink = false;
113
118
  setReadAfter({ conversationId, id: newestMessageId(latest.current.messages) });
114
119
  void read();
115
120
  }, [conversationId, read]);
@@ -333,5 +338,32 @@ export function useOrdersMenu(source) {
333
338
  }
334
339
  })();
335
340
  },
341
+ sendingPaymentLink,
342
+ paymentLinkFailed,
343
+ sendPaymentLink: () => {
344
+ if (pressed.current.paymentLink)
345
+ return;
346
+ pressed.current.paymentLink = true;
347
+ setSendingPaymentLink(true);
348
+ setPaymentLinkFailed(false);
349
+ // The conversation it was pressed in, whatever opens while it waits.
350
+ const generation = reads.current.generation;
351
+ void (async () => {
352
+ try {
353
+ await latest.current.sendNote(conversationId, PAYMENT_LINK_COMMAND);
354
+ }
355
+ catch {
356
+ if (generation === reads.current.generation)
357
+ setPaymentLinkFailed(true);
358
+ }
359
+ finally {
360
+ // A conversation change already freed the button for the new conversation.
361
+ if (generation === reads.current.generation) {
362
+ setSendingPaymentLink(false);
363
+ pressed.current.paymentLink = false;
364
+ }
365
+ }
366
+ })();
367
+ },
336
368
  };
337
369
  }
@@ -61,6 +61,9 @@ export interface OrdersMenuWords {
61
61
  confirmChangePharmacyBody: (pharmacy: string) => string;
62
62
  reason: string;
63
63
  actionFailed: string;
64
+ sendPaymentLink: string;
65
+ /** The Send payment link button after its note did not post, pressed again to retry. */
66
+ paymentLinkFailed: string;
64
67
  }
65
68
  export interface OrdersMenuProps extends OrdersMenuView {
66
69
  words: OrdersMenuWords;
@@ -120,7 +120,7 @@ export function OrdersMenu(props) {
120
120
  item('past', lists.past.length, words.past, words.noPast),
121
121
  ]),
122
122
  ];
123
- return (_jsxs(View, { className: "relative self-end", children: [_jsx(StaffButton, { label: words.button(props.count), loading: props.reading && !props.open, onPress: props.toggle }), confirm ? (_jsx(View, { className: "absolute bottom-full right-0 z-10 mb-2 w-80 max-w-[90vw] rounded-control border border-line-control bg-surface p-3", children: confirm })) : null, props.open && !confirm ? (_jsx(ScrollView, { role: "group", accessibilityLabel: words.menu, className: "absolute bottom-full right-0 z-10 mb-2 max-h-96 w-80 max-w-[90vw] rounded-control border border-line-control bg-surface p-2", children: list === null ? (_jsxs(View, { className: "gap-1", children: [props.canOrder ? _jsx(StaffButton, { label: words.newOrder, look: "primary", onPress: props.newOrder }) : null, top.map((item) => (_jsx(StaffButton, { label: item.label, disabled: item.empty, onPress: () => {
123
+ return (_jsxs(View, { className: "relative flex-row items-center gap-2 self-end", children: [_jsx(StaffButton, { label: props.paymentLinkFailed ? words.paymentLinkFailed : words.sendPaymentLink, loading: props.sendingPaymentLink, onPress: props.sendPaymentLink }), _jsx(StaffButton, { label: words.button(props.count), loading: props.reading && !props.open, onPress: props.toggle }), confirm ? (_jsx(View, { className: "absolute bottom-full right-0 z-10 mb-2 w-80 max-w-[90vw] rounded-control border border-line-control bg-surface p-3", children: confirm })) : null, props.open && !confirm ? (_jsx(ScrollView, { role: "group", accessibilityLabel: words.menu, className: "absolute bottom-full right-0 z-10 mb-2 max-h-96 w-80 max-w-[90vw] rounded-control border border-line-control bg-surface p-2", children: list === null ? (_jsxs(View, { className: "gap-1", children: [props.canOrder ? _jsx(StaffButton, { label: words.newOrder, look: "primary", onPress: props.newOrder }) : null, top.map((item) => (_jsx(StaffButton, { label: item.label, disabled: item.empty, onPress: () => {
124
124
  props.show(item.list);
125
125
  } }, item.list))), props.pastFailed ? (_jsxs(View, { className: "flex-row flex-wrap items-center justify-between gap-2", children: [_jsx(Line, { text: words.pastFailed, error: true }), _jsx(StaffButton, { label: words.readAgain, loading: props.reading, onPress: () => void props.refetch() })] })) : null, props.cardsFailed === null ? (props.reading && props.count === 0 ? _jsx(Line, { text: words.readingCards }) : null) : (_jsxs(View, { className: "flex-row flex-wrap items-center justify-between gap-2", children: [_jsx(Line, { text: [words.cardsNotRead, props.cardsFailed ? words.reference(props.cardsFailed) : ''].filter(Boolean).join(' '), error: true }), _jsx(StaffButton, { label: words.readAgain, loading: props.reading, onPress: () => void props.refetch() })] }))] })) : (_jsxs(View, { className: "gap-2", children: [_jsxs(View, { className: "flex-row flex-wrap items-center justify-between gap-2", children: [_jsx(StaffButton, { label: words.back, onPress: () => {
126
126
  props.show(null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joinskips/common",
3
- "version": "0.1.0-develop.144",
3
+ "version": "0.1.0-develop.145",
4
4
  "description": "The code the Skips apps share, built once in React Native: components, hooks and helpers.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {