1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

fix: make sure customer type is included in the payload.

Because it previously set it via a reducer and submitted the form in
the same step, the customer type wouldn't be set correctly before the
form was submitted, causing it to show up as "undefined".

We're doing double the work now, but I think that's an acceptable
trade-off for now.
This commit is contained in:
Thomas Heartman 2022-03-10 10:07:28 +01:00
parent 027eac47ac
commit 18c16b3040

View File

@ -7,6 +7,12 @@ const join = (...cs: string[]) => cs.join(' ');
type CustomerType = 'open source' | 'paying';
type FormData = {
score: number;
comment: undefined | string;
customerType: undefined | CustomerType;
};
type InitialData = {
currentStep: number;
data: {
@ -173,13 +179,13 @@ export const FeedbackWrapper: React.FC<Props> = ({ seedData, open }) => {
const setCustomerType = (customerType: CustomerType) =>
dispatch({ kind: 'set customer type', data: customerType });
const submitFeedback = () => {
const submitFeedback = (data: FormData) => {
if (feedbackTargetUrl) {
fetch(feedbackTargetUrl, {
method: 'post',
body: JSON.stringify({
data: {
...state.data,
...data,
openedManually: manuallyOpened,
currentPage: location.pathname,
},
@ -380,7 +386,16 @@ export const FeedbackWrapper: React.FC<Props> = ({ seedData, open }) => {
onSubmit={(e) => {
e.preventDefault();
setCustomerType(value);
submitFeedback();
// To ensure that we get the correct customer type included.
// We can't rely on the reducer to set it because it won't
// happen until the component re-renders, causing customer
// type to have an old or empty value.
const finalState = stateReducer(state, {
kind: 'set customer type',
data: value,
});
submitFeedback(finalState.data);
}}
>
<fieldset disabled={hidden}>