Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for hsm templates #3040

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/UI/ImgFallback/ImgFallback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const ImgFallback = ({ src, alt, ...rest }: ImgProps) => {
const imgRef: any = useRef<HTMLImageElement>();

useEffect(() => {
setImgSrc(src);
setImgSrc(src || FallbackImage);
}, [src]);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const ChatMessageType = ({
zIndex={1501} // greater than tooltips
/>
</div>
<MessagesWithLinks isSender={isSender} message={media.caption || media.text} />
<MessagesWithLinks isSender={isSender} message={media.caption || media.text || body} />
</div>
);

Expand Down
9 changes: 7 additions & 2 deletions src/containers/Template/Form/HSM/HSM.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,21 @@ export const HSM = () => {

const getSimulatorMessage = (messages: any) => {
const message = removeFirstLineBreak(messages);
const media: any = { ...sampleMessages.media };
const text = getTemplate(message);
media.caption = text;

const media = {
...sampleMessages.media,
caption: text,
};

setSampleMessages((val) => ({ ...val, body: text, media }));
};

const getAttachmentUrl = (type: any, media: any) => {
const mediaBody = { ...media };
const mediaObj: any = sampleMessages.media;
mediaBody.caption = mediaObj.caption;

setSampleMessages((val) => ({ ...val, type, media: mediaBody }));
};

Expand Down
29 changes: 21 additions & 8 deletions src/containers/Template/Form/Template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@
setBody(bodyValue || '');
setEditorState(bodyValue || '');
}
variables = getExampleValue(exampleValue);
setVariables(variables);

if (exampleValue) {
if (hasButtons) {
Expand All @@ -324,10 +326,12 @@
);
setTemplateButtons(buttonsVal);
setTemplateType(templateButtonType);
const parse = convertButtonsToTemplate(buttonsVal, templateButtonType);
const parsedText = parse.length ? `| ${parse.join(' | ')}` : null;
const { message }: any = getTemplateAndButton(getExampleFromBody(bodyValue, variables));
const sampleText: any = parsedText && message + parsedText;
onExampleChange(sampleText);
}
variables = getExampleValue(exampleValue);
setVariables(variables);
onExampleChange(getExampleFromBody(bodyValue, variables));
}

if (shortcodeValue && setNewShortcode) {
Expand Down Expand Up @@ -359,6 +363,7 @@
}
if (MessageMediaValue) {
setAttachmentURL(MessageMediaValue.sourceUrl);
getUrlAttachmentAndType(typeValue || 'TEXT', { url: MessageMediaValue.sourceUrl });
} else {
setAttachmentURL('');
}
Expand Down Expand Up @@ -520,8 +525,10 @@
}, [languages]);

useEffect(() => {
if ((type === '' || type) && attachmentURL) {
validateURL(attachmentURL);
if (type === '' || type) {
if (attachmentURL) {
validateURL(attachmentURL);
}
if (getUrlAttachmentAndType) {
getUrlAttachmentAndType(type.id || 'TEXT', { url: attachmentURL });
}
Expand All @@ -540,13 +547,15 @@

// Removing buttons when checkbox is checked or unchecked
useEffect(() => {
const { message }: any = getTemplateAndButton(getExampleFromBody(body, variables));
onExampleChange(message || '');
if (!isEditing) {
const { message }: any = getTemplateAndButton(getExampleFromBody(body, variables));
onExampleChange(message || '');
}
}, [isAddButtonChecked]);

// Converting buttons to template and vice-versa to show realtime update on simulator
useEffect(() => {
if (templateButtons.length > 0) {
if (templateButtons.length > 0 && !isEditing) {
const parse = convertButtonsToTemplate(templateButtons, templateType);

const parsedText = parse.length ? `| ${parse.join(' | ')}` : null;
Expand Down Expand Up @@ -853,6 +862,10 @@

let translationsCopy: any = {};
if (template) {
if (payloadCopy.isHsm) {
payloadCopy.category = category.label || category;
payloadCopy.example = getExampleFromBody(payloadCopy.body, variables);

Check warning on line 867 in src/containers/Template/Form/Template.tsx

View check run for this annotation

Codecov / codecov/patch

src/containers/Template/Form/Template.tsx#L867

Added line #L867 was not covered by tests
}
if (template.sessionTemplate.sessionTemplate.language.id === language?.id) {
payloadCopy.languageId = language?.id;
if (payloadCopy.type) {
Expand Down
Loading