Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
ff311e56
Commit
ff311e56
authored
May 09, 2024
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor reCaptcha field
parent
5909d485
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
70 additions
and
72 deletions
+70
-72
CsvExportForm.tsx
ui/csvExport/CsvExportForm.tsx
+10
-3
CsvExportFormReCaptcha.tsx
ui/csvExport/CsvExportFormReCaptcha.tsx
+0
-67
PublicTagsSubmitForm.tsx
ui/publicTags/submit/PublicTagsSubmitForm.tsx
+2
-2
FormFieldReCaptcha.tsx
ui/shared/forms/fields/FormFieldReCaptcha.tsx
+58
-0
No files found.
ui/csvExport/CsvExportForm.tsx
View file @
ff311e56
import
{
Button
,
chakra
,
Flex
}
from
'
@chakra-ui/react
'
;
import
{
Alert
,
Button
,
chakra
,
Flex
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
type
{
SubmitHandler
}
from
'
react-hook-form
'
;
import
type
{
SubmitHandler
}
from
'
react-hook-form
'
;
import
{
useForm
,
FormProvider
}
from
'
react-hook-form
'
;
import
{
useForm
,
FormProvider
}
from
'
react-hook-form
'
;
...
@@ -11,9 +11,9 @@ import type { ResourceName } from 'lib/api/resources';
...
@@ -11,9 +11,9 @@ import type { ResourceName } from 'lib/api/resources';
import
dayjs
from
'
lib/date/dayjs
'
;
import
dayjs
from
'
lib/date/dayjs
'
;
import
downloadBlob
from
'
lib/downloadBlob
'
;
import
downloadBlob
from
'
lib/downloadBlob
'
;
import
useToast
from
'
lib/hooks/useToast
'
;
import
useToast
from
'
lib/hooks/useToast
'
;
import
FormFieldReCaptcha
from
'
ui/shared/forms/fields/FormFieldReCaptcha
'
;
import
CsvExportFormField
from
'
./CsvExportFormField
'
;
import
CsvExportFormField
from
'
./CsvExportFormField
'
;
import
CsvExportFormReCaptcha
from
'
./CsvExportFormReCaptcha
'
;
interface
Props
{
interface
Props
{
hash
:
string
;
hash
:
string
;
...
@@ -76,6 +76,13 @@ const CsvExportForm = ({ hash, resource, filterType, filterValue, fileNameTempla
...
@@ -76,6 +76,13 @@ const CsvExportForm = ({ hash, resource, filterType, filterValue, fileNameTempla
},
[
resource
,
hash
,
exportType
,
filterType
,
filterValue
,
fileNameTemplate
,
toast
]);
},
[
resource
,
hash
,
exportType
,
filterType
,
filterValue
,
fileNameTemplate
,
toast
]);
const
disabledFeatureMessage
=
(
<
Alert
status=
"error"
>
CSV export is not available at the moment since reCaptcha is not configured for this application.
Please contact the service maintainer to make necessary changes in the service configuration.
</
Alert
>
);
return
(
return
(
<
FormProvider
{
...
formApi
}
>
<
FormProvider
{
...
formApi
}
>
<
chakra
.
form
<
chakra
.
form
...
@@ -85,7 +92,7 @@ const CsvExportForm = ({ hash, resource, filterType, filterValue, fileNameTempla
...
@@ -85,7 +92,7 @@ const CsvExportForm = ({ hash, resource, filterType, filterValue, fileNameTempla
<
Flex
columnGap=
{
5
}
rowGap=
{
3
}
flexDir=
{
{
base
:
'
column
'
,
lg
:
'
row
'
}
}
alignItems=
{
{
base
:
'
flex-start
'
,
lg
:
'
center
'
}
}
flexWrap=
"wrap"
>
<
Flex
columnGap=
{
5
}
rowGap=
{
3
}
flexDir=
{
{
base
:
'
column
'
,
lg
:
'
row
'
}
}
alignItems=
{
{
base
:
'
flex-start
'
,
lg
:
'
center
'
}
}
flexWrap=
"wrap"
>
{
exportType
!==
'
holders
'
&&
<
CsvExportFormField
name=
"from"
formApi=
{
formApi
}
/>
}
{
exportType
!==
'
holders
'
&&
<
CsvExportFormField
name=
"from"
formApi=
{
formApi
}
/>
}
{
exportType
!==
'
holders
'
&&
<
CsvExportFormField
name=
"to"
formApi=
{
formApi
}
/>
}
{
exportType
!==
'
holders
'
&&
<
CsvExportFormField
name=
"to"
formApi=
{
formApi
}
/>
}
<
CsvExportFormReCaptcha
formApi=
{
formApi
}
/>
<
FormFieldReCaptcha
disabledFeatureMessage=
{
disabledFeatureMessage
}
/>
</
Flex
>
</
Flex
>
<
Button
<
Button
variant=
"solid"
variant=
"solid"
...
...
ui/csvExport/CsvExportFormReCaptcha.tsx
deleted
100644 → 0
View file @
5909d485
import
{
Alert
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
ReCaptcha
from
'
react-google-recaptcha
'
;
import
type
{
UseFormReturn
}
from
'
react-hook-form
'
;
import
type
{
FormFields
}
from
'
./types
'
;
import
config
from
'
configs/app
'
;
interface
Props
{
formApi
:
UseFormReturn
<
FormFields
>
;
}
const
CsvExportFormReCaptcha
=
({
formApi
}:
Props
)
=>
{
const
ref
=
React
.
useRef
<
ReCaptcha
>
(
null
);
React
.
useEffect
(()
=>
{
formApi
.
register
(
'
reCaptcha
'
,
{
required
:
true
,
shouldUnregister
:
true
});
return
()
=>
{
formApi
.
unregister
(
'
reCaptcha
'
);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
},
[]);
React
.
useEffect
(()
=>
{
ref
.
current
?.
reset
();
formApi
.
trigger
(
'
reCaptcha
'
);
// eslint-disable-next-line react-hooks/exhaustive-deps
},
[
formApi
.
formState
.
submitCount
]);
const
handleReCaptchaChange
=
React
.
useCallback
((
token
:
string
|
null
)
=>
{
if
(
token
)
{
formApi
.
clearErrors
(
'
reCaptcha
'
);
formApi
.
setValue
(
'
reCaptcha
'
,
token
,
{
shouldValidate
:
true
});
}
},
[
formApi
]);
const
handleReCaptchaExpire
=
React
.
useCallback
(()
=>
{
formApi
.
resetField
(
'
reCaptcha
'
);
formApi
.
setError
(
'
reCaptcha
'
,
{
type
:
'
required
'
});
},
[
formApi
]);
const
feature
=
config
.
features
.
csvExport
;
if
(
!
feature
.
isEnabled
)
{
return
(
<
Alert
status=
"error"
>
CSV export is not available at the moment since reCaptcha is not configured for this application.
Please contact the service maintainer to make necessary changes in the service configuration.
</
Alert
>
);
}
return
(
<
ReCaptcha
className=
"recaptcha"
ref=
{
ref
}
sitekey=
{
feature
.
reCaptcha
.
siteKey
}
onChange=
{
handleReCaptchaChange
}
onExpired=
{
handleReCaptchaExpire
}
/>
);
};
export
default
CsvExportFormReCaptcha
;
ui/publicTags/submit/PublicTagsSubmitForm.tsx
View file @
ff311e56
...
@@ -8,13 +8,13 @@ import type { PublicTagTypesResponse } from 'types/api/addressMetadata';
...
@@ -8,13 +8,13 @@ import type { PublicTagTypesResponse } from 'types/api/addressMetadata';
import
delay
from
'
lib/delay
'
;
import
delay
from
'
lib/delay
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
FormFieldReCaptcha
from
'
ui/shared/forms/fields/FormFieldReCaptcha
'
;
import
Hint
from
'
ui/shared/Hint
'
;
import
Hint
from
'
ui/shared/Hint
'
;
import
PublicTagsSubmitFieldAddresses
from
'
./fields/PublicTagsSubmitFieldAddresses
'
;
import
PublicTagsSubmitFieldAddresses
from
'
./fields/PublicTagsSubmitFieldAddresses
'
;
import
PublicTagsSubmitFieldCompanyName
from
'
./fields/PublicTagsSubmitFieldCompanyName
'
;
import
PublicTagsSubmitFieldCompanyName
from
'
./fields/PublicTagsSubmitFieldCompanyName
'
;
import
PublicTagsSubmitFieldCompanyWebsite
from
'
./fields/PublicTagsSubmitFieldCompanyWebsite
'
;
import
PublicTagsSubmitFieldCompanyWebsite
from
'
./fields/PublicTagsSubmitFieldCompanyWebsite
'
;
import
PublicTagsSubmitFieldDescription
from
'
./fields/PublicTagsSubmitFieldDescription
'
;
import
PublicTagsSubmitFieldDescription
from
'
./fields/PublicTagsSubmitFieldDescription
'
;
import
PublicTagsSubmitFieldReCaptcha
from
'
./fields/PublicTagsSubmitFieldReCaptcha
'
;
import
PublicTagsSubmitFieldRequesterEmail
from
'
./fields/PublicTagsSubmitFieldRequesterEmail
'
;
import
PublicTagsSubmitFieldRequesterEmail
from
'
./fields/PublicTagsSubmitFieldRequesterEmail
'
;
import
PublicTagsSubmitFieldRequesterName
from
'
./fields/PublicTagsSubmitFieldRequesterName
'
;
import
PublicTagsSubmitFieldRequesterName
from
'
./fields/PublicTagsSubmitFieldRequesterName
'
;
import
PublicTagsSubmitFieldTags
from
'
./fields/PublicTagsSubmitFieldTags
'
;
import
PublicTagsSubmitFieldTags
from
'
./fields/PublicTagsSubmitFieldTags
'
;
...
@@ -73,7 +73,7 @@ const PublicTagsSubmitForm = ({ config }: Props) => {
...
@@ -73,7 +73,7 @@ const PublicTagsSubmitForm = ({ config }: Props) => {
</
GridItem
>
</
GridItem
>
<
GridItem
colSpan=
{
{
base
:
1
,
lg
:
3
}
}
>
<
GridItem
colSpan=
{
{
base
:
1
,
lg
:
3
}
}
>
<
PublicTagsSubmitFieldReCaptcha
formApi=
{
formApi
}
/>
<
FormFieldReCaptcha
/>
</
GridItem
>
</
GridItem
>
<
Button
<
Button
...
...
ui/
publicTags/submit/fields/PublicTagsSubmit
FieldReCaptcha.tsx
→
ui/
shared/forms/fields/Form
FieldReCaptcha.tsx
View file @
ff311e56
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
ReCaptcha
from
'
react-google-recaptcha
'
;
import
ReCaptcha
from
'
react-google-recaptcha
'
;
import
type
{
UseFormReturn
}
from
'
react-hook-form
'
;
import
{
useFormContext
}
from
'
react-hook-form
'
;
import
type
{
FormFields
}
from
'
../types
'
;
import
config
from
'
configs/app
'
;
import
config
from
'
configs/app
'
;
interface
Props
{
interface
Props
{
formApi
:
UseFormReturn
<
FormFields
>
;
disabledFeatureMessage
?:
JSX
.
Element
;
}
}
const
PublicTagsSubmitFieldReCaptcha
=
({
formApi
}:
Props
)
=>
{
const
FormFieldReCaptcha
=
({
disabledFeatureMessage
}:
Props
)
=>
{
const
{
register
,
unregister
,
trigger
,
clearErrors
,
setValue
,
resetField
,
setError
,
formState
}
=
useFormContext
();
const
ref
=
React
.
useRef
<
ReCaptcha
>
(
null
);
const
ref
=
React
.
useRef
<
ReCaptcha
>
(
null
);
React
.
useEffect
(()
=>
{
React
.
useEffect
(()
=>
{
formApi
.
register
(
'
reCaptcha
'
,
{
required
:
true
,
shouldUnregister
:
true
});
register
(
'
reCaptcha
'
,
{
required
:
true
,
shouldUnregister
:
true
});
return
()
=>
{
return
()
=>
{
formApi
.
unregister
(
'
reCaptcha
'
);
unregister
(
'
reCaptcha
'
);
};
};
// eslint-disable-next-line react-hooks/exhaustive-deps
// eslint-disable-next-line react-hooks/exhaustive-deps
},
[]);
},
[]);
React
.
useEffect
(()
=>
{
React
.
useEffect
(()
=>
{
ref
.
current
?.
reset
();
ref
.
current
?.
reset
();
formApi
.
trigger
(
'
reCaptcha
'
);
trigger
(
'
reCaptcha
'
);
// eslint-disable-next-line react-hooks/exhaustive-deps
// eslint-disable-next-line react-hooks/exhaustive-deps
},
[
form
Api
.
form
State
.
submitCount
]);
},
[
formState
.
submitCount
]);
const
handleReCaptchaChange
=
React
.
useCallback
((
token
:
string
|
null
)
=>
{
const
handleReCaptchaChange
=
React
.
useCallback
((
token
:
string
|
null
)
=>
{
if
(
token
)
{
if
(
token
)
{
formApi
.
clearErrors
(
'
reCaptcha
'
);
clearErrors
(
'
reCaptcha
'
);
formApi
.
setValue
(
'
reCaptcha
'
,
token
,
{
shouldValidate
:
true
});
setValue
(
'
reCaptcha
'
,
token
,
{
shouldValidate
:
true
});
}
}
},
[
formApi
]);
},
[
clearErrors
,
setValue
]);
const
handleReCaptchaExpire
=
React
.
useCallback
(()
=>
{
const
handleReCaptchaExpire
=
React
.
useCallback
(()
=>
{
formApi
.
resetField
(
'
reCaptcha
'
);
resetField
(
'
reCaptcha
'
);
formApi
.
setError
(
'
reCaptcha
'
,
{
type
:
'
required
'
});
setError
(
'
reCaptcha
'
,
{
type
:
'
required
'
});
},
[
formApi
]);
},
[
resetField
,
setError
]);
const
feature
=
config
.
features
.
csvExport
;
if
(
!
feature
.
isEnabled
)
{
if
(
!
config
.
services
.
reCaptcha
.
siteKey
)
{
return
null
;
return
disabledFeatureMessage
??
null
;
}
}
return
(
return
(
<
ReCaptcha
<
ReCaptcha
className=
"recaptcha"
className=
"recaptcha"
ref=
{
ref
}
ref=
{
ref
}
sitekey=
{
feature
.
reCaptcha
.
siteKey
}
sitekey=
{
config
.
services
.
reCaptcha
.
siteKey
}
onChange=
{
handleReCaptchaChange
}
onChange=
{
handleReCaptchaChange
}
onExpired=
{
handleReCaptchaExpire
}
onExpired=
{
handleReCaptchaExpire
}
/>
/>
);
);
};
};
export
default
PublicTagsSubmit
FieldReCaptcha
;
export
default
Form
FieldReCaptcha
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment