From 183e725aceb96c2aa4e99253d14c42a0aa2c43a2 Mon Sep 17 00:00:00 2001 From: bdebon Date: Thu, 24 Nov 2022 14:13:27 +0100 Subject: [PATCH] fix(ports): adding info tooltip and reset the value (#390) * done * fix --- .../crud-modal/crud-modal.tsx | 21 +++++++++++++++---- .../port-row/port-row.tsx | 20 +++++++++++++----- .../buttons/button-icon/button-icon.tsx | 9 +++++++- .../funnel-flow-body/funnel-flow-body.tsx | 5 ++++- 4 files changed, 44 insertions(+), 11 deletions(-) diff --git a/libs/pages/application/src/lib/ui/page-settings-ports/crud-modal/crud-modal.tsx b/libs/pages/application/src/lib/ui/page-settings-ports/crud-modal/crud-modal.tsx index 1c2dec3deb..7af984da3c 100644 --- a/libs/pages/application/src/lib/ui/page-settings-ports/crud-modal/crud-modal.tsx +++ b/libs/pages/application/src/lib/ui/page-settings-ports/crud-modal/crud-modal.tsx @@ -1,6 +1,7 @@ import { ServicePort } from 'qovery-typescript-axios' +import { useEffect } from 'react' import { Controller, useFormContext } from 'react-hook-form' -import { InputText, InputToggle, ModalCrud } from '@qovery/shared/ui' +import { Icon, IconAwesomeEnum, InputText, InputToggle, ModalCrud, Tooltip } from '@qovery/shared/ui' export interface CrudModalProps { port?: ServicePort @@ -14,12 +15,17 @@ export function CrudModal(props: CrudModalProps) { const { control, watch, setValue } = useFormContext() const watchPublicly = watch('publicly_accessible') + const watchExternalPort = watch('external_port') const pattern = { value: /^[0-9]+$/, message: 'Please enter a number.', } + useEffect(() => { + setValue(`external_port`, watchPublicly ? 443 : undefined) + }, [watchPublicly, setValue]) + return ( +
+ +
+ + } /> )} /> diff --git a/libs/pages/services/src/lib/ui/page-application-create/page-application-create-port/port-row/port-row.tsx b/libs/pages/services/src/lib/ui/page-application-create/page-application-create-port/port-row/port-row.tsx index 42e054df34..820e11b29c 100644 --- a/libs/pages/services/src/lib/ui/page-application-create/page-application-create-port/port-row/port-row.tsx +++ b/libs/pages/services/src/lib/ui/page-application-create/page-application-create-port/port-row/port-row.tsx @@ -1,6 +1,6 @@ import { useEffect } from 'react' import { Controller, useFormContext } from 'react-hook-form' -import { ButtonIcon, ButtonIconStyle, IconAwesomeEnum, InputText, InputToggle } from '@qovery/shared/ui' +import { ButtonIcon, ButtonIconStyle, Icon, IconAwesomeEnum, InputText, InputToggle, Tooltip } from '@qovery/shared/ui' import { PortData } from '../../../../feature/page-application-create-feature/application-creation-flow.interface' export interface PortRowProps { @@ -13,6 +13,7 @@ export function PortRow(props: PortRowProps) { const { control, watch, setValue, resetField } = useFormContext() const isPublicWatch = watch(`ports.${index}.is_public`) + const externalPortWatch = watch(`ports.${index}.external_port`) useEffect(() => { setValue(`ports.${index}.external_port`, isPublicWatch ? 443 : undefined) @@ -32,7 +33,7 @@ export function PortRow(props: PortRowProps) { name={field.name} onChange={field.onChange} value={field.value} - label={`Application Port ${index + 1}`} + label={`Application port`} type="number" /> )} @@ -45,18 +46,27 @@ export function PortRow(props: PortRowProps) { className="flex-grow" name={field.name} onChange={field.onChange} - value={field.value} - label={`External Port ${index + 1}`} + value={externalPortWatch} // passing a watch here because setValue with undefined does not work: https://github.com/react-hook-form/react-hook-form/issues/8133 + label={`External port`} error={error?.message} type="number" disabled + rightElement={ + +
+ +
+
+ } /> )} /> } + render={({ field }) => ( + + )} /> {!link && ( -