Skip to content

Commit

Permalink
fix(form): fix dynamic secret field for password
Browse files Browse the repository at this point in the history
  • Loading branch information
anteqkois committed Jun 10, 2024
1 parent 80499c9 commit db1ca29
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
5 changes: 4 additions & 1 deletion apps/web/modules/editor/app-connections/SecretTextAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { MarkdownBase } from '../../../shared/components/Markdown/MarkdownBase'
import { AppConnectionsApi } from '../../app-connections'
import { useReachLimitDialog } from '../../billing/useReachLimitDialog'
import { SecretTextField } from '../form/Inputs/SecretTextField'
import { DynamicFieldProvider } from '../form/useFieldCustomValidation'

export interface SecretTextAuthProps extends HTMLAttributes<HTMLElement> {
onCreateAppConnection: (newConnection: AppConnectionWithoutSensitiveData) => void
Expand Down Expand Up @@ -116,7 +117,9 @@ export const SecretTextAuth = ({ onCreateAppConnection, auth, connector, setShow
</MarkdownBase>
) : null}
<div className="sm:max-w-[380px]">
<SecretTextField property={{ ...auth, description: undefined }} name={'secretText'} key={'secretText'} refreshedProperties={[]} />
<DynamicFieldProvider property={{ ...auth, description: undefined }} canUseDynamicValue={false}>
<SecretTextField property={{ ...auth, description: undefined }} name={'secretText'} key={'secretText'} refreshedProperties={[]} />
</DynamicFieldProvider>
</div>
<div className="h-1">
{appConnectionForm.formState.errors.root && <FormMessage>{appConnectionForm.formState.errors.root.message}</FormMessage>}
Expand Down
7 changes: 3 additions & 4 deletions apps/web/modules/editor/form/PropertyLabel.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { ConnectorProperty } from '@linkerry/connectors-framework'
import { FormLabel, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@linkerry/ui-components/client'
import { Icons } from '@linkerry/ui-components/server'
import { HTMLAttributes, SetStateAction } from 'react'
import { HTMLAttributes } from 'react'
import { useDynamicField } from './useFieldCustomValidation'

export interface PropertyLabelProps extends Omit<HTMLAttributes<HTMLElement>, 'property'> {
refreshedProperties: ConnectorProperty[]
property: ConnectorProperty
setUseDynamicValue?: (value: SetStateAction<boolean>) => void
}

export const PropertyLabel = ({ property, refreshedProperties }: PropertyLabelProps) => {
const { setUseDynamicValue } = useDynamicField()
const { setUseDynamicValue, canUseDynamicValue } = useDynamicField()

return (
<FormLabel className="flex justify-between">
Expand Down Expand Up @@ -42,7 +41,7 @@ export const PropertyLabel = ({ property, refreshedProperties }: PropertyLabelPr
</TooltipProvider>
) : null}

{setUseDynamicValue ? (
{canUseDynamicValue ? (
<TooltipProvider delayDuration={100}>
<Tooltip>
<TooltipTrigger onClick={() => setUseDynamicValue(true)} className="opacity-50 hover:opacity-100">
Expand Down
5 changes: 4 additions & 1 deletion apps/web/modules/editor/form/useFieldCustomValidation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ interface DynamicFieldContextValue {
setUseDynamicValue: React.Dispatch<React.SetStateAction<boolean>>
validate: Record<string, Validate<any, FieldValues>>
rules: Omit<RegisterOptions, 'disabled' | 'valueAsNumber' | 'valueAsDate' | 'setValueAs'>
canUseDynamicValue: boolean
}

const DynamicFieldContext = createContext<DynamicFieldContextValue | undefined>(undefined)

interface DynamicFieldProviderProps {
children: React.ReactNode
property: ConnectorProperty
canUseDynamicValue?: boolean
}

export const DynamicFieldProvider = ({ children, property }: DynamicFieldProviderProps) => {
export const DynamicFieldProvider = ({ children, property, canUseDynamicValue = true }: DynamicFieldProviderProps) => {
const [useDynamicValue, setUseDynamicValue] = useState(false)

const validate = useMemo(() => {
Expand Down Expand Up @@ -49,6 +51,7 @@ export const DynamicFieldProvider = ({ children, property }: DynamicFieldProvide
setUseDynamicValue,
validate,
rules,
canUseDynamicValue
}}
>
{children}
Expand Down

0 comments on commit db1ca29

Please sign in to comment.