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

WA Polls: Create and manage polls #3185

Merged
merged 59 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
3bf3219
create and manage polls
akanshaaa19 Jan 10, 2025
c1aaa73
connected apis
akanshaaa19 Jan 13, 2025
5b41396
added poll message
akanshaaa19 Jan 14, 2025
4e78ba7
fixed copies
akanshaaa19 Jan 14, 2025
e9b2fb6
added simulator support
akanshaaa19 Jan 15, 2025
453a490
fixed validation
akanshaaa19 Jan 15, 2025
b24ae5f
fixed voting logic and colors
akanshaaa19 Jan 15, 2025
cae60a0
merge changes
akanshaaa19 Jan 15, 2025
b9d1da7
merge changes
akanshaaa19 Jan 15, 2025
3270d0d
added ids
akanshaaa19 Jan 15, 2025
bc13398
added view action
akanshaaa19 Jan 15, 2025
5bf2a6a
deepscan fixes
akanshaaa19 Jan 15, 2025
7b901e0
deepscan fixes
akanshaaa19 Jan 15, 2025
65e0a3a
merge changes
akanshaaa19 Jan 15, 2025
95c5d8e
fixed content
akanshaaa19 Jan 15, 2025
476f110
fixed content
akanshaaa19 Jan 15, 2025
6da10a1
fixed content
akanshaaa19 Jan 15, 2025
46eb607
fixed content
akanshaaa19 Jan 15, 2025
f52d6b1
reorganised imports
akanshaaa19 Jan 15, 2025
a4b7eeb
deepscan fixes
akanshaaa19 Jan 17, 2025
d3456b1
merge changes
akanshaaa19 Jan 17, 2025
71d2aa7
fixed delete functionality
akanshaaa19 Jan 17, 2025
9e007c0
merge changes
akanshaaa19 Jan 17, 2025
759e27b
added test cases
akanshaaa19 Jan 20, 2025
eede142
changed form name
akanshaaa19 Jan 20, 2025
5393f24
removed download icon
akanshaaa19 Jan 20, 2025
09510d5
removed commented out code
akanshaaa19 Jan 20, 2025
316de00
Merge branch 'master' into feat/wa_polls
akanshaaa19 Jan 20, 2025
825338c
minor fixes
akanshaaa19 Jan 20, 2025
6eaf951
Merge branch 'feat/wa_polls' of github.com:glific/glific-frontend int…
akanshaaa19 Jan 20, 2025
b451ede
merge changes
akanshaaa19 Jan 20, 2025
e344750
Added test cases
akanshaaa19 Jan 20, 2025
1b71dd9
Merge branch 'master' of github.com:glific/glific-frontend into feat/…
akanshaaa19 Feb 12, 2025
b9d1df3
Merge branch 'feat/wa_polls' of github.com:glific/glific-frontend int…
akanshaaa19 Feb 12, 2025
03b4f93
resolve merge conflict
kurund Feb 16, 2025
efda088
remove menu option
kurund Feb 16, 2025
b7bf501
Merge remote-tracking branch 'origin/feat/wa_polls' into feat/poll_me…
kurund Feb 16, 2025
eb3461f
update the title and error fixes
kurund Feb 16, 2025
3f39fe1
Merge branch 'feat/poll_message' of github.com:glific/glific-frontend…
akanshaaa19 Feb 17, 2025
c878305
Merge branch 'feat/wa_polls' of github.com:glific/glific-frontend int…
akanshaaa19 Feb 17, 2025
4e245a0
resolved comments
akanshaaa19 Feb 17, 2025
9647e91
deepscan fixes
akanshaaa19 Feb 17, 2025
e073c71
resolved comments
akanshaaa19 Feb 17, 2025
0f21b12
Merge branch 'feat/wa_polls' of github.com:glific/glific-frontend int…
akanshaaa19 Feb 17, 2025
f738d15
merge changes
akanshaaa19 Feb 17, 2025
5687a6c
added documentation links
akanshaaa19 Feb 17, 2025
95b4a87
added character limitation
akanshaaa19 Feb 17, 2025
6c944d6
refactored the code
akanshaaa19 Feb 17, 2025
0b1f021
fixed view poll
akanshaaa19 Feb 17, 2025
009407f
deepscan fixes
akanshaaa19 Feb 17, 2025
99b0b59
Merge pull request #3223 from glific/wa_polls/char-limit
kurund Feb 17, 2025
339621b
Merge branch 'feat/wa_polls' of github.com:glific/glific-frontend int…
akanshaaa19 Feb 18, 2025
978c28f
Merge branch 'feat/wa_polls' of github.com:glific/glific-frontend int…
akanshaaa19 Feb 18, 2025
b7dfadf
Merge pull request #3186 from glific/feat/poll_message
kurund Feb 18, 2025
36f8efb
Merge branch 'feat/wa_polls' of github.com:glific/glific-frontend int…
akanshaaa19 Feb 19, 2025
32e838a
Merge branch 'master' of github.com:glific/glific-frontend into feat/…
akanshaaa19 Feb 19, 2025
798f428
fixed test cases
akanshaaa19 Feb 19, 2025
7997c1d
minor fixes
akanshaaa19 Feb 19, 2025
c247dd1
added test cases
akanshaaa19 Feb 19, 2025
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
6 changes: 6 additions & 0 deletions src/assets/images/Polls.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/images/icons/Poll.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions src/assets/images/icons/SideDrawer/WaPolls.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const SvgComponent = ({ color }: { color: string }) => (
<svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">

Check warning on line 2 in src/assets/images/icons/SideDrawer/WaPolls.tsx

View check run for this annotation

Codecov / codecov/patch

src/assets/images/icons/SideDrawer/WaPolls.tsx#L2

Added line #L2 was not covered by tests
<path
d="M13 7C13.2833 7 13.5208 6.90417 13.7125 6.7125C13.9042 6.52083 14 6.28333 14 6C14 5.71667 13.9042 5.47917 13.7125 5.2875C13.5208 5.09583 13.2833 5 13 5H10C9.71667 5 9.47917 5.09583 9.2875 5.2875C9.09583 5.47917 9 5.71667 9 6C9 6.28333 9.09583 6.52083 9.2875 6.7125C9.47917 6.90417 9.71667 7 10 7H13ZM13 13C13.2833 13 13.5208 12.9042 13.7125 12.7125C13.9042 12.5208 14 12.2833 14 12C14 11.7167 13.9042 11.4792 13.7125 11.2875C13.5208 11.0958 13.2833 11 13 11H10C9.71667 11 9.47917 11.0958 9.2875 11.2875C9.09583 11.4792 9 11.7167 9 12C9 12.2833 9.09583 12.5208 9.2875 12.7125C9.47917 12.9042 9.71667 13 10 13H13ZM6 8C6.55 8 7.02083 7.80417 7.4125 7.4125C7.80417 7.02083 8 6.55 8 6C8 5.45 7.80417 4.97917 7.4125 4.5875C7.02083 4.19583 6.55 4 6 4C5.45 4 4.97917 4.19583 4.5875 4.5875C4.19583 4.97917 4 5.45 4 6C4 6.55 4.19583 7.02083 4.5875 7.4125C4.97917 7.80417 5.45 8 6 8ZM6 14C6.55 14 7.02083 13.8042 7.4125 13.4125C7.80417 13.0208 8 12.55 8 12C8 11.45 7.80417 10.9792 7.4125 10.5875C7.02083 10.1958 6.55 10 6 10C5.45 10 4.97917 10.1958 4.5875 10.5875C4.19583 10.9792 4 11.45 4 12C4 12.55 4.19583 13.0208 4.5875 13.4125C4.97917 13.8042 5.45 14 6 14ZM2 18C1.45 18 0.979167 17.8042 0.5875 17.4125C0.195833 17.0208 0 16.55 0 16V2C0 1.45 0.195833 0.979167 0.5875 0.5875C0.979167 0.195833 1.45 0 2 0H16C16.55 0 17.0208 0.195833 17.4125 0.5875C17.8042 0.979167 18 1.45 18 2V16C18 16.55 17.8042 17.0208 17.4125 17.4125C17.0208 17.8042 16.55 18 16 18H2ZM2 16H16V2H2V16Z"
fill={color}
/>
</svg>
);
export default SvgComponent;
5 changes: 5 additions & 0 deletions src/common/HelpData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,8 @@ export const templateStatusInfo: HelpDataProps = {
),
link: 'https://docs.gupshup.io/docs/message-template-approvals-statuses',
};

