diff --git a/src/pages/superadmin/header/InviteModal.tsx b/src/pages/superadmin/header/InviteModal.tsx index 5a20fc3f..9175d089 100644 --- a/src/pages/superadmin/header/InviteModal.tsx +++ b/src/pages/superadmin/header/InviteModal.tsx @@ -1,7 +1,7 @@ import React, { useState } from 'react'; import { nonWidgetConfigs } from 'people/utils/Constants'; import { useIsMobile } from 'hooks/uiHooks'; -import { InvoiceForm, InvoiceInput, InvoiceLabel } from 'people/utils/style'; +import { InvoiceForm, InvoiceInput, InvoiceInputContainer, InvoiceLabel } from 'people/utils/style'; import styled from 'styled-components'; import { BudgetButton } from 'people/widgetViews/workspace/style'; import { useStores } from 'store'; @@ -32,15 +32,48 @@ const InviteModal = (props: InviteProps) => { const { open, close, addToast } = props; const [loading, setLoading] = useState(false); const [inviteNumber, setInviteNumber] = useState(1); + const [satAmount, setSatAmount] = useState(1); + const [pubkey, setPubkey] = useState(''); const config = nonWidgetConfigs['workspaceusers']; + const parsePubkey = (pubkey: string): { parsedPubkey: string; routeHint: string } => { + if (pubkey) { + const result = pubkey.split('_'); + if (result.length === 3) { + return { parsedPubkey: result[0], routeHint: `${result[1]}_${result[2]}` }; + } + } + return { parsedPubkey: '', routeHint: '' }; + }; + const createConnectionCode = async () => { setLoading(true); - const status = await main.createConnectionCodes(inviteNumber); + let extractedPubkey = ''; + let parsedRouteHint = ''; + + if (pubkey) { + const { parsedPubkey, routeHint } = parsePubkey(pubkey); + if (!parsedPubkey && !routeHint) { + setLoading(false); + if (addToast) addToast('Invalid Pubkey', 'error'); + return; + } + extractedPubkey = parsedPubkey; + parsedRouteHint = routeHint; + } + + const status = await main.createConnectionCodes({ + users_number: inviteNumber, + sats_amount: satAmount, + ...(extractedPubkey && + parsedRouteHint && { pubkey: extractedPubkey, route_hint: parsedRouteHint }) + }); if (status === 200) { if (addToast) addToast('Users invite code created successfully', 'success'); setInviteNumber(1); + setPubkey(''); + setSatAmount(1); close(); } else { if (addToast) addToast('Could not create users invite code', 'error'); @@ -80,22 +113,61 @@ const InviteModal = (props: InviteProps) => { Invite Users - - Number of users - - setInviteNumber(Number(e.target.value))} - /> + + + Number of users + + setInviteNumber(Number(e.target.value))} + /> + + + + + Pubkey + + setPubkey(e.target.value)} + /> + + + + Sats Amount + + setSatAmount(Number(e.target.value))} + /> + { + async createConnectionCodes({ + users_number, + sats_amount, + pubkey, + route_hint + }: { + users_number: number; + sats_amount?: number; + pubkey?: string; + route_hint?: string; + }): Promise { try { if (!uiStore.meInfo) return 406; const info = uiStore.meInfo; const data = { - number: users_number + number: users_number, + pubkey: pubkey, + route_hint, + sats_amount }; const body = JSON.stringify(data);