-
Notifications
You must be signed in to change notification settings - Fork 44
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
Added send location feature #2635
Changes from all commits
0547476
6847868
9f43928
26cd674
549093d
5c0db11
60115a3
92327ca
ac5ba62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,6 +152,9 @@ export const GUPSHUP_QUICK_REPLY = | |
export const CALL_TO_ACTION = 'CALL_TO_ACTION'; | ||
export const LIST = 'LIST'; | ||
export const QUICK_REPLY = 'QUICK_REPLY'; | ||
export const LOCATION_REQUEST = 'LOCATION_REQUEST_MESSAGE'; | ||
export const TERMS_OF_USE_LINK = 'https://tides.coloredcow.com/terms-of-use'; | ||
export const COMPACT_MESSAGE_LENGTH = 35; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Defining the |
||
|
||
// Gupshup sample media | ||
export const SAMPLE_MEDIA_FOR_SIMULATOR = [ | ||
|
@@ -209,10 +212,3 @@ export const yupPasswordValidation = (t: any) => | |
) | ||
.min(10, t('Password must be at least 10 characters long.')) | ||
.required(t('Input required')); | ||
|
||
export const INTERACTIVE_QUICK_REPLY = 'QUICK_REPLY'; | ||
export const INTERACTIVE_LIST = 'LIST'; | ||
|
||
export const TERMS_OF_USE_LINK = 'https://tides.coloredcow.com/terms-of-use'; | ||
|
||
export const COMPACT_MESSAGE_LENGTH = 35; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,6 +134,8 @@ | |
default: | ||
break; | ||
} | ||
} else if (interactiveJSON.type === 'location_request_message') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The usage of string literal 'location_request_message' should be replaced by the |
||
messageBody = interactiveJSON.body.text; | ||
} | ||
|
||
return messageBody; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,9 +24,10 @@ | |
import { | ||
TIME_FORMAT, | ||
SAMPLE_MEDIA_FOR_SIMULATOR, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
INTERACTIVE_LIST, | ||
INTERACTIVE_QUICK_REPLY, | ||
LIST, | ||
QUICK_REPLY, | ||
DEFAULT_MESSAGE_LIMIT, | ||
LOCATION_REQUEST, | ||
} from 'common/constants'; | ||
import { GUPSHUP_CALLBACK_URL } from 'config'; | ||
import { ChatMessageType } from 'containers/Chat/ChatMessages/ChatMessage/ChatMessageType/ChatMessageType'; | ||
|
@@ -54,6 +55,7 @@ | |
} from 'graphql/subscriptions/Simulator'; | ||
import { updateSimulatorConversations } from 'services/SubscriptionService'; | ||
import styles from './Simulator.module.css'; | ||
import { LocationRequestTemplate } from 'containers/Chat/ChatMessages/ChatMessage/LocationRequestTemplate/LocationRequestTemplate'; | ||
|
||
export interface SimulatorProps { | ||
showSimulator: boolean; | ||
|
@@ -296,7 +298,7 @@ | |
if (content) { | ||
isInteractiveContentPresent = !!Object.entries(content).length; | ||
|
||
if (isInteractiveContentPresent && messageType === INTERACTIVE_LIST) { | ||
if (isInteractiveContentPresent && messageType === LIST) { | ||
template = ( | ||
<> | ||
<ListReplyTemplate | ||
|
@@ -311,7 +313,7 @@ | |
); | ||
} | ||
|
||
if (isInteractiveContentPresent && messageType === INTERACTIVE_QUICK_REPLY) { | ||
if (isInteractiveContentPresent && messageType === QUICK_REPLY) { | ||
template = ( | ||
<QuickReplyTemplate | ||
{...content} | ||
|
@@ -323,6 +325,15 @@ | |
/> | ||
); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
if (isInteractiveContentPresent && messageType === LOCATION_REQUEST) { | ||
template = ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The inline creation of an object for the |
||
<LocationRequestTemplate | ||
content={content} | ||
isSimulator | ||
onSendLocationClick={(payload: any) => sendMessage(sender, payload)} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
return ( | ||
|
@@ -386,7 +397,7 @@ | |
const { templateType, interactiveContent } = interactiveMessage; | ||
const previewMessage = renderMessage(interactiveMessage, 'received', 0, true); | ||
setSimulatedMessage(previewMessage); | ||
if (templateType === INTERACTIVE_LIST) { | ||
if (templateType === LIST) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
const { items } = JSON.parse(interactiveContent); | ||
setSelectedListTemplate(items); | ||
} else { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,9 +9,10 @@ | |
import { | ||
DATE_FORMAT, | ||
TIME_FORMAT, | ||
INTERACTIVE_LIST, | ||
INTERACTIVE_QUICK_REPLY, | ||
LIST, | ||
QUICK_REPLY, | ||
VALID_URL_REGEX, | ||
LOCATION_REQUEST, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The imported constants |
||
} from 'common/constants'; | ||
import { WhatsAppToJsx, WhatsAppTemplateButton } from 'common/RichEditor'; | ||
import { Tooltip } from 'components/UI/Tooltip/Tooltip'; | ||
|
@@ -23,6 +24,7 @@ | |
import { QuickReplyTemplate } from '../QuickReplyTemplate/QuickReplyTemplate'; | ||
import styles from './ChatMessage.module.css'; | ||
import { setNotification } from 'common/notification'; | ||
import { LocationRequestTemplate } from './LocationRequestTemplate/LocationRequestTemplate'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The import statement for |
||
|
||
export interface ChatMessageProps { | ||
id: number; | ||
|
@@ -260,14 +262,18 @@ | |
} | ||
|
||
let template = null; | ||
if (type === INTERACTIVE_LIST) { | ||
if (type === LIST) { | ||
template = <ListReplyTemplate {...content} disabled component={ChatTemplate} />; | ||
} | ||
|
||
if (type === INTERACTIVE_QUICK_REPLY) { | ||
if (type === QUICK_REPLY) { | ||
template = <QuickReplyTemplate {...content} disabled />; | ||
} | ||
|
||
if (type === LOCATION_REQUEST) { | ||
template = <LocationRequestTemplate content={content} disabled />; | ||
} | ||
|
||
let displayLabel; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of |
||
if (flowLabel) { | ||
const labels = flowLabel.split(','); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
.MessageContent { | ||
max-width: 100%; | ||
border-radius: 12px 12px 0px 0px; | ||
font-family: 'Heebo', sans-serif, emoji; | ||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4); | ||
clear: both; | ||
max-width: 404px; | ||
min-width: 85px; | ||
padding: 10px; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Verify that this CSS class |
||
background: white; | ||
border-bottom: 1px solid rgba(0, 0, 0, 0.1); | ||
} | ||
|
||
.SimulatorButton { | ||
width: 100%; | ||
text-transform: none !important; | ||
border-radius: 0px 0px 15px 15px !important; | ||
background: white !important; | ||
border: 1px solid rgba(0, 0, 0, 0.1) !important; | ||
border-top: none !important | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
.ChatButton { | ||
composes: SimulatorButton; | ||
padding: 5px 20px !important; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Button } from '@mui/material'; | ||
import LocationIconDark from 'assets/images/icons/Location/Dark.svg?react'; | ||
import styles from './LocationRequestTemplate.module.css'; | ||
import { ChatMessageType } from '../ChatMessageType/ChatMessageType'; | ||
|
||
export interface LocationRequestTemplateProps { | ||
content: any; | ||
disabled?: boolean; | ||
|
||
isSimulator?: boolean; | ||
onSendLocationClick?: any; | ||
} | ||
|
||
const locationPayload = { | ||
type: 'location', | ||
name: 'location', | ||
id: 'LOCATION', | ||
payload: { | ||
latitude: '41.725556', | ||
longitude: '-49.946944', | ||
}, | ||
}; | ||
|
||
export const LocationRequestTemplate = ({ | ||
content, | ||
disabled = false, | ||
isSimulator = false, | ||
|
||
onSendLocationClick = () => {}, | ||
}: LocationRequestTemplateProps) => { | ||
const body = content.body.text; | ||
return ( | ||
<div> | ||
<div className={styles.MessageContent}> | ||
<ChatMessageType type="TEXT" body={body} isSimulatedMessage={isSimulator} /> | ||
</div> | ||
<Button | ||
variant="text" | ||
disabled={disabled} | ||
startIcon={<LocationIconDark />} | ||
onClick={() => onSendLocationClick({ payload: locationPayload })} | ||
Check warning on line 41 in src/containers/Chat/ChatMessages/ChatMessage/LocationRequestTemplate/LocationRequestTemplate.tsx Codecov / codecov/patchsrc/containers/Chat/ChatMessages/ChatMessage/LocationRequestTemplate/LocationRequestTemplate.tsx#L41
|
||
className={isSimulator ? styles.SimulatorButton : styles.ChatButton} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Passing inline functions, such as |
||
> | ||
Send Location | ||
</Button> | ||
</div> | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's usually better to prefix constants with a common namespace to avoid naming collisions especially with generic terms like
LOCATION_REQUEST
. Consider using a more explicit constant name likeMESSAGE_TYPE_LOCATION_REQUEST
.