1- import React , { useEffect , useState } from "react" ;
1+ import { useEffect , useState } from "react" ;
22import { useTranslation } from "react-i18next" ;
33import { Field , Formik } from "formik" ;
44import cn from "classnames" ;
@@ -20,9 +20,19 @@ const TermsOfUseModal = () => {
2020 useEffect ( ( ) => {
2121 const checkTerms = async ( ) => {
2222 try {
23- const response = await axios . get ( "/admin-ng/user-settings/settings.json" ) ;
24- // @ts -expect-error TS(7006): Parameter 'result' implicitly has an 'any' type.
25- const isAgreed = response . data . results . find ( result => result . key === "agreedToTerms" ) . value === "true" ;
23+ type FetchUserSettings = {
24+ total : number ,
25+ offset : number ,
26+ limit : number ,
27+ results : {
28+ id : number ,
29+ value : string ,
30+ key : string
31+ } [ ]
32+ } ;
33+ const response = await axios . get < FetchUserSettings > ( "/admin-ng/user-settings/settings.json" ) ;
34+ const agreedResult = response . data . results . find ( result => result . key === "agreedToTerms" ) ;
35+ const isAgreed = agreedResult ?. value === "true" ;
2636 setAgreedToTerms ( isAgreed ) ;
2737 } catch ( error ) {
2838 console . error ( "Error while retrieving data: " , error ) ;
@@ -35,27 +45,26 @@ const TermsOfUseModal = () => {
3545
3646 // Fetch terms
3747 useEffect ( ( ) => {
38- axios . get ( getURL ( i18n . language ) )
48+ axios . get < string > ( getURL ( i18n . language ) )
3949 . then ( response => {
4050 setTermsContent ( response . data ) ;
4151 } )
42- . catch ( error => {
43- axios . get ( getURL ( typeof i18n . options . fallbackLng === ' string' ? i18n . options . fallbackLng : ' en-US' ) )
52+ . catch ( ( ) => {
53+ axios . get < string > ( getURL ( typeof i18n . options . fallbackLng === " string" ? i18n . options . fallbackLng : " en-US" ) )
4454 . then ( response => {
4555 setTermsContent ( response . data ) ;
4656 } )
4757 . catch ( error => {
48- console . error ( ' Error while fetching data:' , error ) ;
58+ console . error ( " Error while fetching data:" , error ) ;
4959 setTermsContent ( t ( "TERMS.NOCONTENT" ) ) ;
5060 } ) ;
5161 } ) ;
5262 // eslint-disable-next-line react-hooks/exhaustive-deps
5363 } , [ agreedToTerms ] ) ; // Listen to changes in agreedToTerms
5464
5565 // Set terms to user settings
56- // @ts -expect-error TS(7006): Parameter 'values' implicitly has an 'any' type.
57- const handleSubmit = async ( values ) => {
58- let body = new URLSearchParams ( ) ;
66+ const handleSubmit = async ( values : { agreedToTerms : boolean } ) => {
67+ const body = new URLSearchParams ( ) ;
5968 body . append ( "key" , "agreedToTerms" ) ;
6069 body . append ( "value" , values . agreedToTerms ? "true" : "false" ) ;
6170
@@ -94,11 +103,11 @@ const TermsOfUseModal = () => {
94103 </ div >
95104
96105 < Formik
97- initialValues = { { } }
106+ initialValues = { { agreedToTerms : false } }
98107 enableReinitialize
99108 onSubmit = { handleSubmit }
100109 >
101- { ( formik ) => ( < >
110+ { formik => ( < >
102111 < div className = "modal-content" style = { { display : "block" } } >
103112 < div className = "modal-body" >
104113 < div >
@@ -124,16 +133,13 @@ const TermsOfUseModal = () => {
124133 < div className = "pull-right" >
125134 < button
126135 disabled = {
127- // @ts -expect-error TS(2339): Property 'agreedToTerms' does not exist on type '... Remove this comment to see the full error message
128136 ! ( formik . isValid && formik . values . agreedToTerms )
129137 }
130138 onClick = { ( ) => formik . handleSubmit ( ) }
131139 className = { cn ( "submit" , {
132140 active :
133- // @ts -expect-error TS(2339): Property 'agreedToTerms' does not exist on type '... Remove this comment to see the full error message
134141 formik . isValid && formik . values . agreedToTerms ,
135142 inactive : ! (
136- // @ts -expect-error TS(2339): Property 'agreedToTerms' does not exist on type '... Remove this comment to see the full error message
137143 formik . isValid && formik . values . agreedToTerms
138144 ) ,
139145 } ) }
0 commit comments