diff --git a/src/common/hooks/useOpenPortal.ts b/src/common/hooks/useOpenPortal.ts new file mode 100644 index 0000000000..68800f7e06 --- /dev/null +++ b/src/common/hooks/useOpenPortal.ts @@ -0,0 +1,77 @@ +/** + * Invoice Ninja (https://invoiceninja.com). + * + * @link https://github.com/invoiceninja/invoiceninja source repository + * + * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com) + * + * @license https://www.elastic.co/licensing/elastic-license + */ + +import { AxiosError, AxiosResponse } from 'axios'; +import { endpoint } from '$app/common/helpers'; +import { request } from '$app/common/helpers/request'; +import { toast } from '$app/common/helpers/toast/toast'; +import { ValidationBag } from '$app/common/interfaces/validation-bag'; + +export type PortalEntity = + | 'invoice' + | 'quote' + | 'credit' + | 'recurring_invoice' + | 'purchase_order'; + +export type PortalTarget = + | { entity: PortalEntity; key: string } + | { contact_key: string }; + +export function useOpenPortal() { + return (target: PortalTarget) => { + const key = 'contact_key' in target ? target.contact_key : target.key; + + if (!key) { + return; + } + + const tab = window.open('', '_blank'); + + if (tab) { + tab.opener = null; + } + + request('POST', endpoint('/api/v1/one_time_token/temporary_url'), { + context: 'portal', + ...target, + }) + .then((response: AxiosResponse) => { + const url = + typeof response?.data === 'string' ? response.data.trim() : ''; + + if (!url.startsWith('http')) { + tab?.close(); + + if (response) { + toast.error(); + } + + return; + } + + if (tab) { + tab.location.replace(url); + } else { + window.open(url, '_blank', 'noopener'); + } + }) + .catch((error: AxiosError) => { + tab?.close(); + + if (error.response?.status === 422) { + const [message] = + Object.values(error.response.data.errors ?? {})[0] ?? []; + + toast.error(message ?? error.response.data.message); + } + }); + }; +} diff --git a/src/common/interfaces/company.interface.ts b/src/common/interfaces/company.interface.ts index 32120bedd3..cf56095b8e 100644 --- a/src/common/interfaces/company.interface.ts +++ b/src/common/interfaces/company.interface.ts @@ -118,6 +118,8 @@ export interface Settings { show_all_tasks_client_portal: string; enable_client_portal_password: boolean; enable_client_portal: boolean; + enable_portal_key_login: boolean; + portal_link_otp_after_days: number; enable_client_portal_dashboard: boolean; signature_on_pdf: boolean; document_email_attachment: boolean; diff --git a/src/components/OpenPortalLink.tsx b/src/components/OpenPortalLink.tsx new file mode 100644 index 0000000000..2ad7300e31 --- /dev/null +++ b/src/components/OpenPortalLink.tsx @@ -0,0 +1,48 @@ +/** + * Invoice Ninja (https://invoiceninja.com). + * + * @link https://github.com/invoiceninja/invoiceninja source repository + * + * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com) + * + * @license https://www.elastic.co/licensing/elastic-license + */ + +import classNames from 'classnames'; +import { ReactNode } from 'react'; +import { useAccentColor } from '$app/common/hooks/useAccentColor'; +import { PortalTarget, useOpenPortal } from '$app/common/hooks/useOpenPortal'; +import { ExternalLink } from './icons/ExternalLink'; + +interface Props { + target: PortalTarget; + children: ReactNode; + className?: string; + withExternalIcon?: boolean; +} + +export function OpenPortalLink(props: Props) { + const { target, children, className, withExternalIcon } = props; + + const accentColor = useAccentColor(); + const openPortal = useOpenPortal(); + + return ( +
+ {withExternalIcon && ( +
+ +
+ )} + + +
+ ); +} diff --git a/src/pages/clients/common/components/ClientSlider.tsx b/src/pages/clients/common/components/ClientSlider.tsx index aa37ea2ffe..f3280d1a7b 100644 --- a/src/pages/clients/common/components/ClientSlider.tsx +++ b/src/pages/clients/common/components/ClientSlider.tsx @@ -21,6 +21,7 @@ import { Slider } from '$app/components/cards/Slider'; import { CopyToClipboardIconOnly } from '$app/components/CopyToClipBoardIconOnly'; import { EntityStatus } from '$app/components/EntityStatus'; import { Button, Link } from '$app/components/forms'; +import { OpenPortalLink } from '$app/components/OpenPortalLink'; import { ResourceActions } from '$app/components/ResourceActions'; import { Spinner } from '$app/components/Spinner'; import { Tooltip } from '$app/components/Tooltip'; @@ -383,16 +384,11 @@ export function ClientSlider() { )}
- {t('client_portal')} - + - +
diff --git a/src/pages/clients/common/hooks/useActions.tsx b/src/pages/clients/common/hooks/useActions.tsx index 7ed310ec9e..1bee8f9524 100644 --- a/src/pages/clients/common/hooks/useActions.tsx +++ b/src/pages/clients/common/hooks/useActions.tsx @@ -27,6 +27,7 @@ import { route } from '$app/common/helpers/route'; import { useAdmin } from '$app/common/hooks/permissions/useHasPermission'; import { useDisplayRunTemplateActions } from '$app/common/hooks/useDisplayRunTemplateActions'; import { useEntityPageIdentifier } from '$app/common/hooks/useEntityPageIdentifier'; +import { useOpenPortal } from '$app/common/hooks/useOpenPortal'; import { Client } from '$app/common/interfaces/client'; import { useBulk } from '$app/common/queries/clients'; import { Divider } from '$app/components/cards/Divider'; @@ -60,6 +61,7 @@ export function useActions(params?: Params) { }); const configureClientSettings = useConfigureClientSettings(); + const openPortal = useOpenPortal(); const { setChangeTemplateVisible, @@ -91,15 +93,7 @@ export function useActions(params?: Params) { Boolean(!client.is_deleted && !isShowPage) && ( - window.open( - route( - `${client.contacts[0].link}?silent=true&client_hash=:clientHash`, - { - clientHash: client.client_hash, - } - ), - '__blank' - ) + openPortal({ contact_key: client.contacts[0]?.contact_key ?? '' }) } icon={} > diff --git a/src/pages/clients/show/components/Contacts.tsx b/src/pages/clients/show/components/Contacts.tsx index 78155e3a72..f91a85c1e8 100644 --- a/src/pages/clients/show/components/Contacts.tsx +++ b/src/pages/clients/show/components/Contacts.tsx @@ -10,14 +10,13 @@ import { useTranslation } from 'react-i18next'; import { useColorScheme } from '$app/common/colors'; -import { route } from '$app/common/helpers/route'; import { useFormatCustomFieldValue } from '$app/common/hooks/useFormatCustomFieldValue'; import { Client } from '$app/common/interfaces/client'; import { ClientContact } from '$app/common/interfaces/client-contact'; import { CopyToClipboardIconOnly } from '$app/components/CopyToClipBoardIconOnly'; import { CustomFields, useCustomField } from '$app/components/CustomField'; -import { Link } from '$app/components/forms'; import { InfoCard } from '$app/components/InfoCard'; +import { OpenPortalLink } from '$app/components/OpenPortalLink'; import { Tooltip } from '$app/components/Tooltip'; import { UserUnsubscribedTooltip } from '../../common/components/UserUnsubscribedTooltip'; @@ -148,19 +147,11 @@ export function Contacts(props: Props) { })}
- {t('client_portal')} - + - +
diff --git a/src/pages/credits/common/components/CreditSlider.tsx b/src/pages/credits/common/components/CreditSlider.tsx index 0454e99920..8d33dc8d1d 100644 --- a/src/pages/credits/common/components/CreditSlider.tsx +++ b/src/pages/credits/common/components/CreditSlider.tsx @@ -43,10 +43,6 @@ import { DynamicLink } from '$app/components/DynamicLink'; import { useActions } from '../hooks'; import { CreditStatus } from './CreditStatus'; import { Credit } from '$app/common/interfaces/credit'; -import { - generateClientPortalUrl, - openClientPortal, -} from '$app/pages/invoices/common/helpers/open-client-portal'; import { EmailRecord } from '$app/components/EmailRecord'; import { useEffect, useState } from 'react'; import { EmailRecord as EmailRecordType } from '$app/common/interfaces/email-history'; @@ -64,6 +60,7 @@ import { useGetSetting } from '$app/common/hooks/useGetSetting'; import { useGetTimezone } from '$app/common/hooks/useGetTimezone'; import classNames from 'classnames'; import { useReactSettings } from '$app/common/hooks/useReactSettings'; +import { useOpenPortal } from '$app/common/hooks/useOpenPortal'; import styled from 'styled-components'; import { useNavigate } from 'react-router-dom'; import { CloudPlay } from '$app/components/icons/CloudPlay'; @@ -91,6 +88,7 @@ const Box = styled.div` export function CreditSlider() { const invoicePaths = useInvoiceEditorPaths(); const [t] = useTranslation(); + const openPortal = useOpenPortal(); const queryClient = useQueryClient(); const navigate = useNavigate(); @@ -287,7 +285,14 @@ export function CreditSlider() {
(credit ? openClientPortal(credit) : null)} + onClick={() => + credit + ? openPortal({ + entity: 'credit', + key: credit.invitations[0]?.key ?? '', + }) + : null + } style={{ borderColor: colors.$20, }} @@ -315,7 +320,7 @@ export function CreditSlider() { className="flex flex-col items-center justify-center space-y-2 shadow-sm border px-14 py-5 cursor-pointer rounded-md" onClick={() => { navigator.clipboard.writeText( - generateClientPortalUrl(credit) ?? '' + credit.invitations[0]?.link ?? '' ); toast.success('copied_to_clipboard', { value: '' }); diff --git a/src/pages/credits/common/hooks.tsx b/src/pages/credits/common/hooks.tsx index c8e6ec03ae..a658d1788b 100644 --- a/src/pages/credits/common/hooks.tsx +++ b/src/pages/credits/common/hooks.tsx @@ -30,7 +30,6 @@ import { ValidationBag } from '$app/common/interfaces/validation-bag'; import { Divider } from '$app/components/cards/Divider'; import { Action } from '$app/components/ResourceActions'; import { useAtom, useSetAtom } from 'jotai'; -import { openClientPortal } from '$app/pages/invoices/common/helpers/open-client-portal'; import { useDownloadPdf } from '$app/pages/invoices/common/hooks/useDownloadPdf'; import { DataTableColumnsExtended, @@ -102,6 +101,7 @@ import classNames from 'classnames'; import { Dispatch, SetStateAction } from 'react'; import { normalizeColumnName } from '$app/common/helpers/data-table'; import { useDisplayRunTemplateActions } from '$app/common/hooks/useDisplayRunTemplateActions'; +import { useOpenPortal } from '$app/common/hooks/useOpenPortal'; import { TagPills } from '$app/components/tags/TagPills'; import { PeppolSendingStatus } from '$app/components/e-invoice/PeppolSendingStatus'; import { useColorScheme } from '$app/common/colors'; @@ -413,6 +413,7 @@ interface Params { export function useActions(params?: Params) { const [t] = useTranslation(); + const openPortal = useOpenPortal(); const hasPermission = useHasPermission(); @@ -580,7 +581,13 @@ export function useActions(params?: Params) { actionKey="client_portal" isCommonActionSection={!dropdown} tooltipText={t('client_portal')} - onClick={() => credit && openClientPortal(credit)} + onClick={() => + credit && + openPortal({ + entity: 'credit', + key: credit.invitations[0]?.key ?? '', + }) + } icon={MdCloudCircle} disablePreventNavigation > diff --git a/src/pages/credits/create/components/CreatePage.tsx b/src/pages/credits/create/components/CreatePage.tsx index f5dea54e60..3d5839f441 100644 --- a/src/pages/credits/create/components/CreatePage.tsx +++ b/src/pages/credits/create/components/CreatePage.tsx @@ -80,6 +80,7 @@ export default function CreatePage() { style={{ borderColor: colors.$24 }} > handleClientChange(id)} onLocationChange={(id) => handleChange('location_id', id)} diff --git a/src/pages/credits/edit/Edit.tsx b/src/pages/credits/edit/Edit.tsx index 346e59f808..7a4ffc117d 100644 --- a/src/pages/credits/edit/Edit.tsx +++ b/src/pages/credits/edit/Edit.tsx @@ -78,6 +78,7 @@ export default function Edit() { )} handleChange('client_id', id)} onClearButtonClick={() => handleChange('client_id', '')} diff --git a/src/pages/invoices/common/components/ClientSelector.tsx b/src/pages/invoices/common/components/ClientSelector.tsx index a6eccb0f3a..2a54208a73 100644 --- a/src/pages/invoices/common/components/ClientSelector.tsx +++ b/src/pages/invoices/common/components/ClientSelector.tsx @@ -20,6 +20,7 @@ import { useTranslation } from 'react-i18next'; import { useColorScheme } from '$app/common/colors'; import { useClientResolver } from '$app/common/hooks/clients/useClientResolver'; import { useCurrentCompany } from '$app/common/hooks/useCurrentCompany'; +import { PortalEntity } from '$app/common/hooks/useOpenPortal'; import { useReactSettings } from '$app/common/hooks/useReactSettings'; import { Client } from '$app/common/interfaces/client'; import { Invoice } from '$app/common/interfaces/invoice'; @@ -27,7 +28,8 @@ import { RecurringInvoice } from '$app/common/interfaces/recurring-invoice'; import { CopyToClipboardIconOnly } from '$app/components/CopyToClipBoardIconOnly'; import { Element } from '$app/components/cards'; import { ClientSelector as Selector } from '$app/components/clients/ClientSelector'; -import { Checkbox, InputLabel, Link, SelectField } from '$app/components/forms'; +import { Checkbox, InputLabel, SelectField } from '$app/components/forms'; +import { OpenPortalLink } from '$app/components/OpenPortalLink'; import { Tooltip } from '$app/components/Tooltip'; import { UserUnsubscribedTooltip } from '$app/pages/clients/common/components/UserUnsubscribedTooltip'; import { ClientActionButtons } from './ClientActionButtons'; @@ -35,6 +37,7 @@ import { ClientActionButtons } from './ClientActionButtons'; interface Props { readonly?: boolean; resource?: Invoice | RecurringInvoice; + portalEntity: Exclude; onChange: (id: string) => unknown; onClearButtonClick: () => unknown; onContactCheckboxChange: (contactId: string, value: boolean) => unknown; @@ -283,13 +286,16 @@ export function ClientSelector(props: Props) { return ( Boolean(contactInvitation?.link) && (
- {t('view_in_portal')} - + (null); export const invoiceSliderVisibilityAtom = atom(false); @@ -214,6 +211,7 @@ export function InvoiceSlider() { const [isVisible, setIsSliderVisible] = useAtom(invoiceSliderVisibilityAtom); const [invoice, setInvoice] = useAtom(invoiceSliderAtom); const [t] = useTranslation(); + const openPortal = useOpenPortal(); const colors = useColorScheme(); const reactSettings = useReactSettings(); @@ -443,7 +441,14 @@ export function InvoiceSlider() {
(invoice ? openClientPortal(invoice) : null)} + onClick={() => + invoice + ? openPortal({ + entity: 'invoice', + key: invoice.invitations[0]?.key ?? '', + }) + : null + } style={{ borderColor: colors.$20, }} @@ -471,7 +476,7 @@ export function InvoiceSlider() { className="flex flex-col items-center justify-center space-y-2 shadow-sm border px-14 py-5 cursor-pointer rounded-md" onClick={() => { navigator.clipboard.writeText( - generateClientPortalUrl(invoice) ?? '' + invoice.invitations[0]?.link ?? '' ); toast.success('copied_to_clipboard', { value: '' }); diff --git a/src/pages/invoices/common/helpers/open-client-portal.ts b/src/pages/invoices/common/helpers/open-client-portal.ts deleted file mode 100644 index 3427f30d4c..0000000000 --- a/src/pages/invoices/common/helpers/open-client-portal.ts +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Invoice Ninja (https://invoiceninja.com). - * - * @link https://github.com/invoiceninja/invoiceninja source repository - * - * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com) - * - * @license https://www.elastic.co/licensing/elastic-license - */ - -import { Client } from '$app/common/interfaces/client'; -import { Credit } from '$app/common/interfaces/credit'; -import { Invoice } from '$app/common/interfaces/invoice'; -import { PurchaseOrder } from '$app/common/interfaces/purchase-order'; -import { Quote } from '$app/common/interfaces/quote'; -import { RecurringInvoice } from '$app/common/interfaces/recurring-invoice'; - -export function generateClientPortalUrl( - resource: Invoice | RecurringInvoice | Quote | Credit | PurchaseOrder -) { - if (resource.invitations.length > 0) { - const client = resource['client' as keyof typeof resource] - ? (resource['client' as keyof typeof resource] as unknown as Client) - : ''; - - return `${resource.invitations[0].link}?silent=true${ - client ? `&client_hash=${client.client_hash}` : '' - }`; - } - - return null; -} - -export function openClientPortal( - resource: Invoice | RecurringInvoice | Quote | Credit | PurchaseOrder -) { - const url = generateClientPortalUrl(resource); - - if (url) { - window.open(url, '_blank')?.focus(); - } -} diff --git a/src/pages/invoices/create/components/CreatePage.tsx b/src/pages/invoices/create/components/CreatePage.tsx index cce8582605..dc92b6ecf2 100644 --- a/src/pages/invoices/create/components/CreatePage.tsx +++ b/src/pages/invoices/create/components/CreatePage.tsx @@ -98,6 +98,7 @@ export default function CreatePage() { style={{ borderColor: colors.$24 }} > handleChange('client_id', id)} onLocationChange={(id) => handleChange('location_id', id)} diff --git a/src/pages/invoices/edit/Edit.tsx b/src/pages/invoices/edit/Edit.tsx index d1bfff460f..bea908d672 100644 --- a/src/pages/invoices/edit/Edit.tsx +++ b/src/pages/invoices/edit/Edit.tsx @@ -250,6 +250,7 @@ export default function Edit() { /> handleChange('client_id', id)} onClearButtonClick={() => handleChange('client_id', '')} diff --git a/src/pages/invoices/edit/components/Actions.tsx b/src/pages/invoices/edit/components/Actions.tsx index b5f9aed682..7631f19f6e 100644 --- a/src/pages/invoices/edit/components/Actions.tsx +++ b/src/pages/invoices/edit/components/Actions.tsx @@ -43,6 +43,7 @@ import { useCompanyVerifactu } from '$app/common/hooks/useCompanyVerifactu'; import { useCurrentCompany } from '$app/common/hooks/useCurrentCompany'; import { useDisplayRunTemplateActions } from '$app/common/hooks/useDisplayRunTemplateActions'; import { useEntityPageIdentifier } from '$app/common/hooks/useEntityPageIdentifier'; +import { useOpenPortal } from '$app/common/hooks/useOpenPortal'; import { Invoice } from '$app/common/interfaces/invoice'; import { useBulk } from '$app/common/queries/invoices'; import { Divider } from '$app/components/cards/Divider'; @@ -52,7 +53,6 @@ import { Icon } from '$app/components/icons/Icon'; import { useShouldDisplayClientGatewaysAndAutoBill } from '$app/pages/clients/show/hooks/useShouldDisplayClientGatewaysAndAutoBill'; import { AddActivityComment } from '$app/pages/dashboard/hooks/useGenerateActivityElement'; import { invoiceAtom } from '$app/pages/invoices/common/atoms'; -import { openClientPortal } from '$app/pages/invoices/common/helpers/open-client-portal'; import { useDownloadEInvoice } from '$app/pages/invoices/common/hooks/useDownloadEInvoice'; import { useDownloadPdf } from '$app/pages/invoices/common/hooks/useDownloadPdf'; import { usePrintPdf } from '$app/pages/invoices/common/hooks/usePrintPdf'; @@ -88,6 +88,7 @@ interface Params { export function useActions(params?: Params) { const invoicePaths = useInvoiceEditorPaths(); const { t } = useTranslation(); + const openPortal = useOpenPortal(); const { showEditAction, @@ -392,7 +393,13 @@ export function useActions(params?: Params) { actionKey="client_portal" isCommonActionSection={!dropdown} tooltipText={t('client_portal')} - onClick={() => invoice && openClientPortal(invoice)} + onClick={() => + invoice && + openPortal({ + entity: 'invoice', + key: invoice.invitations[0]?.key ?? '', + }) + } icon={MdCloudCircle} disablePreventNavigation > diff --git a/src/pages/purchase-orders/common/components/PurchaseOrderSlider.tsx b/src/pages/purchase-orders/common/components/PurchaseOrderSlider.tsx index e8849edf41..fbad909af2 100644 --- a/src/pages/purchase-orders/common/components/PurchaseOrderSlider.tsx +++ b/src/pages/purchase-orders/common/components/PurchaseOrderSlider.tsx @@ -43,10 +43,6 @@ import { useActions } from '../hooks'; import { PurchaseOrderStatus } from './PurchaseOrderStatus'; import { PurchaseOrder } from '$app/common/interfaces/purchase-order'; import { Client } from '$app/common/interfaces/client'; -import { - generateClientPortalUrl, - openClientPortal, -} from '$app/pages/invoices/common/helpers/open-client-portal'; import { EmailRecord } from '$app/components/EmailRecord'; import { useEffect, useState } from 'react'; import { EmailRecord as EmailRecordType } from '$app/common/interfaces/email-history'; @@ -61,6 +57,7 @@ import { useColorScheme } from '$app/common/colors'; import { useCompanyTimeFormat } from '$app/common/hooks/useCompanyTimeFormat'; import classNames from 'classnames'; import { useReactSettings } from '$app/common/hooks/useReactSettings'; +import { useOpenPortal } from '$app/common/hooks/useOpenPortal'; import styled from 'styled-components'; import { useNavigate } from 'react-router-dom'; import { CloudPlay } from '$app/components/icons/CloudPlay'; @@ -87,6 +84,7 @@ const Box = styled.div` export function PurchaseOrderSlider() { const [t] = useTranslation(); + const openPortal = useOpenPortal(); const queryClient = useQueryClient(); const navigate = useNavigate(); @@ -296,7 +294,12 @@ export function PurchaseOrderSlider() { - purchaseOrder ? openClientPortal(purchaseOrder) : null + purchaseOrder + ? openPortal({ + entity: 'purchase_order', + key: purchaseOrder.invitations[0]?.key ?? '', + }) + : null } style={{ borderColor: colors.$20, @@ -325,7 +328,7 @@ export function PurchaseOrderSlider() { className="flex flex-col items-center justify-center space-y-2 shadow-sm border px-14 py-5 cursor-pointer rounded-md" onClick={() => { navigator.clipboard.writeText( - generateClientPortalUrl(purchaseOrder) ?? '' + purchaseOrder.invitations[0]?.link ?? '' ); toast.success('copied_to_clipboard', { value: '' }); diff --git a/src/pages/purchase-orders/common/hooks.tsx b/src/pages/purchase-orders/common/hooks.tsx index 2d159a2c63..4bbb693205 100644 --- a/src/pages/purchase-orders/common/hooks.tsx +++ b/src/pages/purchase-orders/common/hooks.tsx @@ -58,6 +58,7 @@ import { useFormatNumber } from '$app/common/hooks/useFormatNumber'; import { useReactSettings } from '$app/common/hooks/useReactSettings'; import { $refetch } from '$app/common/hooks/useRefetch'; import { useRefreshCompanyUsers } from '$app/common/hooks/useRefreshCompanyUsers'; +import { useOpenPortal } from '$app/common/hooks/useOpenPortal'; import { GenericSingleResourceResponse } from '$app/common/interfaces/generic-api-response'; import { PurchaseOrder } from '$app/common/interfaces/purchase-order'; import { ValidationBag } from '$app/common/interfaces/validation-bag'; @@ -77,7 +78,6 @@ import { TagPills } from '$app/components/tags/TagPills'; import { Tooltip } from '$app/components/Tooltip'; import { AddActivityComment } from '$app/pages/dashboard/hooks/useGenerateActivityElement'; import { isDeleteActionTriggeredAtom } from '$app/pages/invoices/common/components/ProductsTable'; -import { openClientPortal } from '$app/pages/invoices/common/helpers/open-client-portal'; import { useDownloadEInvoice } from '$app/pages/invoices/common/hooks/useDownloadEInvoice'; import { useDownloadPdf } from '$app/pages/invoices/common/hooks/useDownloadPdf'; import { DataTableColumnsExtended } from '$app/pages/invoices/common/hooks/useInvoiceColumns'; @@ -559,6 +559,7 @@ export function useActions(params: ActionsParams = {}) { const { showEditAction, showCommonBulkAction, dropdown = true } = params; const [t] = useTranslation(); + const openPortal = useOpenPortal(); const company = useCurrentCompany(); const { isAdmin, isOwner } = useAdmin(); @@ -795,7 +796,12 @@ export function useActions(params: ActionsParams = {}) { actionKey="vendor_portal" isCommonActionSection={!dropdown} tooltipText={t('vendor_portal')} - onClick={() => openClientPortal(purchaseOrder)} + onClick={() => + openPortal({ + entity: 'purchase_order', + key: purchaseOrder.invitations[0]?.key ?? '', + }) + } icon={MdCloudCircle} disablePreventNavigation > diff --git a/src/pages/purchase-orders/edit/components/VendorSelector.tsx b/src/pages/purchase-orders/edit/components/VendorSelector.tsx index 8006d21121..d6f073467f 100644 --- a/src/pages/purchase-orders/edit/components/VendorSelector.tsx +++ b/src/pages/purchase-orders/edit/components/VendorSelector.tsx @@ -21,6 +21,7 @@ import { PurchaseOrder } from '$app/common/interfaces/purchase-order'; import { Vendor } from '$app/common/interfaces/vendor'; import { CopyToClipboardIconOnly } from '$app/components/CopyToClipBoardIconOnly'; import { Checkbox, InputLabel, Link } from '$app/components/forms'; +import { OpenPortalLink } from '$app/components/OpenPortalLink'; import { Tooltip } from '$app/components/Tooltip'; import { VendorSelector as Selector } from '$app/components/vendors/VendorSelector'; @@ -246,13 +247,16 @@ export function VendorSelector(props: Props) { return ( Boolean(contactInvitation?.link) && (
- {t('view_in_portal')} - + (null); export const quoteSliderVisibilityAtom = atom(false); @@ -148,6 +145,7 @@ export function useGenerateActivityElement() { export function QuoteSlider() { const invoicePaths = useInvoiceEditorPaths(); const [t] = useTranslation(); + const openPortal = useOpenPortal(); const queryClient = useQueryClient(); const navigate = useNavigate(); @@ -358,7 +356,14 @@ export function QuoteSlider() {
(quote ? openClientPortal(quote) : null)} + onClick={() => + quote + ? openPortal({ + entity: 'quote', + key: quote.invitations[0]?.key ?? '', + }) + : null + } style={{ borderColor: colors.$20, }} @@ -386,7 +391,7 @@ export function QuoteSlider() { className="flex flex-col items-center justify-center space-y-2 shadow-sm border px-14 py-5 cursor-pointer rounded-md" onClick={() => { navigator.clipboard.writeText( - generateClientPortalUrl(quote) ?? '' + quote.invitations[0]?.link ?? '' ); toast.success('copied_to_clipboard', { value: '' }); diff --git a/src/pages/quotes/common/hooks.tsx b/src/pages/quotes/common/hooks.tsx index 9478765569..18f311b9ec 100644 --- a/src/pages/quotes/common/hooks.tsx +++ b/src/pages/quotes/common/hooks.tsx @@ -63,6 +63,7 @@ import { $refetch } from '$app/common/hooks/useRefetch'; import { useRefreshCompanyUsers } from '$app/common/hooks/useRefreshCompanyUsers'; import { useResolveCountry } from '$app/common/hooks/useResolveCountry'; import { useResolveCurrency } from '$app/common/hooks/useResolveCurrency'; +import { useOpenPortal } from '$app/common/hooks/useOpenPortal'; import { Client } from '$app/common/interfaces/client'; import { GenericSingleResourceResponse } from '$app/common/interfaces/generic-api-response'; import { @@ -89,7 +90,6 @@ import { TagPills } from '$app/components/tags/TagPills'; import { calculateNetAmount } from '$app/common/helpers/invoices/net-amount'; import { AddActivityComment } from '$app/pages/dashboard/hooks/useGenerateActivityElement'; import { isDeleteActionTriggeredAtom } from '$app/pages/invoices/common/components/ProductsTable'; -import { openClientPortal } from '$app/pages/invoices/common/helpers/open-client-portal'; import { useDownloadEInvoice } from '$app/pages/invoices/common/hooks/useDownloadEInvoice'; import { useDownloadPdf } from '$app/pages/invoices/common/hooks/useDownloadPdf'; import { DataTableColumnsExtended } from '$app/pages/invoices/common/hooks/useInvoiceColumns'; @@ -431,6 +431,7 @@ interface Params { } export function useActions(params?: Params) { const [t] = useTranslation(); + const openPortal = useOpenPortal(); const { showCommonBulkAction, @@ -604,7 +605,13 @@ export function useActions(params?: Params) { actionKey="client_portal" isCommonActionSection={!dropdown} tooltipText={t('client_portal')} - onClick={() => quote && openClientPortal(quote)} + onClick={() => + quote && + openPortal({ + entity: 'quote', + key: quote.invitations[0]?.key ?? '', + }) + } icon={MdCloudCircle} disablePreventNavigation > diff --git a/src/pages/quotes/create/components/CreatePage.tsx b/src/pages/quotes/create/components/CreatePage.tsx index daeecd0115..581d571b69 100644 --- a/src/pages/quotes/create/components/CreatePage.tsx +++ b/src/pages/quotes/create/components/CreatePage.tsx @@ -81,6 +81,7 @@ export default function CreatePage() { style={{ borderColor: colors.$24 }} > handleChange('client_id', id)} onLocationChange={(id) => handleChange('location_id', id)} diff --git a/src/pages/quotes/edit/Edit.tsx b/src/pages/quotes/edit/Edit.tsx index 4b85c4257f..5f3a4c0cff 100644 --- a/src/pages/quotes/edit/Edit.tsx +++ b/src/pages/quotes/edit/Edit.tsx @@ -124,6 +124,7 @@ export default function Edit() { )} handleChange('client_id', id)} onClearButtonClick={() => handleChange('client_id', '')} diff --git a/src/pages/recurring-invoices/common/components/RecurringInvoiceSlider.tsx b/src/pages/recurring-invoices/common/components/RecurringInvoiceSlider.tsx index 33ff6f4273..d39de1b000 100644 --- a/src/pages/recurring-invoices/common/components/RecurringInvoiceSlider.tsx +++ b/src/pages/recurring-invoices/common/components/RecurringInvoiceSlider.tsx @@ -32,10 +32,6 @@ import relativeTime from 'dayjs/plugin/relativeTime'; import { route } from '$app/common/helpers/route'; import reactStringReplace from 'react-string-replace'; import { useActions } from '../hooks'; -import { - generateClientPortalUrl, - openClientPortal, -} from '$app/pages/invoices/common/helpers/open-client-portal'; import { RecurringInvoice } from '$app/common/interfaces/recurring-invoice'; import { RecurringInvoiceStatus } from './RecurringInvoiceStatus'; import { ViewLineItem } from '$app/pages/invoices/common/components/ViewLineItem'; @@ -67,6 +63,7 @@ import { DocumentsTable } from '$app/components/DocumentsTable'; import { DocumentsTabLabel } from '$app/components/DocumentsTabLabel'; import { Upload } from '$app/pages/settings/company/documents/components'; import { $refetch } from '$app/common/hooks/useRefetch'; +import { useOpenPortal } from '$app/common/hooks/useOpenPortal'; export const recurringInvoiceSliderAtom = atom(null); export const recurringInvoiceSliderVisibilityAtom = atom(false); @@ -143,6 +140,7 @@ export const RecurringInvoiceSlider = () => { recurringInvoiceSliderAtom ); const [t] = useTranslation(); + const openPortal = useOpenPortal(); const colors = useColorScheme(); const navigate = useNavigate(); @@ -378,7 +376,12 @@ export const RecurringInvoiceSlider = () => { - recurringInvoice ? openClientPortal(recurringInvoice) : null + recurringInvoice + ? openPortal({ + entity: 'recurring_invoice', + key: recurringInvoice.invitations[0]?.key ?? '', + }) + : null } style={{ borderColor: colors.$20, @@ -407,7 +410,7 @@ export const RecurringInvoiceSlider = () => { className="flex flex-col items-center justify-center space-y-2 shadow-sm border px-14 py-5 cursor-pointer rounded-md" onClick={() => { navigator.clipboard.writeText( - generateClientPortalUrl(recurringInvoice) ?? '' + recurringInvoice.invitations[0]?.link ?? '' ); toast.success('copied_to_clipboard', { value: '' }); diff --git a/src/pages/recurring-invoices/create/components/CreatePage.tsx b/src/pages/recurring-invoices/create/components/CreatePage.tsx index f23722fe39..ad2a4f17fe 100644 --- a/src/pages/recurring-invoices/create/components/CreatePage.tsx +++ b/src/pages/recurring-invoices/create/components/CreatePage.tsx @@ -64,6 +64,7 @@ export default function CreatePage() { style={{ borderColor: colors.$24 }} > handleChange('client_id', id)} onLocationChange={(id) => handleChange('location_id', id)} diff --git a/src/pages/recurring-invoices/edit/Edit.tsx b/src/pages/recurring-invoices/edit/Edit.tsx index b8a4505886..5a2b0006ef 100644 --- a/src/pages/recurring-invoices/edit/Edit.tsx +++ b/src/pages/recurring-invoices/edit/Edit.tsx @@ -109,6 +109,7 @@ export default function Edit() { )} handleChange('client_id', id)} onClearButtonClick={() => handleChange('client_id', '')} diff --git a/src/pages/settings/client-portal/components/Authorization.tsx b/src/pages/settings/client-portal/components/Authorization.tsx index 74047836be..3b532e7d8a 100644 --- a/src/pages/settings/client-portal/components/Authorization.tsx +++ b/src/pages/settings/client-portal/components/Authorization.tsx @@ -8,15 +8,20 @@ * @license https://www.elastic.co/licensing/elastic-license */ +import { useAtomValue } from 'jotai'; import { useTranslation } from 'react-i18next'; import { useColorScheme } from '$app/common/colors'; import { useCompanyChanges } from '$app/common/hooks/useCompanyChanges'; +import { useCurrentSettingsLevel } from '$app/common/hooks/useCurrentSettingsLevel'; import { useDisableSettingsField } from '$app/common/hooks/useDisableSettingsField'; +import { Alert } from '$app/components/Alert'; import { Element } from '$app/components/cards'; import { Divider } from '$app/components/cards/Divider'; +import { NumberInputField } from '$app/components/forms/NumberInputField'; import Toggle from '$app/components/forms/Toggle'; import { PropertyCheckbox } from '$app/components/PropertyCheckbox'; import { SettingsLabel } from '$app/components/SettingsLabel'; +import { companySettingsErrorsAtom } from '$app/pages/settings/common/atoms'; import { useHandleCurrentCompanyChangeProperty } from '$app/pages/settings/common/hooks/useHandleCurrentCompanyChange'; export function Authorization() { @@ -24,6 +29,8 @@ export function Authorization() { const colors = useColorScheme(); const company = useCompanyChanges(); + const errors = useAtomValue(companySettingsErrorsAtom); + const { isCompanySettingsActive } = useCurrentSettingsLevel(); const disableSettingsField = useDisableSettingsField(); const handleChange = useHandleCurrentCompanyChangeProperty(); @@ -198,6 +205,60 @@ export function Authorization() { disabled={disableSettingsField('signature_on_pdf')} /> + + {isCompanySettingsActive && ( +
+ +
+ )} + + {isCompanySettingsActive && ( + + + handleChange('settings.enable_portal_key_login', value) + } + /> + + )} + + {isCompanySettingsActive && + Boolean(company?.settings.enable_portal_key_login) && ( +
+ + {t('enable_portal_key_login_warning')} + +
+ )} + + {isCompanySettingsActive && ( + + + handleChange( + 'settings.portal_link_otp_after_days', + parseFloat(value) || 0 + ) + } + placeholder="0" + errorMessage={errors?.errors['settings.portal_link_otp_after_days']} + disablePrecision + /> + + )} ); }