export const pollsInfo: HelpDataProps = {
heading: 'An overview of all the polls created to date',
link: 'https://glific.github.io/docs/docs/WhatsApp%20Groups%20Automation/Sending%20Polls%20To%20WhatsApp%20Groups',
};
2 changes: 2 additions & 0 deletions src/components/UI/ListIcon/ListIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import WaChatIcon from 'assets/images/icons/SideDrawer/WaGroupChat';
import WaCollectionIcon from 'assets/images/icons/SideDrawer/WaGroupCollection';
import WaGroupIcon from 'assets/images/icons/SideDrawer/WhatsAppGroupIcon';
import Assistant from 'assets/images/icons/SideDrawer/Assistant';
import WaPolls from 'assets/images/icons/SideDrawer/WaPolls';
import styles from './ListIcon.module.css';
import FiberNewIcon from '@mui/icons-material/FiberNew';
import { Badge } from '@mui/material';
Expand Down Expand Up @@ -74,6 +75,7 @@ export const ListIcon = ({ icon = '', selected = false, count }: ListIconProps)
waGroup: WaGroupIcon,
assistant: Assistant,
discord: DiscordIcon,
waPolls: WaPolls,
};

const iconImage = stringsToIcons[icon] && (
Expand Down
1 change: 1 addition & 0 deletions src/components/simulator/Simulator.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
background: white;
width: 200px;
margin-top: 4px;
overflow-x: hidden;
}

