diff --git a/app/javascript/dashboard/i18n/locale/en/sla.json b/app/javascript/dashboard/i18n/locale/en/sla.json index 67ec4549f06c..d87f057eb437 100644 --- a/app/javascript/dashboard/i18n/locale/en/sla.json +++ b/app/javascript/dashboard/i18n/locale/en/sla.json @@ -24,21 +24,24 @@ "PLACEHOLDER": "SLA for premium customers" }, "FIRST_RESPONSE_TIME": { - "LABEL": "First Response Time(Seconds)", - "PLACEHOLDER": "300 for 5 minutes" + "LABEL": "First Response Time", + "PLACEHOLDER": "5" }, "NEXT_RESPONSE_TIME": { - "LABEL": "Next Response Time(Seconds)", - "PLACEHOLDER": "600 for 10 minutes" + "LABEL": "Next Response Time", + "PLACEHOLDER": "5" }, "RESOLUTION_TIME": { - "LABEL": "Resolution Time(Seconds)", - "PLACEHOLDER": "86400 for 1 day" + "LABEL": "Resolution Time", + "PLACEHOLDER": "60" }, "BUSINESS_HOURS": { "LABEL": "Business Hours", "PLACEHOLDER": "Only during business hours" }, + "THRESHOLD_TIME": { + "INVALID_FORMAT_ERROR": "Threshold should be a number and greater than zero" + }, "EDIT": "Edit", "CREATE": "Create", "DELETE": "Delete", diff --git a/app/javascript/dashboard/routes/dashboard/settings/sla/Index.vue b/app/javascript/dashboard/routes/dashboard/settings/sla/Index.vue index 6c4002821d46..9ff510d06daa 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/sla/Index.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/sla/Index.vue @@ -38,17 +38,17 @@ {{ sla.description }} - {{ sla.first_response_time_threshold }} + {{ displayTime(sla.first_response_time_threshold) }} - {{ sla.next_response_time_threshold }} + {{ displayTime(sla.next_response_time_threshold) }} - {{ sla.resolution_time_threshold }} + {{ displayTime(sla.resolution_time_threshold) }} @@ -88,6 +88,7 @@ diff --git a/app/javascript/dashboard/routes/dashboard/settings/sla/SlaForm.vue b/app/javascript/dashboard/routes/dashboard/settings/sla/SlaForm.vue index 775c0ff2a315..f41e8fcfc7b4 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/sla/SlaForm.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/sla/SlaForm.vue @@ -2,44 +2,31 @@
- - - - -
@@ -51,7 +38,7 @@
{{ submitLabel }} @@ -66,10 +53,15 @@ diff --git a/app/javascript/dashboard/routes/dashboard/settings/sla/specs/validationMixin.spec.js b/app/javascript/dashboard/routes/dashboard/settings/sla/specs/validationMixin.spec.js index a828c855602c..2266bdccdf3d 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/sla/specs/validationMixin.spec.js +++ b/app/javascript/dashboard/routes/dashboard/settings/sla/specs/validationMixin.spec.js @@ -31,6 +31,7 @@ describe('validationMixin', () => { data() { return { name: '', + thresholdTime: '', }; }, }); @@ -62,4 +63,44 @@ describe('validationMixin', () => { wrapper.vm.$t('SLA.FORM.NAME.MINIMUM_LENGTH_ERROR') ); }); + + it('should accept valid threshold values', () => { + wrapper.setData({ thresholdTime: 10 }); + wrapper.vm.$v.thresholdTime.$touch(); + expect(wrapper.vm.getThresholdTimeErrorMessage).toBe(wrapper.vm.$t('')); + + wrapper.setData({ thresholdTime: 10.5 }); + wrapper.vm.$v.thresholdTime.$touch(); + expect(wrapper.vm.getThresholdTimeErrorMessage).toBe(wrapper.vm.$t('')); + }); + + it('should not return invalid format error message if thresholdTime is empty but not touched', () => { + wrapper.setData({ thresholdTime: '' }); + expect(wrapper.vm.getThresholdTimeErrorMessage).toBe(''); + }); + + it('should return invalid format error message if thresholdTime has an invalid format', () => { + wrapper.setData({ thresholdTime: 'fsdfsdfsdfsd' }); + wrapper.vm.$v.thresholdTime.$touch(); + + expect(wrapper.vm.getThresholdTimeErrorMessage).toBe( + wrapper.vm.$t('SLA.FORM.THRESHOLD_TIME.INVALID_FORMAT_ERROR') + ); + }); + + it('should reject invalid threshold values', () => { + wrapper.setData({ thresholdTime: 0 }); + wrapper.vm.$v.thresholdTime.$touch(); + expect(wrapper.vm.getThresholdTimeErrorMessage).toBe( + wrapper.vm.$t('SLA.FORM.THRESHOLD_TIME.INVALID_FORMAT_ERROR') + ); + }); + + it('should reject invalid threshold values', () => { + wrapper.setData({ thresholdTime: -1 }); + wrapper.vm.$v.thresholdTime.$touch(); + expect(wrapper.vm.getThresholdTimeErrorMessage).toBe( + wrapper.vm.$t('SLA.FORM.THRESHOLD_TIME.INVALID_FORMAT_ERROR') + ); + }); }); diff --git a/app/javascript/dashboard/routes/dashboard/settings/sla/validationMixin.js b/app/javascript/dashboard/routes/dashboard/settings/sla/validationMixin.js index 28f7436c8997..d086c6072b16 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/sla/validationMixin.js +++ b/app/javascript/dashboard/routes/dashboard/settings/sla/validationMixin.js @@ -11,5 +11,16 @@ export default { } return errorMessage; }, + getThresholdTimeErrorMessage() { + let errorMessage = ''; + if (this.$v.thresholdTime.$error) { + if (!this.$v.thresholdTime.numeric || !this.$v.thresholdTime.minValue) { + errorMessage = this.$t( + 'SLA.FORM.THRESHOLD_TIME.INVALID_FORMAT_ERROR' + ); + } + } + return errorMessage; + }, }, }; diff --git a/app/javascript/dashboard/routes/dashboard/settings/sla/validations.js b/app/javascript/dashboard/routes/dashboard/settings/sla/validations.js index bda4b95560e1..024aa6636d3e 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/sla/validations.js +++ b/app/javascript/dashboard/routes/dashboard/settings/sla/validations.js @@ -1,8 +1,17 @@ -import { required, minLength } from 'vuelidate/lib/validators'; +import { + required, + minLength, + minValue, + decimal, +} from 'vuelidate/lib/validators'; export default { name: { required, minLength: minLength(2), }, + thresholdTime: { + decimal, + minValue: minValue(0.001), + }, }; diff --git a/package.json b/package.json index f7a2f86f7996..70ab8a666c38 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "dependencies": { "@braid/vue-formulate": "^2.5.2", "@chatwoot/prosemirror-schema": "1.0.5", - "@chatwoot/utils": "^0.0.21", + "@chatwoot/utils": "^0.0.23", "@hcaptcha/vue-hcaptcha": "^0.3.2", "@june-so/analytics-next": "^2.0.0", "@radix-ui/colors": "^1.0.1", diff --git a/yarn.lock b/yarn.lock index cc9a6f34cad9..b28813887c73 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3177,10 +3177,10 @@ prosemirror-utils "^0.9.6" prosemirror-view "^1.17.2" -"@chatwoot/utils@^0.0.21": - version "0.0.21" - resolved "https://registry.yarnpkg.com/@chatwoot/utils/-/utils-0.0.21.tgz#f9116daac0514a8a8fa6ce594efff10062222be0" - integrity sha512-eUDJ1K5x1rFlBywRctU3hXXiJ1U0EZiklowNl/YJOh1/BWDns4It3DWrQmAcjvsNbEUNWMfY+ShJmjdeei71Cw== +"@chatwoot/utils@^0.0.23": + version "0.0.23" + resolved "https://registry.yarnpkg.com/@chatwoot/utils/-/utils-0.0.23.tgz#e961fd87ef9ee19c442bfcedac5fe0be2ef37726" + integrity sha512-BQ7DprXr7FIkSbHdDc1WonwH0rt/+B+WaaLaXNMjCcxJgkX/gZ8QMltruOfRp/S8cFyd9JfFQhNF0T9lz1OMvA== dependencies: date-fns "^2.29.1"