@buerokratt-ria/common-gui-components 0.0.20 → 0.0.22

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
@@ -4,6 +4,14 @@ All changes to this project will be documented in this file.
4
4
 
5
5
  ## Template [MajorVersion.MediterraneanVersion.MinorVersion] - DD-MM-YYYY
6
6
 
7
+ ## [0.0.22] - 01-07-2025
8
+
9
+ - Handled Previous Messages Edge Case in Buttons
10
+
11
+ ## [0.0.21] - 30-06-2025
12
+
13
+ - Fix Message With Buttons View.
14
+
7
15
  ## [0.0.20] - 21-05-2025
8
16
 
9
17
  - Making chat view go take all vertical space.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buerokratt-ria/common-gui-components",
3
- "version": "0.0.20",
3
+ "version": "0.0.22",
4
4
  "description": "Common GUI components and pre defined templates.",
5
5
  "main": "index.ts",
6
6
  "author": "ExiRai",
@@ -6,7 +6,7 @@
6
6
  margin: 0.3rem 0 0.7rem 0;
7
7
 
8
8
  span {
9
- padding: 0 0.5rem;
9
+ padding: 0.25rem 0.5rem;
10
10
  background-color: get-color(sea-green-12);
11
11
  color: get-color(white);
12
12
  border-radius: 8px;
@@ -1,4 +1,4 @@
1
- import { FC } from 'react';
1
+ import React, { FC } from "react";
2
2
  import { MessageButton } from 'types/message';
3
3
  import './ButtonMessage.scss';
4
4
 
@@ -9,8 +9,8 @@ type ButtonMessageProps = {
9
9
  const ButtonMessage: FC<ButtonMessageProps> = ({ buttons }) => {
10
10
  return (
11
11
  <div className='button-container'>
12
- {buttons.map(({title, payload}) =>
13
- <span key={title}>{title}({payload})</span>
12
+ {buttons.map(({title}) =>
13
+ <span key={title}>{title}</span>
14
14
  )}
15
15
  </div>
16
16
  );
@@ -100,40 +100,50 @@ const HistoricalChat: FC<ChatProps> = ({
100
100
  useEffect(() => {
101
101
  if (!messagesList) return;
102
102
  let groupedMessages: GroupedMessage[] = [];
103
- messagesList.forEach((message) => {
103
+ messagesList.forEach((message, i) => {
104
+ const currentMessage = message;
105
+ const content = currentMessage.content?.trim() ?? "";
106
+
107
+ if (content.startsWith("#service,") || content.startsWith("#common_service,")) {
108
+ const allPreviousButtons = messagesList
109
+ .slice(0, i)
110
+ .flatMap((msg) => (msg.buttons ? JSON.parse(msg.buttons) : []));
111
+ currentMessage.content = allPreviousButtons.find((b: any) => b.payload.includes(content))?.title ?? content;
112
+ }
113
+
104
114
  const lastGroup = groupedMessages[groupedMessages.length - 1];
105
- if (lastGroup?.type === message.authorRole) {
115
+ if (lastGroup?.type === currentMessage.authorRole) {
106
116
  if (
107
- !message.event ||
108
- message.event.toLowerCase() === CHAT_EVENTS.GREETING ||
109
- message.event.toLowerCase() === CHAT_EVENTS.WAITING_VALIDATION ||
110
- message.event.toLowerCase() === CHAT_EVENTS.APPROVED_VALIDATION
117
+ !currentMessage.event ||
118
+ currentMessage.event.toLowerCase() === CHAT_EVENTS.GREETING ||
119
+ currentMessage.event.toLowerCase() === CHAT_EVENTS.WAITING_VALIDATION ||
120
+ currentMessage.event.toLowerCase() === CHAT_EVENTS.APPROVED_VALIDATION
111
121
  ) {
112
122
  lastGroup.messages.push({
113
- ...message,
123
+ ...currentMessage,
114
124
  content:
115
- message.event === CHAT_EVENTS.WAITING_VALIDATION
125
+ currentMessage.event === CHAT_EVENTS.WAITING_VALIDATION
116
126
  ? t("chat.waiting_validation").toString()
117
- : message.content,
127
+ : currentMessage.content,
118
128
  });
119
129
  } else {
120
130
  groupedMessages.push({
121
131
  name: "",
122
132
  type: "event",
123
133
  title: "",
124
- messages: [{ ...message }],
134
+ messages: [{ ...currentMessage }],
125
135
  });
126
136
  }
127
137
  } else {
128
138
  const isBackOfficeUser =
129
- message.authorRole === "backoffice-user"
130
- ? `${message.authorFirstName} ${message.authorLastName}`
139
+ currentMessage.authorRole === "backoffice-user"
140
+ ? `${currentMessage.authorFirstName} ${currentMessage.authorLastName}`
131
141
  : BACKOFFICE_NAME.DEFAULT;
132
142
  groupedMessages.push({
133
- name: message.authorRole === "end-user" ? endUserFullName : isBackOfficeUser,
134
- type: message.authorRole,
135
- title: message.csaTitle ?? "",
136
- messages: [{ ...message }],
143
+ name: currentMessage.authorRole === "end-user" ? endUserFullName : isBackOfficeUser,
144
+ type: currentMessage.authorRole,
145
+ title: currentMessage.csaTitle ?? "",
146
+ messages: [{ ...currentMessage }],
137
147
  });
138
148
  }
139
149
  });