.StickerReceivedMessage {
Expand Down
56 changes: 38 additions & 18 deletions src/components/simulator/Simulator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import { LocationRequestTemplate } from 'containers/Chat/ChatMessages/ChatMessage/LocationRequestTemplate/LocationRequestTemplate';
import { BackdropLoader } from 'containers/Flow/FlowTranslation';
import { SIMULATOR_RELEASE_SUBSCRIPTION } from 'graphql/subscriptions/PeriodicInfo';
import { PollMessage } from 'containers/Chat/ChatMessages/ChatMessage/PollMessage/PollMessage';

export interface SimulatorProps {
setShowSimulator?: any;
Expand All @@ -63,6 +64,7 @@
interactiveMessage?: any;
showHeader?: boolean;
hasResetButton?: boolean;
pollContent?: any;
}

interface Sender {
Expand Down Expand Up @@ -124,6 +126,7 @@
interactiveMessage,
showHeader = true,
hasResetButton = false,
pollContent,
}: SimulatorProps) => {
const [inputMessage, setInputMessage] = useState('');
const [simulatedMessages, setSimulatedMessage] = useState<any>();
Expand Down Expand Up @@ -268,7 +271,13 @@
});
};

const renderMessage = (messageObject: any, direction: string, index: number, isInteractive: boolean = false) => {
const renderMessage = (
messageObject: any,
direction: string,
index: number,
isInteractive: boolean,
isPollContent: boolean = false
) => {
const { insertedAt, type, media, location, interactiveContent, bspMessageId, templateType } = messageObject;

const messageType = isInteractive ? templateType : type;
Expand Down Expand Up @@ -320,26 +329,31 @@
}
}

