Skip to content

Commit

Permalink
Merge pull request #265 from City-of-Helsinki/UHF-10025
Browse files Browse the repository at this point in the history
UHF-10025: Contact form bugfixes
  • Loading branch information
hyrsky authored May 7, 2024
2 parents 0687db8 + 1d969ac commit ab4d4cd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 16 deletions.
7 changes: 3 additions & 4 deletions pages/api/feedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,15 @@ export default async function handler(request, response) {
message,
page,
name,
feedback_email,
subject = 'Palautetta sivustolta: <otsikko puuttuu>',
uuid,
} = request?.body
const form_response = await axios.post(POST_URL, {
sender_email,
message,
page,
subject,
subject: `Palautetta sivustolta: ${page}`,
name,
feedback_email,
uuid,
webform_id: WEBFORM_ID,
})
if (form_response?.status !== 200) {
Expand Down
11 changes: 3 additions & 8 deletions src/components/feedback/FeedbackForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useForm } from 'react-hook-form'
import InfoBlock from '@/components/feedback/InfoBlock'
import { isSSR } from '@/hooks/useIsomorphicLayoutEffect'
import axios from 'axios'
import { feedbackEmailAtom } from '@/src/store'
import {nodeIdAtom} from '@/src/store'
import { useAtomValue } from 'jotai/utils'

// eslint-disable-next-line react/display-name
Expand All @@ -15,7 +15,7 @@ const FeedbackForm = forwardRef(({ onCancel }, ref) => {
// Consider using async atom and useAtom hook instead if this becomes a real issue.

const { t } = useTranslation('common')
const feedbackEmail = useAtomValue(feedbackEmailAtom)
const nodeId = useAtomValue(nodeIdAtom)
const urlWithoutHash =
isSSR() === false ? window.location.href.split('#').shift() : ''
const {
Expand All @@ -27,7 +27,7 @@ const FeedbackForm = forwardRef(({ onCancel }, ref) => {
} = useForm()

const onSubmit = async (data) =>
axios.post('/api/feedback', { ...data, feedback_email: feedbackEmail })
axios.post('/api/feedback', { ...data, uuid: nodeId })

const onError = (errors, e) => {
console.error({ errors, e })
Expand Down Expand Up @@ -82,11 +82,6 @@ const FeedbackForm = forwardRef(({ onCancel }, ref) => {

<form onSubmit={handleSubmit(onSubmit, onError)}>
<input type="hidden" {...register('page')} value={urlWithoutHash} />
<input
type="hidden"
{...register('subject')}
value={`Palautetta sivusta: ${urlWithoutHash}`}
/>
<div className="mb-2">
<label
htmlFor="ifu-feedback-name"
Expand Down
4 changes: 0 additions & 4 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@ export const themeMenuAtom = atom((get) => get(pageAtom).themeMenu)

export const nodeAtom = selectAtom(pageAtom, (page) => page?.node)
export const nodeIdAtom = selectAtom(pageAtom, (page) => page?.node?.id)
export const feedbackEmailAtom = selectAtom(
pageAtom,
(page) => page?.node?.field_feedback_email
)

/** Cookie consent atom */
export const cookieConsentAtom = atomWithStorage(
Expand Down

0 comments on commit ab4d4cd

Please sign in to comment.