@7365admin1/layer-common 4.7.2 → 4.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @iservice365/layer-common
2
2
 
3
+ ## 4.7.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 24367db: Connect the feedback and work-order Chat panel to the real comment thread. It
8
+ shipped as a mockup - five hardcoded messages from "Tan Wei" dated 06/28/2024, a
9
+ textarea with no model and a Send button wired to nothing - while a complete
10
+ `useComment` composable sat in the layer with no callers. The panel now loads,
11
+ groups by day, aligns by sender, sends, and attaches photos. The bubble matches
12
+ the mobile apps field for field, its avatar renders an actual profile picture,
13
+ and a load failure is reported rather than shown as an empty thread.
14
+ - a4737bd: Show the completion photos on the area checklist history screen. The API has
15
+ always returned the file ids of the photos a technician took when completing a
16
+ unit; nothing drew them, so the office had no way to see the proof of work.
17
+ Each unit now shows its photos as thumbnails that open full size.
18
+
3
19
  ## 4.7.2
4
20
 
5
21
  ### Patch Changes
@@ -963,11 +979,11 @@
963
979
  `utils/console-tier.ts` + `composables/useConsoleTier.ts` mirror the server's
964
980
  own rule from two endpoints the console already calls, unprojected:
965
981
 
966
- GET /api/members/user/:user/app/admin the Seven365 staff membership
967
- GET /api/roles/id/:role that membership's role document
982
+ GET /api/members/user/:user/app/admin the Seven365 staff membership
983
+ GET /api/roles/id/:role that membership's role document
968
984
 
969
- owner = member.type === "admin" && role.type === "admin" && role.default === true
970
- staff = member.type === "admin" && role.type === "admin"
985
+ owner = member.type === "admin" && role.type === "admin" && role.default === true
986
+ staff = member.type === "admin" && role.type === "admin"
971
987
 
972
988
  `role.default` is the marker because it is the only property of a platform
973
989
  staff role no API caller can set - `role.controller.ts` validates create and
@@ -170,6 +170,63 @@
170
170
  />
171
171
  </v-col>
172
172
  </v-row>
173
+
174
+ <!-- The photos the technician took to complete the
175
+ unit. The API has always returned these ids on the
176
+ history record; nothing drew them, so the office
177
+ had no way to see the proof of work. -->
178
+ <v-row
179
+ v-if="unit.attachment?.length"
180
+ no-gutters
181
+ class="pb-2"
182
+ >
183
+ <v-col cols="12">
184
+ <div class="text-body-2 text-medium-emphasis mb-1">
185
+ Attached Photos ({{ unit.attachment.length }})
186
+ </div>
187
+ <div class="d-flex flex-wrap ga-2">
188
+ <v-img
189
+ v-for="id in unit.attachment"
190
+ :key="id"
191
+ :src="getFileUrl(id)"
192
+ width="72"
193
+ height="72"
194
+ cover
195
+ rounded="lg"
196
+ class="border-thin"
197
+ style="cursor: zoom-in; flex: 0 0 auto"
198
+ @click="openFullImage(getFileUrl(id))"
199
+ >
200
+ <template v-slot:placeholder>
201
+ <v-row
202
+ class="fill-height ma-0"
203
+ align="center"
204
+ justify="center"
205
+ >
206
+ <v-progress-circular
207
+ indeterminate
208
+ size="20"
209
+ color="grey-lighten-4"
210
+ />
211
+ </v-row>
212
+ </template>
213
+ <template v-slot:error>
214
+ <v-row
215
+ class="fill-height ma-0"
216
+ align="center"
217
+ justify="center"
218
+ >
219
+ <v-icon
220
+ icon="mdi-image-broken"
221
+ size="24"
222
+ color="grey"
223
+ />
224
+ </v-row>
225
+ </template>
226
+ </v-img>
227
+ </div>
228
+ </v-col>
229
+ </v-row>
173
230
  </v-list-item>
174
231
 
175
232
  <v-divider
@@ -186,6 +243,22 @@
186
243
  </AppCard>
187
244
  </v-col>
