-
Notifications
You must be signed in to change notification settings - Fork 48
Whatsapp Forms #3624
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
Open
akanshaaa19
wants to merge
12
commits into
master
Choose a base branch
from
feat/whatsapp-forms
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Whatsapp Forms #3624
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
eaaa41e
Add WhatsApp Forms feature with create and update operations and UI c…
akanshaaa19 41aa284
Merge branch 'master' into feat/whatsapp-forms
akanshaaa19 ab532af
Merge branch 'master' into feat/whatsapp-forms
priyanshu6238 777610b
Add WhatsApp form response handling in ChatMessage component
akanshaaa19 6c7c220
Merge branch 'feat/whatsapp-forms' of github.com:glific/glific-fronte…
akanshaaa19 7aa46fe
add whatsappFormResponse field to various mocks
akanshaaa19 32e66c4
WhatsApp Forms: Add UI for listing WhatsApp flows (#3615)
priyanshu6238 4b91823
Whatsapp forms cleanup (#3629)
akanshaaa19 c2a8b06
Add new button to HSM for whatsapp forms (#3626)
akanshaaa19 bbd65d2
Merge branch 'master' into feat/whatsapp-forms
shijithkjayan 9a5e169
Added fields to subscription query
akanshaaa19 0edf13d
Merge branch 'master' into feat/whatsapp-forms
akanshaaa19 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| const WhatsAppForm = ({ color }: { color: string }) => { | ||
| return ( | ||
| <svg | ||
| className="w-6 h-6 " | ||
| aria-hidden="true" | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| width="24" | ||
| height="24" | ||
| fill="none" | ||
| viewBox="0 0 24 24" | ||
| color={color} | ||
| > | ||
| <path | ||
| stroke={'currentColor'} | ||
| strokeLinecap="round" | ||
| strokeLinejoin="round" | ||
| strokeWidth="2" | ||
| d="M15 4h3a1 1 0 0 1 1 1v15a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h3m0 3h6m-6 5h6m-6 4h6M10 3v4h4V3h-4Z" | ||
| /> | ||
| </svg> | ||
| ); | ||
| }; | ||
| export default WhatsAppForm; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...ainers/Chat/ChatMessages/ChatMessage/WhatsappFormResponse/WhatsAppFormResponse.module.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| .FormResponseContainer { | ||
| display: flex; | ||
| align-items: center; | ||
| padding: 12px 16px; | ||
| border-radius: 12px; | ||
| cursor: pointer; | ||
| max-width: 280px; | ||
| background-color: #0000004c; | ||
| } | ||
|
|
||
| .Content { | ||
| display: flex; | ||
| flex-direction: column; | ||
| color: #fff !important; | ||
| } | ||
|
|
||
| .Title { | ||
| font-weight: 500; | ||
| color: #fff; | ||
| margin-bottom: 2px; | ||
| } | ||
|
|
||
| .Subtitle { | ||
| color: #afafaf; | ||
| font-size: 12px; | ||
| } |
72 changes: 72 additions & 0 deletions
72
src/containers/Chat/ChatMessages/ChatMessage/WhatsappFormResponse/WhatsAppFormResponse.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import { Typography } from '@mui/material'; | ||
|
|
||
| import { DialogBox } from 'components/UI/DialogBox/DialogBox'; | ||
| import { useEffect, useState } from 'react'; | ||
| import styles from './WhatsAppFormResponse.module.css'; | ||
|
|
||
| interface WhatsAppFormResponseProps { | ||
| rawResponse: string; | ||
| } | ||
akanshaaa19 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export const WhatsAppFormResponse = ({ rawResponse }: WhatsAppFormResponseProps) => { | ||
| const [open, setOpen] = useState<boolean>(false); | ||
| const [parsedResponse, setParsedResponse] = useState<any>({}); | ||
akanshaaa19 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const handleOpen = () => setOpen(true); | ||
| const handleClose = () => setOpen(false); | ||
|
|
||
| useEffect(() => { | ||
| console.log(rawResponse); | ||
akanshaaa19 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (rawResponse) { | ||
| try { | ||
| const response = JSON.parse(rawResponse); | ||
| setParsedResponse(response); | ||
| } catch (error) { | ||
| console.error('Error parsing WhatsApp form response:', error); | ||
| setParsedResponse({ error: 'Invalid response format' }); | ||
| } | ||
| } | ||
| }, [rawResponse]); | ||
|
|
||
| return ( | ||
| <> | ||
| <div className={styles.FormResponseContainer}> | ||
| <div onClick={handleOpen} className={styles.Content}> | ||
| <Typography variant="body2" className={styles.Title}> | ||
| View Response | ||
| </Typography> | ||
| <Typography variant="caption" className={styles.Subtitle}> | ||
| Response recieved | ||
akanshaaa19 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </Typography> | ||
| </div> | ||
| </div> | ||
| {open && ( | ||
| <DialogBox | ||
| open={open} | ||
| title="WhatsApp Form Response" | ||
| handleCancel={handleClose} | ||
| skipCancel | ||
| handleOk={handleClose} | ||
| buttonOk="Close" | ||
| > | ||
| {Object.keys(parsedResponse).length > 0 ? ( | ||
| <> | ||
| {Object.entries(parsedResponse).map(([key, value]) => ( | ||
| <div key={key} style={{ marginBottom: '8px' }}> | ||
| <Typography variant="subtitle2" style={{ fontWeight: 'bold' }}> | ||
| {key}: | ||
| </Typography> | ||
| <Typography variant="body2"> | ||
| {typeof value === 'object' ? JSON.stringify(value, null, 2) : String(value)} | ||
| </Typography> | ||
| </div> | ||
| ))} | ||
| </> | ||
| ) : ( | ||
| <Typography variant="body2">No response data available.</Typography> | ||
| )} | ||
| </DialogBox> | ||
| )} | ||
| </> | ||
| ); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| .FlowBuilderInfo { | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: space-between; | ||
| padding: 1.5rem; | ||
| margin: 2rem; | ||
| margin-bottom: 0; | ||
| background: linear-gradient(135deg, #f0fdf4 0%, #ecfdf5 100%); | ||
| border: 1px solid #bbf7d0; | ||
| border-radius: 12px; | ||
| box-shadow: 0 1px 3px 0 rgba(34, 197, 94, 0.1); | ||
| transition: all 0.2s ease-in-out; | ||
| } | ||
|
|
||
| .FlowBuilderInfo:hover { | ||
| box-shadow: 0 4px 6px -1px rgba(34, 197, 94, 0.15); | ||
| transform: translateY(-1px); | ||
| } | ||
|
|
||
| .FlowBuilderInfo p { | ||
| margin-bottom: 0; | ||
| } | ||
|
|
||
| .InfoContent { | ||
| display: flex; | ||
| align-items: flex-start; | ||
| gap: 1rem; | ||
| flex: 1; | ||
| } | ||
|
|
||
| .IconWrapper { | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| width: 3rem; | ||
| height: 3rem; | ||
| background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%); | ||
| border-radius: 12px; | ||
| flex-shrink: 0; | ||
| } | ||
|
|
||
| .Icon { | ||
| color: white !important; | ||
| font-size: 24px !important; | ||
| } | ||
|
|
||
| .Title { | ||
| margin: 0 0 8px 0; | ||
| font-size: 1.125rem; | ||
| font-weight: 600; | ||
| color: #14532d; | ||
| line-height: 1.4; | ||
| } | ||
|
|
||
| .Description { | ||
| margin: 0; | ||
| font-size: 0.875rem; | ||
| color: #16a34a; | ||
| line-height: 1.5; | ||
| } | ||
|
|
||
| .FlowBuilderButton { | ||
| padding: 0.75rem 1.5rem !important; | ||
| font-weight: 500 !important; | ||
| border-radius: 8px !important; | ||
| white-space: nowrap; | ||
| min-width: 160px; | ||
| transition: all 0.2s ease-in-out !important; | ||
| color: #fff !important; | ||
| } | ||
|
|
||
| .FlowBuilderButton:hover { | ||
| transform: translateY(-1px); | ||
| box-shadow: 0 4px 12px rgba(34, 197, 94, 0.3) !important; | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import { MockedProvider } from '@apollo/client/testing'; | ||
| import { fireEvent, render, waitFor } from '@testing-library/react'; | ||
| import * as Notification from 'common/notification'; | ||
| import { formJson, WHATSAPP_FORM_MOCKS } from 'mocks/WhatsApp'; | ||
| import { MemoryRouter, Route, Routes } from 'react-router'; | ||
| import WhatsAppFormList from './WhatsAppFormList/WhatsAppFormList'; | ||
| import WhatsAppForms from './WhatsAppForms'; | ||
|
|
||
| describe('<WhatsAppForms />', () => { | ||
| const notificationSpy = vi.spyOn(Notification, 'setNotification'); | ||
| const wrapper = (initialEntry: string = '/whatsapp-forms/add') => ( | ||
| <MockedProvider mocks={WHATSAPP_FORM_MOCKS}> | ||
| <MemoryRouter initialEntries={[initialEntry]}> | ||
| <Routes> | ||
| <Route path="/whatsapp-forms/add" element={<WhatsAppForms />} /> | ||
| <Route path="/whatsapp-forms/:id/edit" element={<WhatsAppForms />} /> | ||
| <Route path="/whatsapp-forms" element={<WhatsAppFormList />} /> | ||
| </Routes> | ||
| </MemoryRouter> | ||
| </MockedProvider> | ||
| ); | ||
|
|
||
| test('it should render the WhatsApp Form page initially', async () => { | ||
| const { getByText } = render(wrapper()); | ||
| expect(getByText('Loading...')).toBeInTheDocument(); | ||
|
|
||
| await waitFor(() => { | ||
| expect(getByText('Create WhatsApp Form')).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| test('it should create WhatsApp Form page with form fields', async () => { | ||
| const { getByTestId, getByText, getAllByRole } = render(wrapper()); | ||
| expect(getByText('Loading...')).toBeInTheDocument(); | ||
|
|
||
| await waitFor(() => { | ||
| expect(getByText('Create WhatsApp Form')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| const inputs = getAllByRole('textbox'); | ||
|
|
||
| fireEvent.change(inputs[0], { target: { value: 'Test Form' } }); | ||
| fireEvent.change(inputs[1], { target: { value: 'This is a test form' } }); | ||
| fireEvent.change(inputs[2], { target: { value: 'sign_up' } }); | ||
|
|
||
| fireEvent.click(getByTestId('submitActionButton')); | ||
|
|
||
| await waitFor(() => { | ||
| expect(getByText('Must be valid JSON')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| const autocomplete = getByTestId('AutocompleteInput'); | ||
|
|
||
| autocomplete.focus(); | ||
| fireEvent.keyDown(autocomplete, { key: 'ArrowDown' }); | ||
|
|
||
| fireEvent.click(getByText('Other'), { key: 'Enter' }); | ||
| fireEvent.change(inputs[2], { target: { value: JSON.stringify(formJson) } }); | ||
|
|
||
| fireEvent.click(getByTestId('submitActionButton')); | ||
|
|
||
| await waitFor(() => { | ||
| expect(notificationSpy).toHaveBeenCalledWith('Whatsapp Form created successfully!'); | ||
| }); | ||
| }); | ||
|
|
||
| test('it should edit WhatsApp Form page with form fields', async () => { | ||
| const { getByTestId, getByText, getAllByRole } = render(wrapper('/whatsapp-forms/1/edit')); | ||
| expect(getByText('Loading...')).toBeInTheDocument(); | ||
|
|
||
| await waitFor(() => { | ||
| expect(getByText('Edit WhatsApp Form')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| const inputs = getAllByRole('textbox'); | ||
|
|
||
| fireEvent.change(inputs[0], { target: { value: 'Updated Form Name' } }); | ||
| fireEvent.change(inputs[1], { target: { value: 'This is an updated test form' } }); | ||
|
|
||
| fireEvent.click(getByTestId('submitActionButton')); | ||
|
|
||
| await waitFor(() => { | ||
| expect(notificationSpy).toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.