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 8 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
15 changes: 6 additions & 9 deletions src/containers/Template/Form/HSM/HSM.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,13 @@ 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 }));
};

Expand All @@ -100,12 +104,6 @@ export const HSM = () => {
setSampleMessages((val) => ({ ...val, type, media: mediaBody }));
};

const addButtonsToSampleMessage = (buttonTemplate: string) => {
const message: any = { ...sampleMessages };
message.body = buttonTemplate;
setSampleMessages(message);
};

const isCopyState = location.state === 'copy';
let isEditing = false;
if (params.id && !isCopyState) {
Expand Down Expand Up @@ -199,7 +197,6 @@ export const HSM = () => {
getUrlAttachmentAndType={getAttachmentUrl}
setCategory={setCategory}
category={category}
onExampleChange={addButtonsToSampleMessage}
allowTemplateCategoryChange={allowTemplateCategoryChange}
setAllowTemplateCategoryChange={setAllowTemplateCategoryChange}
languageVariant={languageVariant}
Expand Down
21 changes: 11 additions & 10 deletions src/containers/Template/Form/Template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ export interface TemplateProps {
getUrlAttachmentAndType?: any;
setCategory?: any;
category?: any;
onExampleChange?: any;
languageStyle?: string;
getSimulatorMessage?: any;
allowTemplateCategoryChange?: boolean;
Expand Down Expand Up @@ -183,7 +182,6 @@ const Template = ({
getUrlAttachmentAndType,
setCategory,
category,
onExampleChange = () => {},
allowTemplateCategoryChange,
setAllowTemplateCategoryChange,
languageStyle = 'dropdown',
Expand Down Expand Up @@ -327,7 +325,7 @@ const Template = ({
}
variables = getExampleValue(exampleValue);
setVariables(variables);
onExampleChange(getExampleFromBody(bodyValue, variables));
getSimulatorMessage(getExampleFromBody(bodyValue, variables));
}

if (shortcodeValue && setNewShortcode) {
Expand Down Expand Up @@ -359,6 +357,7 @@ const Template = ({
}
if (MessageMediaValue) {
setAttachmentURL(MessageMediaValue.sourceUrl);
getUrlAttachmentAndType(typeValue || 'TEXT', { url: MessageMediaValue.sourceUrl });
} else {
setAttachmentURL('');
}
Expand Down Expand Up @@ -520,8 +519,10 @@ const Template = ({
}, [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 @@ -539,10 +540,10 @@ const Template = ({
}, [templateType]);

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

// Converting buttons to template and vice-versa to show realtime update on simulator
useEffect(() => {
Expand All @@ -555,7 +556,7 @@ const Template = ({

const sampleText: any = parsedText && message + parsedText;
if (sampleText) {
onExampleChange(sampleText);
getSimulatorMessage(sampleText);
}
}
}, [templateButtons]);
Expand Down
Loading