A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
feat(app): pass Operator Passes on to friends and answer offers
Hampusf5c755e9afc7
diff --git a/fluxer_app/src/features/premium/components/operator_pass/OperatorPassOfferModal.module.css b/fluxer_app/src/features/premium/components/operator_pass/OperatorPassOfferModal.module.cssnew file mode 100644index 000000000..5af6f4cc0--- /dev/null+++ b/fluxer_app/src/features/premium/components/operator_pass/OperatorPassOfferModal.module.css@@ -0,0 +1,47 @@+/* SPDX-License-Identifier: AGPL-3.0-or-later */++.loading {+ display: flex;+ justify-content: center;+ padding: 2rem 0;+}++.note {+ margin: 0;+ color: var(--text-primary-muted);+ font-size: 0.875rem;+ line-height: 1.25rem;+}++.consentBox {+ padding: 0.75rem;+ border-radius: 0.5rem;+ background-color: var(--background-secondary);+ border: 1px solid var(--background-modifier-accent);+}++.consentBoxError {+ border-color: var(--status-danger);+}++.consentError {+ margin: 0.5rem 0 0;+ color: var(--status-danger);+ font-size: 0.875rem;+ line-height: 1.25rem;+}++.consentCheckbox {+ height: auto !important;+ align-items: flex-start;+}++.consentCheckbox > :first-child {+ flex-shrink: 0;+}++.consentLabel {+ color: var(--text-secondary);+ font-size: 0.875rem;+ line-height: 1.25rem;+}diff --git a/fluxer_app/src/features/premium/components/operator_pass/OperatorPassOfferModal.tsx b/fluxer_app/src/features/premium/components/operator_pass/OperatorPassOfferModal.tsxnew file mode 100644index 000000000..d8f9fb211--- /dev/null+++ b/fluxer_app/src/features/premium/components/operator_pass/OperatorPassOfferModal.tsx@@ -0,0 +1,370 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++import {Routes} from '@app/app/Routes';+import * as Modal from '@app/features/app/components/dialogs/Modal';+import {ExternalLink} from '@app/features/app/components/shared/ExternalLink';+import {OPERATOR_PASS_NAME, PRODUCT_NAME} from '@app/features/app/config/I18nDisplayConstants';+import {Logger} from '@app/features/platform/utils/AppLogger';+import * as OperatorPassCommands from '@app/features/premium/commands/OperatorPassCommands';+import styles from '@app/features/premium/components/operator_pass/OperatorPassOfferModal.module.css';+import {OperatorPassWallNameField} from '@app/features/premium/components/operator_pass/OperatorPassWallNameField';+import OperatorPassHoldings from '@app/features/premium/state/OperatorPassHoldings';+import {+ focusFirstInvalidOperatorPassField,+ focusOperatorPassField,+ formatOperatorPassDateTime,+ formatOperatorPassUnlockDay,+ getOperatorPassErrorCode,+ getOperatorPassOfferUserName,+ getOperatorPassWallNameProblem,+ hasOperatorPassTimePassed,+ normalizeOperatorPassWallName,+ type OperatorPassWallNameProblem,+} from '@app/features/premium/utils/OperatorPassUtils';+import {+ OPERATOR_PASS_CHARACTERISTICS_DESCRIPTOR,+ OPERATOR_PASS_LISTING_UNCHANGED_DESCRIPTOR,+ OPERATOR_PASS_REQUIRED_BOX_DESCRIPTOR,+} from '@app/features/premium/utils/PremiumMessageDescriptors';+import {Button} from '@app/features/ui/button/Button';+import {Checkbox} from '@app/features/ui/checkbox/Checkbox';+import * as ModalCommands from '@app/features/ui/commands/ModalCommands';+import {modal} from '@app/features/ui/commands/ModalCommands';+import * as ToastCommands from '@app/features/ui/commands/ToastCommands';+import {Spinner} from '@app/features/ui/components/Spinner';+import {WarningAlert} from '@app/features/ui/warning_alert/WarningAlert';+import Users from '@app/features/user/state/Users';+import {APIErrorCodes} from '@fluxer/constants/src/ApiErrorCodes';+import type {OperatorPassOfferResponse} from '@fluxer/schema/src/domains/operator_pass/OperatorPassSchemas';+import type {MessageDescriptor} from '@lingui/core';+import {msg} from '@lingui/core/macro';+import {Trans, useLingui} from '@lingui/react/macro';+import {clsx} from 'clsx';+import {observer} from 'mobx-react-lite';+import {useEffect, useState} from 'react';++const OFFER_TITLE_DESCRIPTOR = msg({+ message: '{operatorPassName} from {senderName}',+ comment:+ 'Title of the dialog where you accept or decline an Operator Pass another person passed on to you. {senderName} is their display name. Operator Pass is a product name and stays untranslated.',+});+const OFFER_ARRIVES_DESCRIPTOR = msg({+ message: 'It arrives on {date} if you accept.',+ comment:+ 'Line in the dialog for an Operator Pass someone passed on to you, while the waiting period after payment runs. It is the pass. {date} is a date such as Nov 23, 2026.',+});+const OFFER_ARRIVES_NOW_DESCRIPTOR = msg({+ message: 'It arrives as soon as you accept.',+ comment:+ 'Line in the dialog for an Operator Pass someone passed on to you, once the waiting period after payment has ended. It is the pass.',+});+const ACCEPT_DESCRIPTOR = msg({+ message: 'Accept',+ comment: 'Button that accepts an incoming Operator Pass offer.',+});+const DECLINE_DESCRIPTOR = msg({+ message: 'Decline',+ comment: 'Button that declines an incoming Operator Pass offer.',+});+const ACCEPTED_DESCRIPTOR = msg({+ message: 'Accepted. It arrives on {date}.',+ comment:+ 'Toast after accepting an Operator Pass offer while the waiting period after payment runs. It is the pass. {date} is a date such as Nov 23, 2026.',+});+const ARRIVED_DESCRIPTOR = msg({+ message: 'The pass is yours now.',+ comment: 'Toast after accepting an Operator Pass offer that moved to your account right away.',+});+const DECLINED_DESCRIPTOR = msg({+ message: 'Pass declined.',+ comment: 'Toast after declining an Operator Pass someone offered you.',+});+const OFFER_GONE_DESCRIPTOR = msg({+ message: 'This offer is no longer open.',+ comment: 'Notice in the incoming Operator Pass offer dialog when the sender took the offer back or it ended.',+});+const OFFER_FAILED_DESCRIPTOR = msg({+ message: "Couldn't answer the offer. Try again.",+ comment: 'Notice when accepting or declining an incoming Operator Pass offer failed.',+});+const OFFER_LOAD_FAILED_DESCRIPTOR = msg({+ message: "Couldn't load the offer. Try again later.",+ comment: 'Notice when the incoming Operator Pass offer could not be loaded.',+});++const logger = new Logger('OperatorPassOfferModal');++const WALL_NAME_FIELD_ID = 'operator-pass-offer-wall-name';+const TERMS_BOX_ID = 'operator-pass-offer-terms';+const TERMS_ERROR_ID = 'operator-pass-offer-terms-error';++type Notice = 'gone' | 'failed' | 'load_failed';++const NOTICE_DESCRIPTORS: Record<Notice, MessageDescriptor> = {+ gone: OFFER_GONE_DESCRIPTOR,+ failed: OFFER_FAILED_DESCRIPTOR,+ load_failed: OFFER_LOAD_FAILED_DESCRIPTOR,+};++const OperatorPassOfferModal = observer(function OperatorPassOfferModal({offerId}: {offerId: string}) {+ const {i18n} = useLingui();+ const [offer, setOffer] = useState<OperatorPassOfferResponse | null>(() => OperatorPassHoldings.findOffer(offerId));+ const [acceptedTerms, setAcceptedTerms] = useState(false);+ const [termsMissing, setTermsMissing] = useState(false);+ const [wallName, setWallName] = useState(() => Users.currentUser?.displayName ?? '');+ const [wallOptOut, setWallOptOut] = useState(false);+ const [wallNameProblem, setWallNameProblem] = useState<OperatorPassWallNameProblem | null>(null);+ const [submitting, setSubmitting] = useState<'accept' | 'decline' | null>(null);+ const [notice, setNotice] = useState<Notice | null>(null);+ const [wallChosen, setWallChosen] = useState<boolean | null>(null);+ const [revealWallField, setRevealWallField] = useState(false);+ const isOperator = (OperatorPassHoldings.count ?? 0) > 0 || Users.currentUser?.operatorPassSince != null;+ const asksWallChoice = revealWallField || !(wallChosen ?? isOperator);+ useEffect(() => {+ let active = true;+ OperatorPassCommands.fetchState()+ .then((state) => {+ if (active) setWallChosen(state.holder?.wall_chosen ?? false);+ })+ .catch((error) => logger.warn('Failed to load the Operator Pass state for an offer', error));+ return () => {+ active = false;+ };+ }, []);+ useEffect(() => {+ let active = true;+ OperatorPassCommands.fetchOffer(offerId)+ .then((result) => {+ if (!active) return;+ setOffer(result);+ if (result.status !== 'pending') setNotice('gone');+ })+ .catch((error) => {+ logger.warn('Failed to load the Operator Pass offer', error);+ if (active) setNotice((current) => current ?? 'load_failed');+ });+ return () => {+ active = false;+ };+ }, [offerId]);+ const pending = offer?.status === 'pending';+ const handleError = (error: unknown) => {+ logger.error('Operator Pass offer answer failed', error);+ const code = getOperatorPassErrorCode(error);+ if (code === APIErrorCodes.OPERATOR_PASS_WALL_NAME_REQUIRED) {+ setRevealWallField(true);+ setWallNameProblem('required');+ focusOperatorPassField(WALL_NAME_FIELD_ID);+ return;+ }+ if (code === APIErrorCodes.OPERATOR_PASS_TERMS_NOT_ACCEPTED) {+ setAcceptedTerms(false);+ setTermsMissing(true);+ focusOperatorPassField(TERMS_BOX_ID);+ return;+ }+ setNotice(+ code === APIErrorCodes.UNKNOWN_OPERATOR_PASS_OFFER ||+ code === APIErrorCodes.OPERATOR_PASS_OFFER_UNAVAILABLE ||+ code === APIErrorCodes.OPERATOR_PASS_RECIPIENT_NOT_FRIEND+ ? 'gone'+ : 'failed',+ );+ };+ const handleAccept = async () => {+ if (!offer || submitting) return;+ const problem = asksWallChoice ? getOperatorPassWallNameProblem(wallName, wallOptOut) : null;+ setWallNameProblem(problem);+ setTermsMissing(!acceptedTerms);+ if (+ focusFirstInvalidOperatorPassField([+ {id: WALL_NAME_FIELD_ID, invalid: problem !== null},+ {id: TERMS_BOX_ID, invalid: !acceptedTerms},+ ])+ ) {+ return;+ }+ setSubmitting('accept');+ setNotice(null);+ try {+ const result = await OperatorPassCommands.acceptOffer(+ offer.id,+ asksWallChoice+ ? {+ accept_terms: true,+ wall_name: wallOptOut ? null : normalizeOperatorPassWallName(wallName),+ wall_opt_out: wallOptOut,+ }+ : {accept_terms: true},+ );+ ToastCommands.success(+ result.status === 'completed'+ ? i18n._(ARRIVED_DESCRIPTOR)+ : i18n._(ACCEPTED_DESCRIPTOR, {date: formatOperatorPassUnlockDay(result.arrives_at)}),+ );+ ModalCommands.pop();+ } catch (error) {+ handleError(error);+ } finally {+ setSubmitting(null);+ }+ };+ const handleDecline = async () => {+ if (!offer || submitting) return;+ setSubmitting('decline');+ setNotice(null);+ try {+ await OperatorPassCommands.declineOffer(offer.id);+ ToastCommands.success(i18n._(DECLINED_DESCRIPTOR));+ ModalCommands.pop();+ } catch (error) {+ handleError(error);+ } finally {+ setSubmitting(null);+ }+ };+ const noticeText = notice ? i18n._(NOTICE_DESCRIPTORS[notice]) : null;+ return (+ <Modal.Root size="small" centered data-flx="premium.operator-pass-offer-modal.modal-root">+ <Modal.Header+ title={+ offer+ ? i18n._(OFFER_TITLE_DESCRIPTOR, {+ operatorPassName: OPERATOR_PASS_NAME,+ senderName: getOperatorPassOfferUserName(offer.sender),+ })+ : OPERATOR_PASS_NAME+ }+ data-flx="premium.operator-pass-offer-modal.modal-header"+ />+ <Modal.Content data-flx="premium.operator-pass-offer-modal.modal-content">+ <Modal.ContentLayout data-flx="premium.operator-pass-offer-modal.content-layout">+ {noticeText && (+ <div role="alert" data-flx="premium.operator-pass-offer-modal.notice-alert">+ <WarningAlert data-flx="premium.operator-pass-offer-modal.notice">{noticeText}</WarningAlert>+ </div>+ )}+ {!offer && !notice && (+ <div className={styles.loading} data-flx="premium.operator-pass-offer-modal.loading">+ <Spinner data-flx="premium.operator-pass-offer-modal.spinner" />+ </div>+ )}+ {offer && (+ <>+ <Modal.Description+ title={+ hasOperatorPassTimePassed(offer.arrives_at) ? undefined : formatOperatorPassDateTime(offer.arrives_at)+ }+ data-flx="premium.operator-pass-offer-modal.body"+ >+ {`${isOperator ? '' : `${i18n._(OPERATOR_PASS_CHARACTERISTICS_DESCRIPTOR, {productName: PRODUCT_NAME})} `}${+ hasOperatorPassTimePassed(offer.arrives_at)+ ? i18n._(OFFER_ARRIVES_NOW_DESCRIPTOR)+ : i18n._(OFFER_ARRIVES_DESCRIPTOR, {date: formatOperatorPassUnlockDay(offer.arrives_at)})+ }`}+ </Modal.Description>+ {pending &&+ (!asksWallChoice ? (+ <p className={styles.note} data-flx="premium.operator-pass-offer-modal.listing-unchanged">+ {i18n._(OPERATOR_PASS_LISTING_UNCHANGED_DESCRIPTOR)}+ </p>+ ) : (+ <OperatorPassWallNameField+ id={WALL_NAME_FIELD_ID}+ name={wallName}+ optOut={wallOptOut}+ problem={wallNameProblem}+ disabled={submitting != null}+ context="offer"+ onNameChange={(value) => {+ setWallName(value);+ if (wallNameProblem) setWallNameProblem(getOperatorPassWallNameProblem(value, wallOptOut));+ }}+ onOptOutChange={(value) => {+ setWallOptOut(value);+ if (value) setWallNameProblem(null);+ }}+ data-flx="premium.operator-pass.operator-pass-offer-modal.operator-pass-wall-name-field"+ />+ ))}+ {pending && (+ <div+ id={TERMS_BOX_ID}+ className={clsx(styles.consentBox, termsMissing && styles.consentBoxError)}+ data-flx="premium.operator-pass-offer-modal.terms"+ >+ <Checkbox+ className={styles.consentCheckbox}+ checked={acceptedTerms}+ onChange={(value) => {+ setAcceptedTerms(value);+ if (value) setTermsMissing(false);+ }}+ disabled={submitting != null}+ aria-describedby={termsMissing ? TERMS_ERROR_ID : undefined}+ data-flx="premium.operator-pass-offer-modal.checkbox.terms"+ >+ <span className={styles.consentLabel} data-flx="premium.operator-pass-offer-modal.terms-label">+ <Trans comment="Required checkbox next to Accept in the dialog for an Operator Pass someone passed on to you. Consumer law text, translate faithfully and keep every condition. The linked text names the Operator Pass terms document. {OPERATOR_PASS_NAME} is a product name and stays untranslated. Its payment is reversed means the payment for the pass is refunded or charged back.">+ I accept the{' '}+ <ExternalLink+ href={Routes.operatorPassTerms()}+ data-flx="premium.operator-pass-offer-modal.terms-link"+ >+ {OPERATOR_PASS_NAME} terms+ </ExternalLink>+ . This pass can't be passed on again, and it ends if its payment is reversed.+ </Trans>+ </span>+ </Checkbox>+ {termsMissing && (+ <p+ id={TERMS_ERROR_ID}+ className={styles.consentError}+ data-flx="premium.operator-pass-offer-modal.terms-error"+ >+ {i18n._(OPERATOR_PASS_REQUIRED_BOX_DESCRIPTOR)}+ </p>+ )}+ </div>+ )}+ </>+ )}+ </Modal.ContentLayout>+ </Modal.Content>+ {pending ? (+ <Modal.Footer data-flx="premium.operator-pass-offer-modal.modal-footer">+ <Button+ variant="secondary"+ onClick={() => void handleDecline()}+ submitting={submitting === 'decline'}+ disabled={submitting === 'accept'}+ data-flx="premium.operator-pass-offer-modal.button.decline"+ >+ {i18n._(DECLINE_DESCRIPTOR)}+ </Button>+ <Button+ variant="primary"+ onClick={() => void handleAccept()}+ submitting={submitting === 'accept'}+ disabled={submitting === 'decline'}+ data-flx="premium.operator-pass-offer-modal.button.accept"+ >+ {i18n._(ACCEPT_DESCRIPTOR)}+ </Button>+ </Modal.Footer>+ ) : (+ <Modal.DismissFooter data-flx="premium.operator-pass-offer-modal.dismiss-footer" />+ )}+ </Modal.Root>+ );+});++const OFFER_MODAL_KEY_PREFIX = 'operator-pass-offer-';++export function openOperatorPassOfferModal(offerId: string): void {+ ModalCommands.pushWithKey(+ modal(() => <OperatorPassOfferModal offerId={offerId} data-flx="premium.operator-pass-offer-modal.open" />),+ `${OFFER_MODAL_KEY_PREFIX}${offerId}`,+ );+}diff --git a/fluxer_app/src/features/premium/components/operator_pass/OperatorPassPassItOnModal.module.css b/fluxer_app/src/features/premium/components/operator_pass/OperatorPassPassItOnModal.module.cssnew file mode 100644index 000000000..d607414e7--- /dev/null+++ b/fluxer_app/src/features/premium/components/operator_pass/OperatorPassPassItOnModal.module.css@@ -0,0 +1,6 @@+/* SPDX-License-Identifier: AGPL-3.0-or-later */++.root {+ height: auto;+ max-height: 45rem;+}diff --git a/fluxer_app/src/features/premium/components/operator_pass/OperatorPassPassItOnModal.tsx b/fluxer_app/src/features/premium/components/operator_pass/OperatorPassPassItOnModal.tsxnew file mode 100644index 000000000..2ed027cfd--- /dev/null+++ b/fluxer_app/src/features/premium/components/operator_pass/OperatorPassPassItOnModal.tsx@@ -0,0 +1,228 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++import {ConfirmModal} from '@app/features/app/components/dialogs/ConfirmModal';+import * as Modal from '@app/features/app/components/dialogs/Modal';+import {+ type RecipientItem,+ RecipientList,+ useRecipientItems,+} from '@app/features/app/components/dialogs/shared/RecipientList';+import selectorStyles from '@app/features/app/components/dialogs/shared/SelectorModalStyles.module.css';+import {SEARCH_FRIENDS_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors';+import * as OperatorPassCommands from '@app/features/premium/commands/OperatorPassCommands';+import styles from '@app/features/premium/components/operator_pass/OperatorPassPassItOnModal.module.css';+import {getOperatorPassErrorCode, getOperatorPassOfferUserName} from '@app/features/premium/utils/OperatorPassUtils';+import {remFromPx} from '@app/features/theme/layout/RemFromPx';+import * as ModalCommands from '@app/features/ui/commands/ModalCommands';+import {modal} from '@app/features/ui/commands/ModalCommands';+import * as ToastCommands from '@app/features/ui/commands/ToastCommands';+import {Input} from '@app/features/ui/components/form/FormInput';+import * as NicknameUtils from '@app/features/user/utils/NicknameUtils';+import {APIErrorCodes} from '@fluxer/constants/src/ApiErrorCodes';+import type {OperatorPassUnitResponse} from '@fluxer/schema/src/domains/operator_pass/OperatorPassSchemas';+import {msg} from '@lingui/core/macro';+import {useLingui} from '@lingui/react/macro';+import {MagnifyingGlassIcon} from '@phosphor-icons/react';+import {observer} from 'mobx-react-lite';+import {useMemo, useState} from 'react';++export const PASS_IT_ON_DESCRIPTOR = msg({+ message: 'Pass it on',+ comment:+ 'Button that offers one of your Operator Passes to another person, and the title of the dialog where you pick that person. Pass it on is the name of the feature, translate it as a short natural phrase for handing something on.',+});+const PASS_IT_ON_BODY_DESCRIPTOR = msg({+ message: 'Pick a friend to pass it on to. They can accept or decline, and you can take it back until it moves.',+ comment:+ 'Text in the dialog where you pick who gets one of your Operator Passes. Only friends can get a pass. They means the friend you pick. Take it back means canceling your offer. It moves means the pass moves to their account. Never word it as a present.',+});+const CHOOSE_DESCRIPTOR = msg({+ message: 'Choose',+ comment:+ 'Button next to a person in the list of people an Operator Pass can be passed on to, and next to the username field in the same dialog.',+});+const CONFIRM_TITLE_DESCRIPTOR = msg({+ message: 'Pass it on to {name}?',+ comment:+ 'Title of the confirmation before offering an Operator Pass to someone. {name} is the display name of that person.',+});+const CONFIRM_BODY_DESCRIPTOR = msg({+ message: 'It moves as soon as they accept. You can take it back until then.',+ comment:+ 'Body of the confirmation before offering an Operator Pass to someone. It is the pass, they is the person you offer it to. Take it back means canceling your offer.',+});+const CONFIRM_LAST_TITLE_DESCRIPTOR = msg({+ message: 'Pass on your last pass?',+ comment: 'Title of the confirmation before offering the only Operator Pass you have left to someone else.',+});+const CONFIRM_LAST_BODY_DESCRIPTOR = msg({+ message: 'Your badge and wall listing go as soon as {name} accepts.',+ comment:+ "Body of the confirmation before offering your last Operator Pass. The badge is the Operator badge, the wall listing is your entry on the Operators' wall. {name} is the display name of the person you offer it to.",+});+const CONFIRM_LAST_PRIMARY_DESCRIPTOR = msg({+ message: 'Pass on my last pass',+ comment: 'Button that confirms offering the only Operator Pass you have left to someone else.',+});+const SEND_OFFER_DESCRIPTOR = msg({+ message: 'Send offer',+ comment: 'Button that confirms offering an Operator Pass to someone. They can then accept or decline it.',+});+const LAST_PASS_NOW_DESCRIPTOR = msg({+ message: 'Your other passes are all on offer. This is your last one.',+ comment:+ 'Error after trying to pass on an Operator Pass when all your other passes are already offered to someone. A confirmation for passing on your last pass opens next.',+});+const OFFER_SENT_DESCRIPTOR = msg({+ message: 'Offer sent to {name}.',+ comment: 'Toast after offering an Operator Pass to someone. {name} is a display name.',+});+const NOT_TRANSFERABLE_DESCRIPTOR = msg({+ message: "Passes you received or got with Visionary can't be passed on.",+ comment:+ 'Error when you try to pass on an Operator Pass that cannot move. Visionary is a product name and stays untranslated.',+});+const OFFER_UNAVAILABLE_DESCRIPTOR = msg({+ message: 'This pass cannot be passed on to that account right now.',+ comment: 'Error when an Operator Pass cannot be offered to the chosen account right now.',+});+const NOT_FRIEND_DESCRIPTOR = msg({+ message: 'You can only pass this on to one of your friends on Fluxer.',+ comment: 'Error when you try to pass an Operator Pass on to someone you are not friends with.',+});+const NO_FRIENDS_DESCRIPTOR = msg({+ message: 'You can only pass a pass on to a friend. Add the person as a friend first, then come back here.',+ comment:+ 'Shown in the Pass it on dialog when you have no friends yet. Operator Passes can only go to friends so they cannot be sent to strangers.',+});+const OFFER_FAILED_DESCRIPTOR = msg({+ message: "Couldn't send the offer. Try again.",+ comment: 'Error when offering an Operator Pass failed for an unknown reason.',+});++function offerErrorMessage(error: unknown): typeof OFFER_FAILED_DESCRIPTOR {+ switch (getOperatorPassErrorCode(error)) {+ case APIErrorCodes.OPERATOR_PASS_NOT_TRANSFERABLE:+ return NOT_TRANSFERABLE_DESCRIPTOR;+ case APIErrorCodes.OPERATOR_PASS_RECIPIENT_NOT_FRIEND:+ return NOT_FRIEND_DESCRIPTOR;+ case APIErrorCodes.OPERATOR_PASS_OFFER_UNAVAILABLE:+ case APIErrorCodes.UNKNOWN_USER:+ return OFFER_UNAVAILABLE_DESCRIPTOR;+ default:+ return OFFER_FAILED_DESCRIPTOR;+ }+}++const OperatorPassPassItOnModal = observer(function OperatorPassPassItOnModalComponent({+ pass,+ onlyPass,+}: {+ pass: OperatorPassUnitResponse;+ onlyPass: boolean;+}) {+ const {i18n} = useLingui();+ const allRecipients = useRecipientItems();+ const recipients = useMemo(() => allRecipients.filter((item) => item.type !== 'group_dm'), [allRecipients]);+ const [searchQuery, setSearchQuery] = useState('');+ const handleChoose = (item: RecipientItem) => {+ confirm(NicknameUtils.getDisplayName(item.user), item.user.id, onlyPass);+ };+ const confirm = (name: string, recipientId: string, lastPass: boolean) => {+ ModalCommands.push(+ modal(() => (+ <ConfirmModal+ title={lastPass ? i18n._(CONFIRM_LAST_TITLE_DESCRIPTOR) : i18n._(CONFIRM_TITLE_DESCRIPTOR, {name})}+ description={i18n._(lastPass ? CONFIRM_LAST_BODY_DESCRIPTOR : CONFIRM_BODY_DESCRIPTOR, {name})}+ primaryText={i18n._(lastPass ? CONFIRM_LAST_PRIMARY_DESCRIPTOR : SEND_OFFER_DESCRIPTOR)}+ primaryVariant={lastPass ? 'danger' : 'primary'}+ onPrimary={async () => {+ try {+ const offer = await OperatorPassCommands.createOffer(pass.id, recipientId, lastPass);+ ToastCommands.success(+ i18n._(OFFER_SENT_DESCRIPTOR, {name: getOperatorPassOfferUserName(offer.recipient) || name}),+ );+ ModalCommands.popByType(OperatorPassPassItOnModal);+ } catch (error) {+ if (+ !lastPass &&+ getOperatorPassErrorCode(error) === APIErrorCodes.OPERATOR_PASS_LAST_PASS_CONFIRMATION_REQUIRED+ ) {+ ToastCommands.error(i18n._(LAST_PASS_NOW_DESCRIPTOR));+ confirm(name, recipientId, true);+ return;+ }+ ToastCommands.error(i18n._(offerErrorMessage(error)));+ }+ }}+ data-flx="premium.operator-pass-pass-it-on-modal.confirm-modal"+ />+ )),+ );+ };+ return (+ <Modal.Root+ size="small"+ centered+ className={styles.root}+ data-flx="premium.operator-pass-pass-it-on-modal.modal-root"+ >+ <Modal.Header+ title={i18n._(PASS_IT_ON_DESCRIPTOR)}+ data-flx="premium.operator-pass-pass-it-on-modal.modal-header"+ >+ <Modal.Description data-flx="premium.operator-pass-pass-it-on-modal.description">+ {i18n._(PASS_IT_ON_BODY_DESCRIPTOR)}+ </Modal.Description>+ <div className={selectorStyles.headerSearch} data-flx="premium.operator-pass-pass-it-on-modal.search">+ <Input+ value={searchQuery}+ onChange={(event) => setSearchQuery(event.target.value)}+ placeholder={i18n._(SEARCH_FRIENDS_DESCRIPTOR)}+ leftIcon={+ <MagnifyingGlassIcon+ size={remFromPx(20)}+ weight="bold"+ className={selectorStyles.searchIcon}+ data-flx="premium.operator-pass-pass-it-on-modal.search-icon"+ />+ }+ className={selectorStyles.headerSearchInput}+ data-flx="premium.operator-pass-pass-it-on-modal.input.search"+ />+ </div>+ </Modal.Header>+ <Modal.Content+ className={selectorStyles.selectorContent}+ data-flx="premium.operator-pass-pass-it-on-modal.modal-content"+ >+ <RecipientList+ recipients={recipients}+ sendingTo={new Set()}+ sentTo={new Map()}+ onSend={handleChoose}+ defaultButtonLabel={i18n._(CHOOSE_DESCRIPTOR)}+ scrollerKey="operator-pass-pass-it-on-modal-scroller"+ searchQuery={searchQuery}+ onSearchQueryChange={setSearchQuery}+ showSearchInput={false}+ emptyText={i18n._(NO_FRIENDS_DESCRIPTOR)}+ data-flx="premium.operator-pass-pass-it-on-modal.recipient-list"+ />+ </Modal.Content>+ <Modal.DismissFooter data-flx="premium.operator-pass-pass-it-on-modal.dismiss-footer" />+ </Modal.Root>+ );+});++export function openOperatorPassPassItOnModal(pass: OperatorPassUnitResponse, onlyPass: boolean): void {+ ModalCommands.push(+ modal(() => (+ <OperatorPassPassItOnModal+ pass={pass}+ onlyPass={onlyPass}+ data-flx="premium.operator-pass-pass-it-on-modal.open"+ />+ )),+ );+}