Skip to content

Commit

Permalink
[MIM-1934] Mim 1934 bugfix default selection contact form (#2844)
Browse files Browse the repository at this point in the history
* Use receiver state value as selectedItem instead of first item in items array

MIM-1934

* Minor code refactoring; ts typing and sonarcloud warnings

* Remove logging
  • Loading branch information
johnnadeluy authored Aug 1, 2024
1 parent 6c71e46 commit 03b0a52
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"@item-enonic-types/lib-time": "~1.0.4",
"@reduxjs/toolkit": "~2.2.7",
"@statisticsnorway/ssb-component-library": "~2.2.3",
"@types/grecaptcha": "^3.0.9",
"@types/ramda": "~0.30.1",
"@types/react": "~18.3.3",
"@types/react-mathjax": "^1.0.4",
Expand Down
23 changes: 11 additions & 12 deletions src/main/resources/site/parts/contactForm/contactForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ interface ContactFormProps {

function ContactForm(props: ContactFormProps) {
const { contactFormServiceUrl, recaptchaSiteKey } = props
const DEFAULT_RECEIVER_ITEM = {
title: props.phrases.contactFormReceiverGenerell,
id: 'generell',
}
const [receiver, setReceiver] = useState({
error: false,
errorMsg: props.phrases.contactFormValidateReveicer,
value: '',
value: DEFAULT_RECEIVER_ITEM,
})
const [name, setName] = useState({
error: false,
Expand Down Expand Up @@ -59,7 +63,7 @@ function ContactForm(props: ContactFormProps) {
setLoading(true)
grecaptcha.enterprise.ready(function () {
grecaptcha.enterprise
.execute(recaptchaSiteKey, {
.execute(recaptchaSiteKey as string, {
action: 'submitContactForm',
})
.then(function (token: string) {
Expand All @@ -83,9 +87,6 @@ function ContactForm(props: ContactFormProps) {
setLoading(false)
})
})
.catch((e) => {
console.trace(e)
})
})
}

Expand Down Expand Up @@ -215,6 +216,7 @@ function ContactForm(props: ContactFormProps) {
</Row>
)
}
return
}

function renderEmailSentError() {
Expand All @@ -229,15 +231,13 @@ function ContactForm(props: ContactFormProps) {
</Row>
)
}
return
}

function renderForm() {
if (!emailSent) {
const items = [
{
title: props.phrases.contactFormReceiverGenerell,
id: 'generell',
},
DEFAULT_RECEIVER_ITEM,
{
title: props.phrases.contactFormReceiverStatistikk,
id: 'statistikk',
Expand Down Expand Up @@ -269,8 +269,7 @@ function ContactForm(props: ContactFormProps) {
onChange('receiver', value)
}}
header={props.phrases.contactFormChooseReceiver}
placeholder={''}
selectedItem={items[0]}
selectedItem={receiver.value}
error={receiver.error}
errorMessage={receiver.errorMsg}
items={items}
Expand Down Expand Up @@ -328,6 +327,7 @@ function ContactForm(props: ContactFormProps) {
</Row>
)
}
return
}

function renderContactForm() {
Expand All @@ -339,7 +339,6 @@ function ContactForm(props: ContactFormProps) {
</section>
)
}

return renderContactForm()
}

Expand Down
1 change: 1 addition & 0 deletions src/tsconfig.react4xp.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"lib": ["es2021", "dom", "ES2021.String"],
"types": [
"@item-enonic-types/global",
"@types/grecaptcha"
],
"rootDirs": [
"./main/resources",
Expand Down

0 comments on commit 03b0a52

Please sign in to comment.