Skip to content

Commit

Permalink
added fallback images
Browse files Browse the repository at this point in the history
  • Loading branch information
akanshaaa19 committed Sep 3, 2024
1 parent d7460c6 commit 4dbd788
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
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 @@ -35,7 +35,7 @@ export const ChatMessageType = ({
if (type !== 'LOCATION' && !media) {
return (
<div className={`${isContextMessage && styles.ContentMessageMaxWidth}`}>
<MessagesWithLinks message={body} showPreview={!isContextMessage} isSender={isSender} />
<MessagesWithLinks isSender={isSender} message={media.caption || media.text || body} />{' '}
</div>
);
}
Expand Down
8 changes: 6 additions & 2 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 Down
25 changes: 17 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 @@ const Template = ({
setBody(bodyValue || '');
setEditorState(bodyValue || '');
}
variables = getExampleValue(exampleValue);
setVariables(variables);

if (exampleValue) {
if (hasButtons) {
Expand All @@ -324,10 +326,12 @@ const Template = ({
);
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 @@ const Template = ({
}
if (MessageMediaValue) {
setAttachmentURL(MessageMediaValue.sourceUrl);
getUrlAttachmentAndType(typeValue || 'TEXT', { url: MessageMediaValue.sourceUrl });
} else {
setAttachmentURL('');
}
Expand Down Expand Up @@ -520,8 +525,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 @@ -540,13 +547,15 @@ const Template = ({

// 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

0 comments on commit 4dbd788

Please sign in to comment.