188
245
  </v-row>
246
+
247
+ <v-dialog v-model="showLightbox" max-width="900">
248
+ <v-card class="screen-modal">
249
+ <v-card-actions class="pa-2 justify-end">
250
+ <v-btn
251
+ icon="mdi-close"
252
+ variant="text"
253
+ class="screen-modal__close"
254
+ @click="showLightbox = false"
255
+ />
256
+ </v-card-actions>
257
+ <v-card-text class="screen-modal__body pa-2 pt-0">
258
+ <v-img :src="lightboxSrc" contain max-height="80vh" />
259
+ </v-card-text>
260
+ </v-card>
261
+ </v-dialog>
189
262
  </template>
190
263
 
191
264
  <script setup lang="ts">
@@ -227,6 +300,14 @@ watchEffect(() => {
227
300
  }
228
301
  });
229
302
 
303
+ const showLightbox = ref(false);
304
+ const lightboxSrc = ref("");
305
+
306
+ const openFullImage = (src: string) => {
307
+ lightboxSrc.value = src;
308
+ showLightbox.value = true;
309
+ };
310
+
230
311
  const createdAt = ref<string>("N/A");
231
312
  const createdBy = ref<string>("N/A");
232
313
  const timeOut = ref<string>("N/A");
@@ -1,62 +1,120 @@
1
1
  <template>
2
- <v-card class="chat-bubble screen-card mb-2 pa-4" width="400" elevation="0">
3
- <v-row no-gutters align="center">
4
- <v-col cols="auto" class="mr-3">
2
+ <v-card
3
+ class="chat-bubble screen-card pa-3"
4
+ :class="isCurrentUser ? 'chat-bubble--mine' : 'chat-bubble--theirs'"
5
+ elevation="0"
6
+ >
7
+ <v-row no-gutters align="start" class="flex-nowrap">
8
+ <v-col cols="auto" :class="isCurrentUser ? 'order-last ml-3' : 'mr-3'">
5
9
  <v-avatar class="chat-bubble__avatar" size="35">
6
- <v-img v-if="currentUser?.profile" width="15" height="15" />
10
+ <!-- Was `<v-img width="15" height="15" />` with no `src` at all, so a
11
+ sender with a profile picture got a blank 15px box instead of a
12
+ photo - and never fell through to their initials either. -->
13
+ <v-img v-if="avatarUrl" :src="avatarUrl" cover />
7
14
  <span v-else>{{ getNameInitials(senderName) }}</span>
8
15
  </v-avatar>
9
16
  </v-col>
10
17
 
11
- <v-col class="d-flex flex-column">
12
- <span class="chat-bubble__sender">{{ senderName }}</span>
13
- <span class="chat-bubble__sub">{{ role }}</span>
14
- </v-col>
15
- </v-row>
18
+ <v-col class="chat-bubble__body">
19
+ <div class="chat-bubble__sender">{{ senderName }}</div>
20
+ <div v-if="roleLabel" class="chat-bubble__sub">{{ roleLabel }}</div>
21
+
22
+ <div v-if="message" class="chat-bubble__text mt-2">{{ message }}</div>
23
+
24
+ <div v-if="attachments?.length" class="d-flex flex-wrap ga-2 mt-2">
25
+ <v-img
26
+ v-for="file in attachments"
27
+ :key="file.id"
28
+ :src="getFileUrl(file.id)"
29
+ width="110"
30
+ height="90"
31
+ cover
32
+ rounded="lg"
33
+ class="border-thin"
34
+ style="cursor: zoom-in; flex: 0 0 auto"
35
+ @click="emit('preview', getFileUrl(file.id))"
36
+ >
37
+ <template #placeholder>
38
+ <v-row class="fill-height ma-0" align="center" justify="center">
39
+ <v-progress-circular
40
+ indeterminate
41
+ size="20"
42
+ color="grey-lighten-4"
43
+ />
44
+ </v-row>
45
+ </template>
46
+ <template #error>
47
+ <v-row class="fill-height ma-0" align="center" justify="center">
48
+ <v-icon icon="mdi-image-broken" size="24" color="grey" />
49
+ </v-row>
50
+ </template>
51
+ </v-img>
52
+ </div>
16
53
 