let messageBody: any = (
<>
<ChatMessageType
type={messageType}
media={media}
body={body}
location={location}
isSimulatedMessage={isSimulatedMessage}
/>
<TimeComponent direction={direction} insertedAt={insertedAt} />
</>
);
if (isInteractiveContentPresent && direction !== 'send') {
messageBody = template;
} else if (isPollContent) {
messageBody = <PollMessage pollContent={pollContent} isSimulator />;
}

return (
<div key={index}>
<div
className={getStyleForDirection(direction, isInteractiveContentPresent, messageType)}
data-testid="simulatorMessage"
>
{isInteractiveContentPresent && direction !== 'send' ? (
template
) : (
<>
<ChatMessageType
type={messageType}
media={media}
body={body}
location={location}
isSimulatedMessage={isSimulatedMessage}
/>
<TimeComponent direction={direction} insertedAt={insertedAt} />
</>
)}
{messageBody}
</div>
<div className={styles.TemplateButtons}>
<TemplateButtons
Expand All @@ -356,17 +370,17 @@
const chatMessage = messages
.map((simulatorMessage: any, index: number) => {
if (simulatorMessage.receiver.id === simulatorId) {
return renderMessage(simulatorMessage, 'received', index);
return renderMessage(simulatorMessage, 'received', index, false);

Check warning on line 373 in src/components/simulator/Simulator.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/simulator/Simulator.tsx#L373

Added line #L373 was not covered by tests
}
return renderMessage(simulatorMessage, 'send', index);
return renderMessage(simulatorMessage, 'send', index, false);
})
.reverse();
setSimulatedMessage(chatMessage);
};

const getPreviewMessage = () => {
if (message && message.type) {
const previewMessage = renderMessage(message, 'received', 0);
const previewMessage = renderMessage(message, 'received', 0, false);
if (['STICKER', 'AUDIO'].includes(message.type)) {
setSimulatedMessage(previewMessage);
} else if (message.body || message.media?.caption) {
Expand All @@ -380,6 +394,7 @@
if (interactiveMessage) {
const { templateType, interactiveContent } = interactiveMessage;
const previewMessage = renderMessage(interactiveMessage, 'received', 0, true);

setSimulatedMessage(previewMessage);
if (templateType === LIST) {
const { items } = JSON.parse(interactiveContent);
Expand All @@ -388,6 +403,11 @@
setIsDrawerOpen(false);
}
}

if (pollContent) {
const previewMessage = renderMessage(pollContent, 'received', 0, false, true);
setSimulatedMessage(previewMessage);
}
};

useEffect(() => {
Expand Down
7 changes: 7 additions & 0 deletions src/config/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ const menus = (): Menu[] => [
type: 'sideDrawer',
roles: allRoles,
},
{
title: 'Group Polls',
path: '/group/polls',
icon: 'waPolls',
type: 'sideDrawer',
roles: allRoles,
},
],
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import AudioIconDark from 'assets/images/icons/Audio/Dark.svg?react';
import DocumentIconDark from 'assets/images/icons/Document/Dark.svg?react';
import StickerIconDark from 'assets/images/icons/Sticker/Dark.svg?react';
import LocationIconDark from 'assets/images/icons/Location/Dark.svg?react';
import PollIcon from 'assets/images/icons/Poll.svg?react';

import styles from './MessageType.module.css';

Expand All @@ -26,6 +27,7 @@ const lightIcons: any = {
DOCUMENT: <DocumentIcon />,
STICKER: <StickerIcon />,
LOCATION: <LocationIcon />,
POLL: <PollIcon />,
};

const darkIcons: any = {
Expand All @@ -51,6 +53,7 @@ export const MessageType = ({ type, body = '', color = 'light' }: MessageTypePro
QUICK_REPLY: 'Quick Reply',
LIST: 'List',
LOCATION_REQUEST_MESSAGE: 'Location Request',
POLL: body,
};

const option = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
.Inline {
display: flex;
}

.SendBy {
display: flex;
align-items: flex-end;
Expand Down Expand Up @@ -298,3 +299,7 @@
padding-bottom: 8px;
font-weight: bold;
}

.NoIcon {
margin: 0 1rem;
}
Loading
Loading