diff --git a/app/javascript/shared/components/CustomerSatisfaction.vue b/app/javascript/shared/components/CustomerSatisfaction.vue index 10792aca2..799ec772c 100644 --- a/app/javascript/shared/components/CustomerSatisfaction.vue +++ b/app/javascript/shared/components/CustomerSatisfaction.vue @@ -49,7 +49,9 @@ export default { ?.feedback_message; }, isButtonDisabled() { - return !(this.selectedRating && this.feedback); + if (!(this.selectedRating && this.feedback)) return true; + if (this.isUpdating) return true; + return false; }, textColor() { return getContrastingTextColor(this.widgetColor); @@ -79,14 +81,16 @@ export default { methods: { buttonClass(rating) { + const isLocked = this.isFeedbackSubmitted || this.isUpdating; return [ { selected: rating.value === this.selectedRating }, - { disabled: this.isRatingSubmitted }, - { hover: this.isRatingSubmitted }, + { disabled: isLocked }, + { hover: isLocked }, 'emoji-button', ]; }, async onSubmit() { + if (this.isUpdating) return; this.isUpdating = true; try { await this.$store.dispatch('message/update', { @@ -106,10 +110,12 @@ export default { }, selectRating(rating) { + if (this.isFeedbackSubmitted || this.isUpdating) return; this.selectedRating = rating.value; this.onSubmit(); }, selectStarRating(value) { + if (this.isFeedbackSubmitted || this.isUpdating) return; this.selectedRating = value; this.onSubmit(); }, @@ -138,7 +144,7 @@ export default {
- + {{ $t('SURVEY.FEEDBACK.BUTTON_TEXT') }} diff --git a/app/javascript/survey/components/Rating.vue b/app/javascript/survey/components/Rating.vue index 25467706d..db2fd8b75 100644 --- a/app/javascript/survey/components/Rating.vue +++ b/app/javascript/survey/components/Rating.vue @@ -7,6 +7,10 @@ export default { type: Number, default: null, }, + isDisabled: { + type: Boolean, + default: false, + }, }, emits: ['selectRating'], data() { @@ -19,12 +23,13 @@ export default { buttonClass(rating) { return [ { selected: rating.value === this.selectedRating }, - { disabled: !!this.selectedRating }, - { hover: !!this.selectedRating }, + { disabled: this.isDisabled }, + { hover: this.isDisabled }, 'emoji-button shadow-none text-3xl lg:text-4xl outline-none mr-8', ]; }, onClick(rating) { + if (this.isDisabled) return; this.$emit('selectRating', rating.value); }, }, diff --git a/app/javascript/survey/views/Response.vue b/app/javascript/survey/views/Response.vue index 878dd7c9d..38fc4c66e 100644 --- a/app/javascript/survey/views/Response.vue +++ b/app/javascript/survey/views/Response.vue @@ -27,6 +27,7 @@ export default { errorMessage: null, selectedRating: null, feedbackMessage: '', + hasSubmittedFeedback: false, isUpdating: false, logo: '', inboxName: '', @@ -43,10 +44,14 @@ export default { return this.surveyDetails && this.surveyDetails.rating; }, isFeedbackSubmitted() { - return this.surveyDetails && this.surveyDetails.feedback_message; + return ( + this.hasSubmittedFeedback || !!this.surveyDetails?.feedback_message + ); }, isButtonDisabled() { - return !(this.selectedRating && this.feedback); + if (!this.selectedRating) return true; + if (this.isUpdating) return true; + return false; }, isEmojiType() { return this.displayType === CSAT_DISPLAY_TYPES.EMOJI; @@ -78,12 +83,13 @@ export default { }, methods: { selectRating(rating) { + if (this.isFeedbackSubmitted || this.isUpdating) return; this.selectedRating = rating; this.updateSurveyDetails(); }, sendFeedback(message) { this.feedbackMessage = message; - this.updateSurveyDetails(); + this.updateSurveyDetails({ markFeedbackSubmitted: true }); }, async getSurveyDetails() { this.isLoading = true; @@ -106,7 +112,7 @@ export default { this.isLoading = false; } }, - async updateSurveyDetails() { + async updateSurveyDetails({ markFeedbackSubmitted = false } = {}) { this.isUpdating = true; try { const data = { @@ -127,6 +133,9 @@ export default { rating: this.selectedRating, feedback_message: this.feedbackMessage, }; + if (markFeedbackSubmitted) { + this.hasSubmittedFeedback = true; + } } catch (error) { const errorMessage = error?.response?.data?.error; this.errorMessage = errorMessage || this.$t('SURVEY.API.ERROR_MESSAGE'); @@ -179,12 +188,13 @@ export default {