Skip to content

Commit 8ac0fd9

Browse files
committed
fix(feedback): disable form until the submission is through
1 parent 2c9cee4 commit 8ac0fd9

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

app/_assets/javascripts/apps/Feedback.vue

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99
:class="{ 'feedback__button--active': vote === option }"
1010
:aria-label="option ? 'Yes' : 'No'"
1111
:value="option"
12+
:disabled="isSubmitting"
1213
@click="handleVote(option)"
1314
>
1415
{{ option ? 'Yes' : 'No' }}
1516
</button>
1617
</div>
1718

18-
<p v-if="vote !== null" class="feedback__reply text-sm text-terciary flex">Thank you! We received your feedback.</p>
19+
<p v-if="vote !== null" class="feedback__reply text-sm text-terciary flex">
20+
Thank you! We received your feedback.
21+
</p>
1922

2023
<form
2124
v-if="vote === false"
@@ -27,12 +30,13 @@
2730
id="feedback-message"
2831
v-model="message"
2932
class="bg-secondary rounded-md border border-brand-saturated/40 py-2 px-3"
33+
:disabled="isSubmitting"
3034
></textarea>
3135
<div class="flex gap-3 justify-end">
32-
<button type="button" class="button button--secondary" @click="handleCancel">
36+
<button type="button" class="button button--secondary" @click="handleCancel" :disabled="isSubmitting">
3337
Cancel
3438
</button>
35-
<button type="submit" class="button button--primary">Send</button>
39+
<button type="submit" class="button button--primary" :disabled="isSubmitting">Send</button>
3640
</div>
3741
</form>
3842
</div>
@@ -44,9 +48,14 @@
4448
const vote = ref(null);
4549
const message = ref('');
4650
const feedbackId = ref(null);
51+
const isSubmitting = ref(false);
4752
4853
function handleVote(val) {
54+
if (isSubmitting.value) { return };
55+
4956
vote.value = val;
57+
isSubmitting.value = true;
58+
5059
fetch('/.netlify/functions/feedback-create', {
5160
method: 'POST',
5261
headers: { 'Content-Type': 'application/json' },
@@ -59,11 +68,18 @@
5968
.then((res) => res.json())
6069
.then((data) => {
6170
feedbackId.value ||= data.feedbackId;
71+
console.log('create callback')
72+
console.log(`id: ${feedbackId.value}`)
6273
})
63-
.catch((err) => console.error('Feedback error:', err));
74+
.catch((err) => console.error('Feedback error:', err))
75+
.finally(() => { isSubmitting.value = false; });
6476
}
6577
6678
function handleSubmit() {
79+
if (isSubmitting.value) { return };
80+
81+
isSubmitting.value = true;
82+
6783
fetch('/.netlify/functions/feedback-update', {
6884
method: 'PUT',
6985
headers: { 'Content-Type': 'application/json' },
@@ -75,7 +91,7 @@
7591
})
7692
.then((res) => res.json())
7793
.catch((err) => console.error('Feedback error:', err))
78-
94+
.finally(() => { isSubmitting.value = false; });
7995
resetForm();
8096
}
8197
@@ -87,4 +103,10 @@
87103
message.value = '';
88104
vote.value = null;
89105
}
90-
</script>
106+
</script>
107+
108+
<style scoped>
109+
.feedback__button:disabled {
110+
@apply !text-gray-500;
111+
}
112+
</style>

0 commit comments

Comments
 (0)