mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-11-03 20:48:07 +00:00 
			
		
		
		
	chore: Add loader for email and csat submit buttons (#2569)
* fix the loader issue in submit button * review fixes Co-authored-by: Nithin David Thomas <1277421+nithindavid@users.noreply.github.com>
This commit is contained in:
		@@ -29,8 +29,8 @@
 | 
				
			|||||||
        :disabled="isButtonDisabled"
 | 
					        :disabled="isButtonDisabled"
 | 
				
			||||||
        :style="{ background: widgetColor, borderColor: widgetColor }"
 | 
					        :style="{ background: widgetColor, borderColor: widgetColor }"
 | 
				
			||||||
      >
 | 
					      >
 | 
				
			||||||
        <i v-if="!isUpdating" class="ion-ios-arrow-forward" />
 | 
					        <spinner v-if="isUpdating && feedback" />
 | 
				
			||||||
        <spinner v-else />
 | 
					        <i v-else class="ion-ios-arrow-forward" />
 | 
				
			||||||
      </button>
 | 
					      </button>
 | 
				
			||||||
    </form>
 | 
					    </form>
 | 
				
			||||||
  </div>
 | 
					  </div>
 | 
				
			||||||
@@ -50,6 +50,10 @@ export default {
 | 
				
			|||||||
      type: Object,
 | 
					      type: Object,
 | 
				
			||||||
      default: () => {},
 | 
					      default: () => {},
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					    messageId: {
 | 
				
			||||||
 | 
					      type: Number,
 | 
				
			||||||
 | 
					      required: true,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  data() {
 | 
					  data() {
 | 
				
			||||||
    return {
 | 
					    return {
 | 
				
			||||||
@@ -84,10 +88,10 @@ export default {
 | 
				
			|||||||
  mounted() {
 | 
					  mounted() {
 | 
				
			||||||
    if (this.isRatingSubmitted) {
 | 
					    if (this.isRatingSubmitted) {
 | 
				
			||||||
      const {
 | 
					      const {
 | 
				
			||||||
        csat_survey_response: { rating, feedback },
 | 
					        csat_survey_response: { rating, feedback_message },
 | 
				
			||||||
      } = this.messageContentAttributes;
 | 
					      } = this.messageContentAttributes;
 | 
				
			||||||
      this.selectedRating = rating;
 | 
					      this.selectedRating = rating;
 | 
				
			||||||
      this.feedback = feedback;
 | 
					      this.feedback = feedback_message;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -100,11 +104,23 @@ export default {
 | 
				
			|||||||
        'emoji-button',
 | 
					        'emoji-button',
 | 
				
			||||||
      ];
 | 
					      ];
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    onSubmit() {
 | 
					    async onSubmit() {
 | 
				
			||||||
      this.$emit('submit', {
 | 
					      this.isUpdating = true;
 | 
				
			||||||
        rating: this.selectedRating,
 | 
					      try {
 | 
				
			||||||
        feedback: this.feedback,
 | 
					        await this.$store.dispatch('message/update', {
 | 
				
			||||||
      });
 | 
					          submittedValues: {
 | 
				
			||||||
 | 
					            csat_survey_response: {
 | 
				
			||||||
 | 
					              rating: this.selectedRating,
 | 
				
			||||||
 | 
					              feedback_message: this.feedback,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					          messageId: this.messageId,
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					      } catch (error) {
 | 
				
			||||||
 | 
					        // Ignore error
 | 
				
			||||||
 | 
					      } finally {
 | 
				
			||||||
 | 
					        this.isUpdating = false;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    selectRating(rating) {
 | 
					    selectRating(rating) {
 | 
				
			||||||
      this.selectedRating = rating.value;
 | 
					      this.selectedRating = rating.value;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -47,7 +47,7 @@
 | 
				
			|||||||
    <customer-satisfaction
 | 
					    <customer-satisfaction
 | 
				
			||||||
      v-if="isCSAT"
 | 
					      v-if="isCSAT"
 | 
				
			||||||
      :message-content-attributes="messageContentAttributes.submitted_values"
 | 
					      :message-content-attributes="messageContentAttributes.submitted_values"
 | 
				
			||||||
      @submit="onCSATSubmit"
 | 
					      :message-id="messageId"
 | 
				
			||||||
    />
 | 
					    />
 | 
				
			||||||
  </div>
 | 
					  </div>
 | 
				
			||||||
</template>
 | 
					</template>
 | 
				
			||||||
@@ -125,17 +125,6 @@ export default {
 | 
				
			|||||||
        messageId: this.messageId,
 | 
					        messageId: this.messageId,
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    onCSATSubmit({ feedback, rating }) {
 | 
					 | 
				
			||||||
      this.onResponse({
 | 
					 | 
				
			||||||
        submittedValues: {
 | 
					 | 
				
			||||||
          csat_survey_response: {
 | 
					 | 
				
			||||||
            rating,
 | 
					 | 
				
			||||||
            feedback_message: feedback,
 | 
					 | 
				
			||||||
          },
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        messageId: this.messageId,
 | 
					 | 
				
			||||||
      });
 | 
					 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
</script>
 | 
					</script>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,7 +18,7 @@
 | 
				
			|||||||
        :disabled="$v.email.$invalid"
 | 
					        :disabled="$v.email.$invalid"
 | 
				
			||||||
        :style="{ background: widgetColor, borderColor: widgetColor }"
 | 
					        :style="{ background: widgetColor, borderColor: widgetColor }"
 | 
				
			||||||
      >
 | 
					      >
 | 
				
			||||||
        <i v-if="!uiFlags.isUpdating" class="ion-ios-arrow-forward" />
 | 
					        <i v-if="!isUpdating" class="ion-ios-arrow-forward" />
 | 
				
			||||||
        <spinner v-else />
 | 
					        <spinner v-else />
 | 
				
			||||||
      </button>
 | 
					      </button>
 | 
				
			||||||
    </form>
 | 
					    </form>
 | 
				
			||||||
@@ -47,11 +47,11 @@ export default {
 | 
				
			|||||||
  data() {
 | 
					  data() {
 | 
				
			||||||
    return {
 | 
					    return {
 | 
				
			||||||
      email: '',
 | 
					      email: '',
 | 
				
			||||||
 | 
					      isUpdating: false,
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  computed: {
 | 
					  computed: {
 | 
				
			||||||
    ...mapGetters({
 | 
					    ...mapGetters({
 | 
				
			||||||
      uiFlags: 'message/getUIFlags',
 | 
					 | 
				
			||||||
      widgetColor: 'appConfig/getWidgetColor',
 | 
					      widgetColor: 'appConfig/getWidgetColor',
 | 
				
			||||||
    }),
 | 
					    }),
 | 
				
			||||||
    hasSubmitted() {
 | 
					    hasSubmitted() {
 | 
				
			||||||
@@ -68,15 +68,21 @@ export default {
 | 
				
			|||||||
    },
 | 
					    },
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  methods: {
 | 
					  methods: {
 | 
				
			||||||
    onSubmit() {
 | 
					    async onSubmit() {
 | 
				
			||||||
      if (this.$v.$invalid) {
 | 
					      if (this.$v.$invalid) {
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					      this.isUpdating = true;
 | 
				
			||||||
      this.$store.dispatch('message/update', {
 | 
					      try {
 | 
				
			||||||
        email: this.email,
 | 
					        await this.$store.dispatch('message/update', {
 | 
				
			||||||
        messageId: this.messageId,
 | 
					          email: this.email,
 | 
				
			||||||
      });
 | 
					          messageId: this.messageId,
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					      } catch (error) {
 | 
				
			||||||
 | 
					        // Ignore error
 | 
				
			||||||
 | 
					      } finally {
 | 
				
			||||||
 | 
					        this.isUpdating = false;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user