Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UHF-10025: Contact form bugfixes #265

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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