1- import React from "react" ;
1+ import React , { useState } from "react" ;
22
33import { FieldErrors , UseFormRegister , useWatch } from "react-hook-form" ;
44import { useTranslation } from "react-i18next" ;
55
6- import { Button , ErrorMessage , Input , Spinner } from "@components/atoms" ;
6+ import { Button , ErrorMessage , Input , SecretInput , Spinner } from "@components/atoms" ;
77
88import { FloppyDiskIcon } from "@assets/image/icons" ;
99
1010export const NotionApiKeyForm = ( {
1111 control,
1212 errors,
1313 isLoading,
14+ mode,
1415 register,
16+ setValue,
1517} : {
1618 control : any ;
1719 errors : FieldErrors < any > ;
@@ -21,22 +23,45 @@ export const NotionApiKeyForm = ({
2123 setValue : any ;
2224} ) => {
2325 const { t } = useTranslation ( "integrations" ) ;
26+ const [ lockState , setLockState ] = useState < { apiKey : boolean } > ( {
27+ apiKey : true ,
28+ } ) ;
2429
25- const internalIntegrationSecret = useWatch ( { control, name : "internal_integration_secret" } ) ;
30+ const apiKey = useWatch ( { control, name : "api_key" } ) ;
31+ const isEditMode = mode === "edit" ;
2632
2733 return (
2834 < >
2935 < div className = "relative" >
30- < Input
31- { ...register ( "internal_integration_secret" ) }
32- aria-label = { t ( "notion.placeholders.internalIntegrationSecret" ) }
33- disabled = { isLoading }
34- isError = { ! ! errors . internal_integration_secret }
35- isRequired
36- label = { t ( "notion.placeholders.internalIntegrationSecret" ) }
37- value = { internalIntegrationSecret }
38- />
39- < ErrorMessage > { errors . internal_integration_secret ?. message as string } </ ErrorMessage >
36+ { isEditMode ? (
37+ < SecretInput
38+ type = "password"
39+ { ...register ( "api_key" ) }
40+ aria-label = { t ( "notion.placeholders.apiKey" ) }
41+ disabled = { isLoading }
42+ handleInputChange = { ( newValue ) => setValue ( "api_key" , newValue ) }
43+ handleLockAction = { ( newLockState ) =>
44+ setLockState ( ( prevState ) => ( { ...prevState , apiKey : newLockState } ) )
45+ }
46+ isError = { ! ! errors . api_key }
47+ isLocked = { lockState . apiKey }
48+ isRequired
49+ label = { t ( "notion.placeholders.apiKey" ) }
50+ value = { apiKey }
51+ />
52+ ) : (
53+ < Input
54+ { ...register ( "api_key" ) }
55+ aria-label = { t ( "notion.placeholders.apiKey" ) }
56+ disabled = { isLoading }
57+ isError = { ! ! errors . api_key }
58+ isRequired
59+ label = { t ( "notion.placeholders.apiKey" ) }
60+ value = { apiKey }
61+ />
62+ ) }
63+
64+ < ErrorMessage > { errors . api_key ?. message as string } </ ErrorMessage >
4065 </ div >
4166
4267 < Button
0 commit comments