forked from EnergySage/es-ds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EsReview.vue
382 lines (374 loc) · 11.3 KB
/
EsReview.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<template>
<div
:id="id"
class="review-holder p-100 p-lg-0"
v-bind="$attrs">
<div class="d-flex mb-50 mb-lg-100">
<div class="d-flex flex-grow-1">
<EsRating
:rating="rating"
:read-only="readOnly" />
<template v-if="isReviewOwner">
<b-link
data-testid="edit-review"
class="d-flex align-items-center"
@click="$emit('editReview', id)">
<IconPencil
class="ml-25"
width="20px"
height="20px" />
</b-link>
</template>
<template v-if="reportFlagVisible">
<b-link
data-testid="report-review"
class="d-flex align-items-center"
@click="$emit('reportReview', id)">
<IconFlag
class="ml-1"
width="20px"
height="20px" />
</b-link>
</template>
<div
v-if="updatedComment && commentLimit"
class="ml-auto ml-lg-100">
<es-badge
data-testid="badge-test"
variant="info"
@click="$emit('showMore')">
Updated
</es-badge>
</div>
</div>
</div>
<div class="mb-100">
<h4
v-if="title"
class="font-size-200 font-weight-bold text-truncate mb-50"
data-testid="title-test">
{{ title }}
</h4>
<EsViewMore
v-if="commentLimit"
class="comment-holder overflow-hidden"
:content="updatedComment || comment"
:length="commentLimit"
@click="$emit('showMore')" />
<template v-else>
<template v-if="!commentLimit && updatedComment">
<div data-testid="both-comments">
<span class="d-inline-block font-weight-bolder">Updated review: </span>
{{ updatedComment }}
<div
v-if="modified"
class="font-size-75 mt-50">
<span class="d-none d-lg-inline-block">Updated on </span>
{{ localeDate(modified) }}
</div>
<div class="mt-50">
<span class="d-inline-block font-weight-bolder">Previous review: </span>
{{ comment }}
</div>
</div>
</template>
<template v-else>
{{ updatedComment || comment }}
</template>
</template>
</div>
<div class="d-flex flex-nowrap">
<small
v-if="displayDate"
class="d-flex align-items-center text-nowrap details-holder">
<span
class="name-holder d-inline-block text-truncate pr-25"
data-testid="subtext-test">
<span class="d-none d-lg-inline-block">{{ displayDateText }}</span>
<IconVerified
v-if="certified"
class="d-lg-none mr-50 text-success"
width="20px"
height="20px" />
{{ reviewerName }}
</span>
<span class="date-holder">on {{ localeDate(displayDate) }}</span>
</small>
</div>
<div
v-if="certified"
class="d-none d-lg-flex mt-50 align-items-center font-size-75">
<IconVerified
class="mr-50 text-success"
width="20px"
height="20px" />
Verified Shopper
</div>
<div
v-if="response && commentLimit"
class="d-flex flex-nowrap align-items-center font-size-75 mt-50 mt-lg-100">
<b-link
data-testid="view-response"
@click="$emit('showMore')">
View provider response
</b-link>
</div>
<div
v-if="response && !commentLimit"
data-testid="developer-response">
<b-row class="mt-100">
<b-col
cols="12"
lg="1"
class="dev-logo-holder">
<b-row
align-v="center"
class="">
<b-col
v-if="developerLogo"
cols="2"
lg="12"
class="pr-0">
<b-img
class="rounded"
fluid
:src="developerLogo"
:alt="`${developerName} logo`" />
</b-col>
<b-col
:cols="developerLogo ? 10 : 12"
lg="12"
class="d-lg-none">
<span class="font-weight-bolder m-0 mb-lg-50">
Response from {{ developerName }}
</span>
</b-col>
</b-row>
</b-col>
<b-col
cols="12"
:lg="developerLogo ? 11 : 12"
class="pt-lg-0 pt-50 pl-lg-100">
<p class="d-none d-lg-block font-weight-bolder m-0 mb-lg-50">
Response from {{ developerName }}
</p>
{{ response }}
<p class="font-size-75 m-0 mt-50 mt-lg-100">
Responded on {{ localeDate(responseDate) }}
</p>
</b-col>
</b-row>
</div>
</div>
</template>
<script lang="js">
import { BLink, BImg } from 'bootstrap-vue';
import IconVerified from '../lib-icons/icon-verified.vue';
import IconPencil from '../lib-icons/icon-pencil.vue';
import IconFlag from '../lib-icons/icon-flag.vue';
import EsRating from './EsRating.vue';
import EsViewMore from './EsViewMore.vue';
import EsBadge from './EsBadge.vue';
export default {
name: 'EsReview',
components: {
EsRating, EsViewMore, IconVerified, IconPencil, IconFlag, BLink, EsBadge, BImg,
},
props: {
/**
* ID
*/
id: {
type: [String, Number],
required: true,
},
/**
* Current user id
*/
userId: {
type: [String, Number, null],
required: false,
default: null,
},
/**
* Reviewer Name
*/
reviewerName: {
required: true,
type: String,
},
/**
* User id of user left the review
*/
reviewerId: {
required: false,
type: [String, Number, null],
default: null,
},
/**
* Certified
*/
certified: {
default: false,
type: Boolean,
},
/**
* Created Date
*/
created: {
default: () => new Date(),
type: Date,
},
/**
* Modified Date
*/
modified: {
default: null,
type: Date,
},
/**
* Rating
*/
rating: {
required: true,
type: Number,
validator: (num) => num >= 0 && num <= 5,
},
/**
* Review Title
*/
title: {
default: '',
type: String,
},
/**
* Review Comment
*/
comment: {
required: true,
type: String,
},
/**
* Updated Comment
*
* Used in es-cdgm when a user changes
* their original comment this field reflects
* the updated comment and comment
* retains the original.
*/
updatedComment: {
required: false,
type: String,
default: '',
},
/**
* Review Comment Truncation Limit
* Also indicates whether to show the modal view of component
*/
commentLimit: {
default: 225,
type: [Number, Boolean],
},
/**
* Developer Response
*/
response: {
required: false,
type: String,
default: null,
},
/**
* Logo of responding developer
*/
developerLogo: {
required: false,
type: String,
default: '',
},
/**
* Date developer created/updated
* their response
*/
responseDate: {
required: false,
type: Date,
default: null,
},
/**
* Developer name
*/
developerName: {
required: false,
type: String,
default: '',
},
/**
* Whether we want to show the report flag
*/
reportFlagVisible: {
required: false,
type: Boolean,
default: false,
},
/**
* Disable changing the rating
*/
readOnly: {
type: Boolean,
default: true,
},
},
computed: {
displayDate() {
return (this.updatedComment && this.commentLimit) ? this.modified || null : this.created;
},
displayDateText() {
if (this.updatedComment && this.commentLimit) {
if (this.modified) {
return 'Updated by ';
}
return '';
}
return 'Posted by ';
},
isReviewOwner() {
if (!this.userId || !this.reviewerId) {
return false;
}
return this.userId.toString() === this.reviewerId.toString();
},
},
methods: {
localeDate(date) {
if (date) {
// Displays DD/MM/YYYY
return new Date(date).toLocaleDateString();
}
return '';
},
},
};
</script>
<style lang="scss" scoped>
@use "~@energysage/es-bs-base/scss/variables" as variables;
@use "~@energysage/es-bs-base/scss/mixins/breakpoints" as breakpoints;
.review-holder {
.details-holder {
max-width: 70%;
}
}
.dev-logo-holder {
max-width: 300px;
}
.title {
@include breakpoints.media-breakpoint-down(md) {
font-size: variables.$font-size-base;
}
}
@include breakpoints.media-breakpoint-down(md) {
.review-holder {
border: 1px solid variables.$border-color;
border-radius: 0.75rem;
}
}
</style>