17
- <v-row no-gutters class="mt-1">
18
- <v-col>
19
- <span class="chat-bubble__text py-2">{{ message }}</span>
20
-
21
- <v-row no-gutters justify="space-between" align="center" class="mt-1">
22
- <v-col cols="auto">
23
- <span class="chat-bubble__sub">{{ timestamp }}</span>
24
- </v-col>
25
- <v-col v-if="isCurrentUser" cols="auto" class="d-flex align-center">
26
- <v-icon size="16" class="chat-bubble__sub mr-1"
27
- >mdi-eye-outline</v-icon
28
- >
29
- <span class="chat-bubble__sub">{{ seenLabel }}</span>
30
- </v-col>
31
- </v-row>
54
+ <div class="chat-bubble__sub chat-bubble__time mt-2">
55
+ {{ timestamp }}
56
+ </div>
32
57
  </v-col>
33
58
  </v-row>
34
59
  </v-card>
35
60
  </template>
36
61
 
37
62
  <script setup lang="ts">
38
- defineProps<{
63
+ import { formatSenderRole } from "../../utils/chat-sender.ts";
64
+
65
+ /**
66
+ * One message bubble, drawn the same way for both people in the conversation
67
+ * and matching the mobile apps' bubble field for field: avatar, sender, role,
68
+ * message, photos, time.
69
+ *
70
+ * It used to be a fixed `width="400"` card with no left/right distinction, an
71
+ * avatar that could not render a photo, and a "Seen" line that only the current
72
+ * user's own messages carried.
73
+ */
74
+ const props = defineProps<{
39
75
  isCurrentUser: boolean;
40
76
  message: string;
41
77
  timestamp: string;
42
- seenLabel?: string;
43
78
  senderName: string;
44
79
  role?: string;
80
+ attachments?: TAttachment[];
81
+ avatarId?: string;
45
82
  }>();
46
83
 
47
- const { currentUser } = useLocalAuth();
84
+ const emit = defineEmits<{ (event: "preview", src: string): void }>();
85
+
48
86
  const { getNameInitials } = useUtils();
87
+ const { getFileUrl } = useFile();
88
+
89
+ const roleLabel = computed(() => formatSenderRole(props.role));
90
+ const avatarUrl = computed(() =>
91
+ props.avatarId ? getFileUrl(props.avatarId) : ""
92
+ );
49
93
  </script>
50
94
 
51
95
  <style scoped>
52
96
  .chat-bubble {
53
97
  font-family: var(--font-sans);
54
98
  color: var(--text);
99
+ /* Was a fixed 400px, which is both too wide on a narrow panel and unable to
100
+ grow on a wide one. The thread caps the column instead. */
101
+ max-width: 100%;
102
+ }
103
+
104
+ /* Alignment alone is a weak signal on a panel this narrow, so the two sides
105
+ also differ in fill - the same distinction the mobile bubbles make. */
106
+ .chat-bubble--mine {
107
+ background: var(--hover);
108
+ }
109
+
110
+ .chat-bubble--theirs {
111
+ background: var(--card);
112
+ }
113
+
114
+ .chat-bubble__body {
115
+ min-width: 0;
55
116
  }
56
117
 
57
- /* Was `color="surface-variant"` with the initials at `text-h5`, i.e. a 24px
58
- pair of letters in a 35px circle. The design's avatar is the tone wash with
59
- the accent ink, and the initials fit inside it. */
60
118
  .chat-bubble__avatar {
61
119
  background: var(--hover);
62
120
  color: var(--text2);
@@ -71,6 +129,8 @@ const { getNameInitials } = useUtils();
71
129
 
72
130
  .chat-bubble__text {
73
131
  font-size: var(--fs-cell);
132
+ white-space: pre-wrap;
133
+ overflow-wrap: anywhere;
74
134
  }
75
135
 
76
136
  /* The role, the timestamp and the seen label were `text-grey`, `text-caption`
@@ -79,4 +139,8 @@ const { getNameInitials } = useUtils();
79
139
  font-size: var(--fs-chip);
80
140
  color: var(--muted);
81
141
  }
142
+
143
+ .chat-bubble__time {
144
+ text-align: right;
145
+ }
82
146
  </style>
@@ -11,57 +11,127 @@
11
11
  </div>
12
12
 
13
13
  <v-sheet
14
+ ref="threadEl"
14
15
  class="chat-panel__thread overflow-y-auto flex-grow-1 pa-3"
15
16
  :style="{ height: 'calc(100vh - 300px)', overflowX: 'hidden' }"
16
17
  >
17
- <v-row
18
- v-for="(msg, i) in messages"
19
- :key="i"
20
- no-gutters
21
- :justify="msg.isCurrentUser ? 'end' : 'start'"
22
- class="mb-2"
18
+ <div v-if="isCommentsLoaded" class="d-flex justify-center py-6">
19
+ <v-progress-circular indeterminate size="28" color="primary" />
20
+ </div>
21
+
22
+ <div
23
+ v-else-if="!days.length"
24
+ class="text-center text-medium-emphasis py-6"
23
25
  >
24
- <v-col cols="auto">
25
- <ChatBubbles
26
- :isCurrentUser="msg.isCurrentUser"
27
- :message="msg.message"
28
- :timestamp="msg.timestamp"
29
- :seenLabel="msg.seenLabel"
30
- :senderName="msg.senderName"
31
- :role="msg.role"
32
- />
33
- </v-col>
34
- </v-row>
26
+ No messages yet
27
+ </div>
28
+
29
+ <template v-for="group in days" :key="group.day">
30
+ <div class="d-flex justify-center my-3">
31
+ <span class="chat-panel__day px-3 py-1">{{ group.day }}</span>
32
+ </div>
33
+
34
+ <v-row
35
+ v-for="msg in group.messages"
36
+ :key="msg._id"
37
+ no-gutters
38
+ :justify="isMine(msg) ? 'end' : 'start'"
39
+ class="mb-2"
40
+ >
41
+ <v-col cols="11" sm="10">
42
+ <div
43
+ class="d-flex"
44
+ :class="isMine(msg) ? 'justify-end' : 'justify-start'"
45
+ >
46
+ <ChatBubbles
47
+ :isCurrentUser="isMine(msg)"
48
+ :message="msg.comment"
49
+ :timestamp="formatTime(msg.createdAt)"
50
+ :senderName="isMine(msg) ? 'You' : msg.createdByName || 'User'"
51
+ :role="msg.createdByType"
52
+ :attachments="msg.attachments"
53
+ :avatarId="msg.createdByProfile"
54
+ @preview="openPreview"
55
+ />
56
+ </div>
57
+ </v-col>
58
+ </v-row>
59
+ </template>
35
60
  </v-sheet>
36
61
 
37
62
  <v-card class="screen-card mx-4 mb-4 mt-2 pa-3" elevation="0">
38
63
  <v-row no-gutters align="end">
39
64
  <v-col cols="10">
40
65
  <v-textarea
66
+ v-model="draft"
41
67
  class="filter-field"
42
68
  label="Message"
43
69
  auto-grow
44
70
  hide-details
45
71
  rows="1"
46
72
  variant="outlined"
73
+ :disabled="sending"
74
+ @keydown.enter.exact.prevent="send"
47
75
  />
48
76
  </v-col>
49
77
  <v-col cols="2" class="pl-2">
50
- <v-btn class="screen-btn-primary" variant="flat" block>Send</v-btn>
78
+ <v-btn
79
+ class="screen-btn-primary"
80
+ variant="flat"
81
+ block
82
+ :loading="sending"
83
+ :disabled="!canSend"
84
+ @click="send"
85
+ >
86
+ Send
87
+ </v-btn>
51
88
  </v-col>
52
89
  </v-row>
53
90
 
91
+ <div v-if="photos.length" class="d-flex flex-wrap ga-2 mt-3">
92
+ <div
93
+ v-for="(photo, index) in photos"
94
+ :key="photo.id"
95
+ class="chat-panel__pending"
96
+ >
97
+ <v-img
98
+ :src="getFileUrl(photo.id)"
99
+ width="64"
100
+ height="64"
101
+ cover
102
+ rounded="lg"
103
+ />
104
+ <v-btn
105
+ icon="mdi-close"
106
+ size="x-small"
107
+ variant="flat"
108
+ class="chat-panel__pending-remove"
109
+ @click="photos.splice(index, 1)"
110
+ />
111
+ </div>
112
+ </div>
113
+
54
114
  <v-divider class="my-2" />
55
115
 
56
116
  <v-row justify="start" no-gutters align="center">
57
117
  <v-col cols="auto">
58
- <v-icon size="20" class="chat-panel__tool mr-3">mdi-paperclip</v-icon>
59
- </v-col>
60
-
61
- <v-col cols="auto">
62
- <v-icon size="20" class="chat-panel__tool mr-3"
63
- >mdi-emoticon-happy-outline</v-icon
118
+ <v-btn
119
+ icon
120
+ density="compact"
121
+ variant="text"
122
+ :loading="uploading"
123
+ @click="fileInput?.click()"
64
124
  >
125
+ <v-icon size="20" class="chat-panel__tool">mdi-paperclip</v-icon>
126
+ </v-btn>
127
+ <input
128
+ ref="fileInput"
129
+ type="file"
130
+ accept="image/*"
131
+ multiple
132
+ hidden
133
+ @change="onFilesPicked"
134
+ />
65
135
  </v-col>
66
136
 
67
137
  <v-col cols="auto">
@@ -94,57 +164,185 @@
94
164
  </v-col>
95
165
  </v-row>
96
166
  </v-card>
167
+
168
+ <v-dialog v-model="showPreview" max-width="900">
169
+ <v-card class="screen-modal">
170
+ <v-card-actions class="pa-2 justify-end">
171
+ <v-btn
172
+ icon="mdi-close"
173
+ variant="text"
174
+ class="screen-modal__close"
175
+ @click="showPreview = false"
176
+ />
177
+ </v-card-actions>
178
+ <v-card-text class="screen-modal__body pa-2 pt-0">
179
+ <v-img :src="previewSrc" contain max-height="80vh" />
180
+ </v-card-text>
181
+ </v-card>
182
+ </v-dialog>
183
+
184
+ <Snackbar v-model="showMessage" :text="message" :color="messageColor" />
97
185
  </v-sheet>
98
186
  </template>
99
187
 
100
188
  <script setup lang="ts">
101
- defineProps({
189
+ import { groupChatByDay } from "../../utils/chat-sender.ts";
190
+
191
+ /**
192
+ * The comment thread under a feedback or a work order.
193
+ *
194
+ * This panel used to be a mockup: five hardcoded messages from "Tan Wei" dated
195
+ * 06/28/2024, a textarea with no model, and a Send button wired to nothing. So
196
+ * on the web the chat showed the same fake conversation on every record, and
197
+ * nothing anyone typed was ever sent - while the mobile apps had been reading
198
+ * and writing the real thread through `/api/comments/v1` all along.
199
+ */
200
+ const props = defineProps({
102
201
  type: {
103
202
  type: String,
104
203
  default: "feedback",
105
204
  },
205
+ /** The feedback or work order this thread hangs off. */
206
+ recordId: {
207
+ type: String,
208
+ default: "",
209
+ },
106
210
  });
107
211
 
108
- const messages = [
109
- {
110
- isCurrentUser: true,
111
- message: "Hello we would like to transfer this task...",
112
- timestamp: "06/28/2024 08:40",
113
- seenLabel: "Seen",
114
- senderName: "You",
115
- role: "Site Personnel",
116
- },
117
- {
118
- isCurrentUser: false,
119
- message: "Sure. Let me take care of that.",
120
- timestamp: "06/28/2024 08:42",
121
- senderName: "Tan Wei",
122
- role: "Manager",
123
- },
124
- {
125
- isCurrentUser: true,
126
- message: "Thanks!",
127
- timestamp: "06/28/2024 08:43",
128
- seenLabel: "Seen",
129
- senderName: "You",
130
- role: "Site Personnel",
131
- },
132
- {
133
- isCurrentUser: false,
134
- message: "No worries!",
135
- timestamp: "06/28/2024 08:44",
136
- senderName: "Tan Wei",
137
- role: "Manager",
138
- },
139
- {
140
- isCurrentUser: true,
141
- message: "Let me know if you need anything else.",
142
- timestamp: "06/28/2024 08:45",
143
- seenLabel: "Seen",
144
- senderName: "You",
145
- role: "Site Personnel",
146
- },
147
- ];
212
+ // `useComment` already existed with everything this panel needs - the fetch,
213
+ // the post, and the read receipts - and had not a single caller, because the
214
+ // panel it was written for was never wired up.
215
+ const { comments, isCommentsLoaded, setComments, addComment } = useComment();
216
+ const { currentUser } = useLocalAuth();
217
+ const { getFileUrl, addFile } = useFile();
218
+
219
+ const sending = ref(false);
220
+ const uploading = ref(false);
221
+ const draft = ref("");
222
+ const photos = ref<{ id: string; name?: string }[]>([]);
223
+ const fileInput = ref<HTMLInputElement | null>(null);
224
+ const threadEl = ref<any>(null);
225
+
226
+ const showPreview = ref(false);
227
+ const previewSrc = ref("");
228
+ const showMessage = ref(false);
229
+ const message = ref("");
230
+ const messageColor = ref("error");
231
+
232
+ const notify = (text: string, color = "error") => {
233
+ message.value = text;
234
+ messageColor.value = color;
235
+ showMessage.value = true;
236
+ };
237
+
238
+ const formatDay = (value: string | Date) =>
239
+ new Date(value).toLocaleDateString("en-US", {
240
+ year: "numeric",
241
+ month: "short",
242
+ day: "numeric",
243
+ });
244
+
245
+ const formatTime = (value?: string | Date) =>
246
+ value
247
+ ? new Date(value).toLocaleTimeString("en-US", {
248
+ hour: "2-digit",
249
+ minute: "2-digit",
250
+ })
251
+ : "";
252
+
253
+ // `setComments` hands the thread back oldest first, which is already reading
254
+ // order for a top-to-bottom panel.
255
+ const days = computed(() => groupChatByDay(comments.value, formatDay));
256
+
257
+ // `createdBy` is the author's user id; the API returns it unpopulated.
258
+ const isMine = (msg: TCommentChat) =>
259
+ !!currentUser.value?._id &&
260
+ String(msg.createdBy) === String(currentUser.value._id);
261
+
262
+ const canSend = computed(
263
+ () => !sending.value && (!!draft.value.trim() || photos.value.length > 0)
264
+ );
265
+
266
+ const threadKind = computed(() =>
267
+ props.type === "workOrder" ? "workOrder" : "feedback"
268
+ );
269
+
270
+ const scrollToLatest = () => {
271
+ nextTick(() => {
272
+ const el = threadEl.value?.$el ?? threadEl.value;
273
+ if (el) el.scrollTop = el.scrollHeight;
274
+ });
275
+ };
276
+
277
+ const load = async () => {
278
+ if (!props.recordId) {
279
+ comments.value = [];
280
+ return;
281
+ }
282
+ try {
283
+ await setComments(props.recordId, threadKind.value);
284
+ scrollToLatest();
285
+ } catch (error: any) {
286
+ notify(error?.data?.message || "The chat could not be loaded.");
287
+ }
288
+ };
289
+
290
+ watch(() => props.recordId, load, { immediate: true });
291
+
292
+ const onFilesPicked = async (event: Event) => {
293
+ const input = event.target as HTMLInputElement;
294
+ const files = Array.from(input.files ?? []);
295
+ input.value = "";
296
+ if (!files.length) return;
297
+
298
+ uploading.value = true;
299
+ try {
300
+ for (const file of files) {
301
+ const uploaded = await addFile(file);
302
+ const id = uploaded?.id;
303
+ // No id means nothing to reference; saying so beats attaching a broken
304
+ // image to the message.
305
+ if (!id) throw new Error("The photo upload did not return a file id.");
306
+ photos.value.push({ id, name: file.name });
307
+ }
308
+ } catch (error: any) {
309
+ notify(error?.message || "The photo could not be uploaded.");
310
+ } finally {
311
+ uploading.value = false;
312
+ }
313
+ };
314
+
315
+ const send = async () => {
316
+ if (!canSend.value) return;
317
+ if (!props.recordId) return notify("This record has no id to post against.");
318
+ if (!currentUser.value?._id) return notify("Please sign in again to reply.");
319
+
320
+ sending.value = true;
321
+ try {
322
+ await addComment({
323
+ comment: draft.value.trim(),
324
+ createdBy: String(currentUser.value._id),
325
+ workOrder: threadKind.value === "workOrder" ? props.recordId : "",
326
+ feedback: threadKind.value === "feedback" ? props.recordId : "",
327
+ attachments: photos.value as TAttachment[],
328
+ seenByNames: "",
329
+ } as unknown as TCommentChat);
330
+ // Nothing is cleared until the server has taken it, so a failed send does
331
+ // not silently swallow what was typed.
332
+ draft.value = "";
333
+ photos.value = [];
334
+ await load();
335
+ } catch (error: any) {
336
+ notify(error?.data?.message || "The message could not be sent.");
337
+ } finally {
338
+ sending.value = false;
339
+ }
340
+ };
341
+
342
+ const openPreview = (src: string) => {
343
+ previewSrc.value = src;
344
+ showPreview.value = true;
345
+ };
148
346
 
149
347
  const quickChatOptions = [
150
348
  "This is all noted, thank you!",
@@ -154,9 +352,8 @@ const quickChatOptions = [
154
352
  "We are here to help.",
155
353
  ];
156
354
 
157
- // Placeholder: choosing a quick-chat option is not wired to anything yet.
158
355
  const selectQuickChat = (msg: string) => {
159
- void msg;
356
+ draft.value = draft.value ? `${draft.value} ${msg}` : msg;
160
357
  };
161
358
  </script>
162
359
 
@@ -177,6 +374,23 @@ const selectQuickChat = (msg: string) => {
177
374
  background: var(--bg);
178
375
  }
179
376
 
377
+ .chat-panel__day {
378
+ background: var(--hover);
379
+ color: var(--muted);
380
+ border-radius: 10px;
381
+ font-size: var(--fs-chip);
382
+ }
383
+
384
+ .chat-panel__pending {
385
+ position: relative;
386
+ }
387
+
388
+ .chat-panel__pending-remove {
389
+ position: absolute;
390
+ top: -6px;
391
+ right: -6px;
392
+ }
393
+
180
394
  /* Was a bare icon and one `color="gray"` - not a token, and not the same tone
181
395
  as the icon beside it. */
182
396
  .chat-panel__tool {
@@ -4,7 +4,7 @@
4
4
 
5
5
  <v-col cols="12" xl="7" lg="7" md="7" class="fill-height">
6
6
  <div class="panel-container border-e">
7
- <ChatMessage :type="'feedback'" />
7
+ <ChatMessage :type="'feedback'" :record-id="String(feedback?._id || '')" />
8
8
  </div>
9
9
  </v-col>
10
10
 
@@ -3,7 +3,7 @@
3
3
  <v-row no-gutters class="fill-height">
4
4
  <v-col cols="12" xl="7" lg="7" md="7" class="fill-height">
5
5
  <div class="panel-container border-e">
6
- <ChatMessage :type="'workOrder'" />
6
+ <ChatMessage :type="'workOrder'" :record-id="String(workOrder?._id || '')" />
7
7
  </div>
8
8
  </v-col>
9
9
  <v-col cols="12" xl="5" lg="5" md="5" class="fill-height">
@@ -111,10 +111,18 @@ export default function useComment() {
111
111
  );
112
112
 
113
113
  if (Array.isArray(updateSeenIds) && updateSeenIds.length > 0) {
114
- const seenBy = await updateSeenBy(updateSeenIds, currentUser.value?._id);
114
+ const seenBy = await updateSeenBy(
115
+ updateSeenIds,
116
+ currentUser.value?._id
117
+ );
115
118
  }
116
119
  } catch (error) {
120
+ // Was swallowed here, which is why a thread that failed to load was
121
+ // indistinguishable from a thread with no messages in it. The caller
122
+ // decides what to tell the user.
117
123
  console.error("error :", error);
124
+ comments.value = [];
125
+ throw error;
118
126
  } finally {
119
127
  isCommentsLoaded.value = false;
120
128
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@7365admin1/layer-common",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "4.7.2",
5
+ "version": "4.7.3",
6
6
  "author": "7365admin1",
7
7
  "main": "./nuxt.config.ts",
8
8
  "//files": "What a consumer extending this layer actually loads. Without this npm ships the whole working tree - the changesets, the CI workflows, the render harness in tools/ and any scratch directory that happened to exist at publish time. Nuxt resolves a layer by directory, so every runtime directory below has to stay listed; adding a new top-level runtime directory means adding it here too.",
@@ -36,6 +36,8 @@ declare type TUnitChecklistItem = {
36
36
  remarks: string;
37
37
  completedByName?: string;
38
38
  timestamp?: string;
39
+ /** File ids of the photos taken when the unit was completed. */
40
+ attachment?: string[];
39
41
  };
40
42
 
41
43
  declare type TChecklistSet = {
@@ -9,6 +9,8 @@ declare type TCommentChat = {
9
9
  updatedAt?: string;
10
10
  createdByName?: string;
11
11
  createdByType?: string;
12
+ /** The sender's avatar file id. The API has always returned it. */
13
+ createdByProfile?: string;
12
14
  justify?: string;
13
15
  feedback?: string;
14
16
  seenByNames: Person;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * How a message's sender is described under their name in a chat thread.
3
+ *
4
+ * `createdByType` is the raw `user.type` from the API - lowercase, sometimes
5
+ * hyphenated, sometimes empty. The mobile chat used to print it as-is for
6
+ * everything except "site", so a resident read "provider" while a technician on
7
+ * the same thread read "Site Personnel". The web read nothing at all, because
8
+ * the whole panel was a mockup. Nothing here invents a job title: the one name
9
+ * the product already uses is kept, and anything else is simply made readable.
10
+ *
11
+ * Kept in step with `src/utils/chat-sender.ts` in the six mobile apps.
12
+ */
13
+ export function formatSenderRole(
14
+ type: string | undefined | null,
15
+ sitePersonnelLabel = "Site Personnel"
16
+ ): string {
17
+ const raw = (type ?? "").trim();
18
+ if (!raw) return "";
19
+ if (raw.toLowerCase() === "site") return sitePersonnelLabel;
20
+
21
+ return raw
22
+ .split(/[-_\s]+/)
23
+ .filter(Boolean)
24
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
25
+ .join(" ");
26
+ }
27
+
28
+ /**
29
+ * A thread already in reading order (oldest first, as `useComment.setComments`
30
+ * sorts it), split into one group per day so the panel can draw a single day
31
+ * heading above each day's messages instead of a date on every bubble.
32
+ */
33
+ export function groupChatByDay<T extends { createdAt?: string | Date }>(
34
+ comments: T[],
35
+ formatDay: (value: string | Date) => string
36
+ ): { day: string; messages: T[] }[] {
37
+ const days: { day: string; messages: T[] }[] = [];
38
+
39
+ for (const message of comments) {
40
+ const day = message.createdAt ? formatDay(message.createdAt) : "";
41
+ const current = days[days.length - 1];
42
+ if (current && current.day === day) current.messages.push(message);
43
+ else days.push({ day, messages: [message] });
44
+ }
45
+
46
+ return days;
47
+ }