Skip to content

Commit

Permalink
Merge pull request #1294 from ItzNotABug/fix-feedback-form
Browse files Browse the repository at this point in the history
Fix Feedback Forms
  • Loading branch information
stnguyen90 authored Sep 25, 2024
2 parents 5993684 + b125a4f commit 2248351
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 32 deletions.
10 changes: 8 additions & 2 deletions src/lib/components/feedback/feedback.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
feedbackOptions,
feedbackData
} from '$lib/stores/feedback';
import { user } from '$lib/stores/user';
import { organization } from '$lib/stores/organization';
import { addNotification } from '$lib/stores/notifications';
import { page } from '$app/stores';
$: $selectedFeedback = feedbackOptions.find((option) => option.type === $feedback.type);
Expand All @@ -15,8 +18,11 @@
await feedback.submitFeedback(
`feedback-${$feedback.type}`,
$feedbackData.message,
$feedbackData.name,
$feedbackData.email
$user.name,
$user.email,
$organization.billingPlan,
$page.url.href,
$feedbackData.value
);
addNotification({
type: 'success',
Expand Down
8 changes: 1 addition & 7 deletions src/lib/components/feedback/feedbackGeneral.svelte
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
<script lang="ts">
import { FormList, InputTextarea, InputText, InputEmail } from '$lib/elements/forms';
import { FormList, InputTextarea } from '$lib/elements/forms';
import { feedbackData } from '$lib/stores/feedback';
</script>

<FormList>
<InputText label="Name" id="name" bind:value={$feedbackData.name} placeholder="Enter name" />
<InputEmail
label="Email"
id="email"
bind:value={$feedbackData.email}
placeholder="Enter email" />
<InputTextarea
id="feedback"
placeholder="Your message here"
Expand Down
12 changes: 1 addition & 11 deletions src/lib/components/feedback/feedbackNPS.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { FormList, InputTextarea, InputText, InputEmail } from '$lib/elements/forms';
import { FormList, InputTextarea } from '$lib/elements/forms';
import { feedbackData } from '$lib/stores/feedback';
import Evaluation from './evaluation.svelte';
</script>
Expand All @@ -16,15 +16,5 @@
required
bind:value={$feedbackData.message}
showLabel={false} />
<InputText
label="Name"
id="name"
bind:value={$feedbackData.name}
placeholder="Enter name" />
<InputEmail
label="Email"
id="email"
bind:value={$feedbackData.email}
placeholder="Enter email" />
{/if}
</FormList>
21 changes: 12 additions & 9 deletions src/lib/stores/feedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ export type Feedback = {

export type FeedbackData = {
message: string;
name?: string;
email?: string;
value?: number;
};

Expand Down Expand Up @@ -47,8 +45,6 @@ export const selectedFeedback = writable<FeedbackOption>();
function createFeedbackDataStore() {
const { set, subscribe, update } = writable<FeedbackData>({
message: '',
name: '',
email: '',
value: null
});
return {
Expand All @@ -58,8 +54,6 @@ function createFeedbackDataStore() {
reset: () => {
update((feedbackData) => {
feedbackData.message = '';
feedbackData.name = '';
feedbackData.email = '';
feedbackData.value = null;
return feedbackData;
});
Expand Down Expand Up @@ -110,11 +104,16 @@ function createFeedbackStore() {
return feedback;
});
},
// TODO: update growth server to accept `billingPlan` and other keys.
submitFeedback: async (
subject: string,
message: string,
firstname?: string,
name?: string,
email?: string,
// eslint-disable-next-line
// @ts-expect-error
billingPlan?: string,
currentPage?: string,
value?: number
) => {
if (!VARS.GROWTH_ENDPOINT) return;
Expand All @@ -127,8 +126,12 @@ function createFeedbackStore() {
subject,
message,
email,
firstname: firstname ? firstname : undefined,
customFields: value ? [{ id: '40655', value }] : undefined
// billingPlan,
firstname: name || 'Unknown',
customFields: [
{ id: '47364', currentPage },
...(value ? [{ id: '40655', value }] : [])
]
})
});
if (response.status >= 400) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
await feedback.submitFeedback(`feedback-${$feedback.type}`, message);
} catch (error) {
console.error(
'Feedback cound bot be submitted, but we continue to reditect to do export.'
'Feedback could not be submitted, but we continue to redirect to do export.'
);
console.error(error);
}
Expand Down
10 changes: 8 additions & 2 deletions src/routes/(console)/wizard/feedback/step1.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
feedbackOptions,
feedback
} from '$lib/stores/feedback';
import { user } from '$lib/stores/user';
import { organization } from '$lib/stores/organization';
import { addNotification } from '$lib/stores/notifications';
import { page } from '$app/stores';
$: $selectedFeedback = feedbackOptions.find((option) => option.type === $feedback.type);
Expand All @@ -15,8 +18,11 @@
await feedback.submitFeedback(
`feedback-${$feedback.type}`,
$feedbackData.message,
$feedbackData.name,
$feedbackData.email
$user.name,
$user.email,
$organization.billingPlan,
$page.url.href,
$feedbackData.value
);
addNotification({
type: 'success',
Expand Down

0 comments on commit 2248351

Please sign in to comment.