diff --git a/src/components/UI/Heading/Heading.tsx b/src/components/UI/Heading/Heading.tsx index b3ae295625..b0c82a87bb 100644 --- a/src/components/UI/Heading/Heading.tsx +++ b/src/components/UI/Heading/Heading.tsx @@ -8,7 +8,6 @@ import AddIcon from 'assets/images/add.svg?react'; export interface HeadingProps { formTitle: string; helpData?: any; - showHeaderHelp?: boolean; backLink?: string; headerHelp?: string; button?: { @@ -20,7 +19,13 @@ export interface HeadingProps { }; } -export const Heading = ({ formTitle, helpData, showHeaderHelp = true, backLink, headerHelp, button }: HeadingProps) => { +export const Heading = ({ + formTitle, + helpData, + backLink, + headerHelp, + button, +}: HeadingProps) => { const navigate = useNavigate(); const addIcon = ; @@ -37,7 +42,7 @@ export const Heading = ({ formTitle, helpData, showHeaderHelp = true, backLink, {helpData ? : ''} -
{showHeaderHelp ? headerHelp || `Please enter below details.` : ''}
+ {headerHelp &&
{headerHelp}
} {button && button.show && ( diff --git a/src/containers/Consulting/Consulting.test.tsx b/src/containers/Consulting/Consulting.test.tsx index f42661fe2a..de02625cd2 100644 --- a/src/containers/Consulting/Consulting.test.tsx +++ b/src/containers/Consulting/Consulting.test.tsx @@ -101,7 +101,7 @@ test('it renders consulting hours in edit mode', async () => { }); }); -test('Click in cancel button', async () => { +test('Click on Go Back button', async () => { const { getByText } = render(consultingEditForm); expect(getByText('Loading...')).toBeInTheDocument(); diff --git a/src/containers/ContactManagement/ContactManagement.tsx b/src/containers/ContactManagement/ContactManagement.tsx index 26dbd47613..a99e20e6d4 100644 --- a/src/containers/ContactManagement/ContactManagement.tsx +++ b/src/containers/ContactManagement/ContactManagement.tsx @@ -45,7 +45,7 @@ export const ContactManagement = () => { return ( <> - +
diff --git a/src/containers/Flow/Flow.tsx b/src/containers/Flow/Flow.tsx index f6c1bde16e..984b9a8f7f 100644 --- a/src/containers/Flow/Flow.tsx +++ b/src/containers/Flow/Flow.tsx @@ -351,7 +351,7 @@ export const Flow = () => { customHandler={customHandler} helpData={flowInfo} backLinkButton={`/${backLink}`} - buttonState={{ text: 'Save', status: isTemplate }} + buttonState={{ text: 'Save', status: isTemplate, show: true }} restrictButtonStatus={{ status: isTemplate }} /> ); diff --git a/src/containers/Form/FormLayout.tsx b/src/containers/Form/FormLayout.tsx index dd6500eae7..cfb5ad4092 100644 --- a/src/containers/Form/FormLayout.tsx +++ b/src/containers/Form/FormLayout.tsx @@ -53,6 +53,7 @@ export interface FormLayoutProps { text?: string; status?: boolean; styles?: string; + show?: boolean; }; type?: string; afterSave?: Function; @@ -76,6 +77,7 @@ export interface FormLayoutProps { languageAttributes?: any; helpData?: HelpDataProps; noHeading?: boolean; + isView?: boolean; partialPage?: boolean; confirmationState?: { show: boolean; @@ -86,7 +88,10 @@ export interface FormLayoutProps { text?: string; status?: boolean; }; - skipCancel?: boolean; + errorButtonState?: { + show?: boolean; + text?: string; + }; } export const FormLayout = ({ @@ -95,9 +100,14 @@ export const FormLayout = ({ setStates, validationSchema, listItemName, + isView = false, dialogMessage, formFields, redirectionLink, + errorButtonState = { + show: true, + text: 'Cancel', + }, listItem, getItemQuery, createItemQuery, @@ -118,7 +128,7 @@ export const FormLayout = ({ advanceSearch, cancelAction, button = 'Save', - buttonState = { text: '', status: false, styles: '' }, + buttonState = { text: '', status: false, styles: '', show: true }, type, afterSave, afterDelete, @@ -140,7 +150,6 @@ export const FormLayout = ({ partialPage = false, confirmationState, restrictButtonStatus, - skipCancel = false, }: FormLayoutProps) => { const [showDialog, setShowDialog] = useState(false); const [formSubmitted, setFormSubmitted] = useState(false); @@ -584,22 +593,24 @@ export const FormLayout = ({ ); })}
- + {buttonState.show && ( + + )} {additionalAction ? ( )} @@ -653,6 +664,7 @@ export const FormLayout = ({ } let formTitle = ''; + let headerHelp: string = `Please enter below details.`; // set title if there is a title if (title) { @@ -660,12 +672,14 @@ export const FormLayout = ({ } else if (type === 'copy') { formTitle = `Copy ${listItemName}`; // case when copying an item } else if (itemId) { - formTitle = `Edit ${listItemName}`; // case when editing a item + formTitle = isView ? `${listItemName}` : `Edit ${listItemName}`; // case when editing a item } else { formTitle = `Create a new ${listItemName}`; // case when adding a new item } - - let heading = ; + if (isView) { + headerHelp = `Please view below details.`; + } + let heading = ; let confirmationDialog; if (showConfirmationDialog) { diff --git a/src/containers/HSM/HSM.test.tsx b/src/containers/HSM/HSM.test.tsx index 1e44422417..afc29a6433 100644 --- a/src/containers/HSM/HSM.test.tsx +++ b/src/containers/HSM/HSM.test.tsx @@ -51,7 +51,7 @@ describe('Edit mode', () => { ); await waitFor(() => { - expect(getByText('Edit HSM Template')).toBeInTheDocument(); + expect(getByText('HSM Template')).toBeInTheDocument(); }); await waitFor(() => { @@ -72,7 +72,7 @@ describe('Edit mode', () => { ); await waitFor(() => { - expect(getByText('Edit HSM Template')).toBeInTheDocument(); + expect(getByText('HSM Template')).toBeInTheDocument(); }); await waitFor(() => { @@ -197,7 +197,7 @@ describe('Add mode', () => { render(template); await waitFor(() => { - expect(screen.getByText('Add a new HSM Template')).toBeInTheDocument(); + expect(screen.getByText('Create a new HSM Template')).toBeInTheDocument(); }); const inputs = screen.getAllByRole('textbox'); @@ -272,7 +272,7 @@ describe('Add mode', () => { render(template); await waitFor(() => { - expect(screen.getByText('Add a new HSM Template')).toBeInTheDocument(); + expect(screen.getByText('Create a new HSM Template')).toBeInTheDocument(); }); fireEvent.click(screen.getByText('Add buttons')); diff --git a/src/containers/HSM/HSM.tsx b/src/containers/HSM/HSM.tsx index 9963d1e17d..57eb062713 100644 --- a/src/containers/HSM/HSM.tsx +++ b/src/containers/HSM/HSM.tsx @@ -104,12 +104,16 @@ export const HSM = () => { let backButton = location.state?.tag?.label ? `template?tag=${location.state?.tag?.label}` : 'template'; const { data: categoryList, loading: categoryLoading } = useQuery(GET_HSM_CATEGORIES); - const { data: shortCodes, loading: shortcodesLoading, refetch: refetchShortcodes} = useQuery(GET_SHORTCODES, { + const { + data: shortCodes, + loading: shortcodesLoading, + refetch: refetchShortcodes, + } = useQuery(GET_SHORTCODES, { variables: { filter: { isHsm: true, }, - } + }, }); const { data: tag, loading: tagLoading } = useQuery(GET_TAGS, { @@ -502,16 +506,6 @@ export const HSM = () => { }; const fields = [ - { - component: Checkbox, - name: 'isActive', - title: ( - - Active? - - ), - darkCheckbox: true, - }, { component: AutoComplete, name: 'language', @@ -885,6 +879,7 @@ export const HSM = () => { { icon={templateIcon} getLanguageId={getLanguageId} languageSupport={false} + errorButtonState={{ text: isEditing ? t('Go Back') : t('Cancel'), show: true }} isAttachment getQueryFetchPolicy="cache-and-network" button={!isEditing ? t('Submit for Approval') : t('Save')} - buttonState={{ text: t('Validating URL'), status: validatingURL }} + buttonState={{ text: t('Validating URL'), status: validatingURL, show: !isEditing }} saveOnPageChange={false} type={mode} copyNotification={copyMessage} diff --git a/src/containers/HSM/HSMList/HSMList.test.tsx b/src/containers/HSM/HSMList/HSMList.test.tsx index 41eb040c2c..5ae466a779 100644 --- a/src/containers/HSM/HSMList/HSMList.test.tsx +++ b/src/containers/HSM/HSMList/HSMList.test.tsx @@ -132,6 +132,21 @@ test('should navigate to create template page', async () => { expect(mockedUsedNavigate).toHaveBeenCalledWith('/template/add'); }); +test('should navigate to edit template page', async () => { + const { getByText } = render(template(syncTemplateQuery)); + + await waitFor(() => { + expect(getByText('HSM Templates')).toBeInTheDocument(); + }); + + const viewIcons = await screen.findAllByTestId('view-icon', {}, { timeout: 5000 }); + fireEvent.click(viewIcons[0]); + + await waitFor(() => { + expect(mockedUsedNavigate).toHaveBeenCalledWith('/template/1/edit'); + }); +}); + test('should navigate to create template page with selected tag', async () => { const { getByText, getByTestId, getAllByRole } = render(template(syncTemplateQuery)); diff --git a/src/containers/HSM/HSMList/HSMList.tsx b/src/containers/HSM/HSMList/HSMList.tsx index 9c4545b478..f67c0cea71 100644 --- a/src/containers/HSM/HSMList/HSMList.tsx +++ b/src/containers/HSM/HSMList/HSMList.tsx @@ -21,6 +21,7 @@ import { templateInfo, templateStatusInfo } from 'common/HelpData'; import { setNotification } from 'common/notification'; import { WhatsAppToJsx } from 'common/RichEditor'; import { capitalizeFirstLetter, copyToClipboardMethod, exportCsvFile, getFileExtension } from 'common/utils'; +import ViewIcon from 'assets/images/icons/ViewLight.svg?react'; import { AutoComplete } from 'components/UI/Form/AutoComplete/AutoComplete'; import { Button } from 'components/UI/Form/Button/Button'; @@ -386,7 +387,16 @@ export const HSMList = () => { button.show = false; } + const handleView = (id: any) => { + navigate(`/template/${id}/edit`); + }; let additionalAction: any = () => [ + { + label: t('View'), + icon: , + parameter: 'id', + dialog: handleView, + }, { label: t('Copy UUID'), icon: , @@ -443,6 +453,9 @@ export const HSMList = () => { {...queries} filterList={filterTemplateStatus} filters={selectedTag?.id ? { ...appliedFilters, tagIds: [parseInt(selectedTag.id)] } : appliedFilters} + restrictedAction={(item: any) => ({ + edit: false, + })} /> ); diff --git a/src/containers/InteractiveMessage/InteractiveMessage.tsx b/src/containers/InteractiveMessage/InteractiveMessage.tsx index 29284f8209..19afbdd7da 100644 --- a/src/containers/InteractiveMessage/InteractiveMessage.tsx +++ b/src/containers/InteractiveMessage/InteractiveMessage.tsx @@ -1041,7 +1041,7 @@ export const InteractiveMessage = () => { getQueryFetchPolicy="cache-and-network" afterSave={afterSave} saveOnPageChange={false} - buttonState={{ text: t('Validating URL'), status: validatingURL }} + buttonState={{ text: t('Validating URL'), status: validatingURL, show: true }} helpData={interactiveMessageInfo} backLinkButton={`/${backButton}`} /> diff --git a/src/containers/MyAccount/MyAccount.tsx b/src/containers/MyAccount/MyAccount.tsx index e2e19844f9..40b752dd62 100644 --- a/src/containers/MyAccount/MyAccount.tsx +++ b/src/containers/MyAccount/MyAccount.tsx @@ -303,7 +303,7 @@ export const MyAccount = () => { return (
- +
{userForm} diff --git a/src/containers/Profile/Contact/ContactProfile.tsx b/src/containers/Profile/Contact/ContactProfile.tsx index d0b8ec30ae..86807ce402 100644 --- a/src/containers/Profile/Contact/ContactProfile.tsx +++ b/src/containers/Profile/Contact/ContactProfile.tsx @@ -179,7 +179,7 @@ export const ContactProfile = () => { return ( <> - + {drawer} {profileBodyContent} diff --git a/src/containers/Search/Search.tsx b/src/containers/Search/Search.tsx index 1e12eabf70..dc6d3ce3cd 100644 --- a/src/containers/Search/Search.tsx +++ b/src/containers/Search/Search.tsx @@ -541,11 +541,12 @@ export const Search = ({ afterSave={saveHandler} helpData={searchInfo} backLinkButton="/search" - skipCancel={chatFilters} + errorButtonState={{ text: t('Cancel'), show: !chatFilters }} buttonState={ chatFilters ? { styles: styles.Buttons, + show: true, } : undefined } diff --git a/src/containers/SettingList/OrganizationFlows/OrganisationFLows.test.tsx b/src/containers/SettingList/OrganizationFlows/OrganisationFLows.test.tsx index c8db0b44c8..2c8c9371ec 100644 --- a/src/containers/SettingList/OrganizationFlows/OrganisationFLows.test.tsx +++ b/src/containers/SettingList/OrganizationFlows/OrganisationFLows.test.tsx @@ -24,7 +24,7 @@ test('it renders component properly', async () => { expect(getByText('Loading...')).toBeInTheDocument(); }); -test('it renders component and clicks cancel', async () => { +test('it renders component and clicks Cancel Button', async () => { const { getByText } = render(wrapper); // loading is show initially expect(getByText('Loading...')).toBeInTheDocument(); diff --git a/src/containers/SettingList/Providers/Providers.test.tsx b/src/containers/SettingList/Providers/Providers.test.tsx index 7d5ba34822..062fb0b6f7 100644 --- a/src/containers/SettingList/Providers/Providers.test.tsx +++ b/src/containers/SettingList/Providers/Providers.test.tsx @@ -59,7 +59,7 @@ describe('', () => { }); describe('', () => { - it('Click on Cancel button', async () => { + it('Click on Go Back button', async () => { const { getByText } = render(wrapperWithType); // loading is show initially expect(getByText('Loading...')).toBeInTheDocument(); diff --git a/src/containers/SettingList/Providers/Providers.tsx b/src/containers/SettingList/Providers/Providers.tsx index 7b27b863e5..95930a9e9a 100644 --- a/src/containers/SettingList/Providers/Providers.tsx +++ b/src/containers/SettingList/Providers/Providers.tsx @@ -276,6 +276,7 @@ export const Providers = () => { buttonState={{ text: isDisabled ? 'Credentials Locked' : 'Save', status: isDisabled && type === 'gupshup', + show: true, }} /> ); diff --git a/src/containers/SpeedSend/SpeedSend.tsx b/src/containers/SpeedSend/SpeedSend.tsx index 9c1910c225..e12b11b0da 100644 --- a/src/containers/SpeedSend/SpeedSend.tsx +++ b/src/containers/SpeedSend/SpeedSend.tsx @@ -496,7 +496,7 @@ export const SpeedSend = () => { getMediaId={getMediaId} getQueryFetchPolicy="cache-and-network" button={t('Save')} - buttonState={{ text: t('Validating URL'), status: validatingURL }} + buttonState={{ text: t('Validating URL'), status: validatingURL, show: true }} saveOnPageChange={false} type={mode} copyNotification={t('Copy of the template has been created!')} diff --git a/src/containers/TemplateOptions/TemplateOptions.test.tsx b/src/containers/TemplateOptions/TemplateOptions.test.tsx index 45af9c3c1c..1491975b7c 100644 --- a/src/containers/TemplateOptions/TemplateOptions.test.tsx +++ b/src/containers/TemplateOptions/TemplateOptions.test.tsx @@ -17,7 +17,7 @@ const wrapper = (initialEntry: string = '/template/add') => ( test('it renders component and selects call to action type', async () => { const { findByText, getByText, findByLabelText } = render(wrapper()); - const hsmTitle = await findByText('Add a new HSM Template'); + const hsmTitle = await findByText('Create a new HSM Template'); expect(hsmTitle).toBeInTheDocument(); const addButtonsCheckbox = getByText('Add buttons'); fireEvent.click(addButtonsCheckbox); @@ -31,7 +31,7 @@ test('it renders component and selects call to action type', async () => { test('it renders call to action button template successfully', async () => { const { findByText, getAllByRole, getByText, findByLabelText } = render(wrapper()); - const hsmTitle = await findByText('Add a new HSM Template'); + const hsmTitle = await findByText('Create a new HSM Template'); expect(hsmTitle).toBeInTheDocument(); const addButtonsCheckbox = getByText('Add buttons'); fireEvent.click(addButtonsCheckbox); @@ -58,7 +58,7 @@ test('it renders call to action button template successfully', async () => { test('it renders quick reply button template successfully', async () => { const { findByText, findByLabelText, getByText, getByTestId } = render(wrapper()); - const hsmTitle = await findByText('Add a new HSM Template'); + const hsmTitle = await findByText('Create a new HSM Template'); expect(hsmTitle).toBeInTheDocument(); const addButtonsCheckbox = getByText('Add buttons'); fireEvent.click(addButtonsCheckbox); diff --git a/src/containers/Trigger/Trigger.test.tsx b/src/containers/Trigger/Trigger.test.tsx index e642ba9a4c..21306a5bcb 100644 --- a/src/containers/Trigger/Trigger.test.tsx +++ b/src/containers/Trigger/Trigger.test.tsx @@ -40,7 +40,7 @@ const startTime = dayjs().add(1, 'hour'); const fillForm = async (container: any, frequency: string) => { await waitFor(() => { - expect(screen.getByText('Create a new trigger')).toBeInTheDocument(); + expect(screen.getByText('Create a new Trigger')).toBeInTheDocument(); }); await waitFor(() => { @@ -139,7 +139,7 @@ describe('add mode', () => { expect(screen.getByText('Loading...')).toBeInTheDocument(); await waitFor(() => { - expect(screen.getByText('Create a new trigger')).toBeInTheDocument(); + expect(screen.getByText('Create a new Trigger')).toBeInTheDocument(); }); const autoCompletes = screen.getAllByRole('combobox'); @@ -207,7 +207,7 @@ describe('add mode', () => { expect(screen.getByText('Loading...')).toBeInTheDocument(); await waitFor(() => { - expect(screen.getByText('Create a new trigger')).toBeInTheDocument(); + expect(screen.getByText('Create a new Trigger')).toBeInTheDocument(); }); const autoCompletes = screen.getAllByRole('combobox'); @@ -244,7 +244,7 @@ describe('add mode', () => { expect(screen.getByText('Loading...')).toBeInTheDocument(); await waitFor(() => { - expect(screen.getByText('Create a new trigger')).toBeInTheDocument(); + expect(screen.getByText('Create a new Trigger')).toBeInTheDocument(); }); const autoCompletes = screen.getAllByRole('combobox'); @@ -268,7 +268,7 @@ describe('add mode', () => { expect(screen.getByText('Loading...')).toBeInTheDocument(); await waitFor(() => { - expect(screen.getByText('Create a new trigger')).toBeInTheDocument(); + expect(screen.getByText('Create a new Trigger')).toBeInTheDocument(); }); const startDateInput = container.queryByTestId('Start date'); @@ -320,7 +320,7 @@ describe('edit mode', () => { expect(screen.getByText('Loading...')).toBeInTheDocument(); await waitFor(() => { - expect(screen.getByText('Edit trigger')).toBeInTheDocument(); + expect(screen.getByText('Trigger')).toBeInTheDocument(); }); await waitFor(() => { @@ -330,12 +330,6 @@ describe('edit mode', () => { await waitFor(() => { expect(screen.getAllByRole('combobox')[1]).toHaveValue('Hourly'); }); - - fireEvent.click(screen.getByTestId('submitActionButton')); - - await waitFor(() => { - expect(notificationSpy).toHaveBeenCalledWith('Trigger edited successfully!'); - }); }); test('should renders form for daily triggers', async () => { @@ -354,7 +348,7 @@ describe('edit mode', () => { expect(screen.getByText('Loading...')).toBeInTheDocument(); await waitFor(() => { - expect(screen.getByText('Edit trigger')).toBeInTheDocument(); + expect(screen.getByText('Trigger')).toBeInTheDocument(); }); await waitFor(() => { @@ -382,7 +376,7 @@ describe('edit mode', () => { expect(screen.getByText('Loading...')).toBeInTheDocument(); await waitFor(() => { - expect(screen.getByText('Edit trigger')).toBeInTheDocument(); + expect(screen.getByText('Trigger')).toBeInTheDocument(); }); await waitFor(() => { @@ -412,7 +406,7 @@ describe('edit mode', () => { expect(screen.getByText('Loading...')).toBeInTheDocument(); await waitFor(() => { - expect(screen.getByText('Edit trigger')).toBeInTheDocument(); + expect(screen.getByText('Trigger')).toBeInTheDocument(); }); await waitFor(() => { @@ -442,13 +436,13 @@ describe('edit mode', () => { expect(screen.getByText('Loading...')).toBeInTheDocument(); await waitFor(() => { - expect(screen.getByText('Edit trigger')).toBeInTheDocument(); + expect(screen.getByText('Trigger')).toBeInTheDocument(); }); fireEvent.click(screen.getByTestId('remove-icon')); await waitFor(() => { - expect(screen.getByText('Are you sure you want to delete the trigger?')).toBeInTheDocument(); + expect(screen.getByText('Are you sure you want to delete the Trigger?')).toBeInTheDocument(); }); fireEvent.click(screen.getByTestId('ok-button')); @@ -490,7 +484,7 @@ describe('copy mode', async () => { expect(screen.getByText('Loading...')).toBeInTheDocument(); await waitFor(() => { - expect(screen.getByText('Copy trigger')).toBeInTheDocument(); + expect(screen.getByText('Copy Trigger')).toBeInTheDocument(); }); await waitFor(() => { @@ -521,7 +515,7 @@ describe('copy mode', async () => { fireEvent.click(screen.getByTestId('submitActionButton')); await waitFor(() => { - expect(screen.getByText('Copy trigger')).toBeInTheDocument(); + expect(screen.getByText('Copy Trigger')).toBeInTheDocument(); }); }); }); @@ -548,7 +542,7 @@ describe('Whatsapp group collections', () => { expect(screen.getByText('Loading...')).toBeInTheDocument(); await waitFor(() => { - expect(screen.getByText('Create a new trigger')).toBeInTheDocument(); + expect(screen.getByText('Create a new Trigger')).toBeInTheDocument(); }); await fillForm(container, 'Daily'); @@ -578,7 +572,7 @@ describe('Whatsapp group collections', () => { expect(screen.getByText('Loading...')).toBeInTheDocument(); await waitFor(() => { - expect(screen.getByText('Edit trigger')).toBeInTheDocument(); + expect(screen.getByText('Trigger')).toBeInTheDocument(); }); await waitFor(() => { diff --git a/src/containers/Trigger/Trigger.tsx b/src/containers/Trigger/Trigger.tsx index 62debef405..bfd4b14a7a 100644 --- a/src/containers/Trigger/Trigger.tsx +++ b/src/containers/Trigger/Trigger.tsx @@ -372,6 +372,7 @@ export const Trigger = () => { handleOnChange: (value: any) => setGroupType(value), groupType: groupType, isWhatsAppGroupEnabled: isWhatsAppGroupEnabled, + disabled: isEditing, }, { component: AutoComplete, @@ -443,12 +444,15 @@ export const Trigger = () => { setPayload={(payload: any) => setPayload(payload, roles, groupType)} validationSchema={FormSchema} languageSupport={false} - listItemName="trigger" + listItemName="Trigger" dialogMessage={dialogMessage} formFields={formFields} redirectionLink="trigger" listItem="trigger" type={type} + isView={isEditing} + errorButtonState={{ text: isEditing ? t('Go Back') : t('Cancel'), show: true }} + buttonState={{ show: !isEditing }} copyNotification={t('Copy of the trigger has been created!')} icon={triggerIcon} customStyles={styles.Triggers} diff --git a/src/containers/Trigger/TriggerList/TriggerList.test.tsx b/src/containers/Trigger/TriggerList/TriggerList.test.tsx index c60bb85c72..eca38308e8 100644 --- a/src/containers/Trigger/TriggerList/TriggerList.test.tsx +++ b/src/containers/Trigger/TriggerList/TriggerList.test.tsx @@ -17,6 +17,15 @@ const wrapper = ( ); setUserSession(JSON.stringify({ roles: ['Admin'] })); +const mockedUsedNavigate = vi.fn(); +vi.mock('react-router', async () => { + return { + ...(await vi.importActual('react-router')), + useLocation: () => ({ state: 'copy', pathname: '/trigger/1/edit' }), + useParams: () => ({ id: 1 }), + useNavigate: () => mockedUsedNavigate, + }; +}); test('should load the trigger list', async () => { const { getByText, getByTestId } = render(wrapper); @@ -47,3 +56,16 @@ test('hover over tooltip', async () => { expect(getByText('Repeat: weekly(Mon,Tue)')); }); }); + +test('should navigate to edit page on clicking the view button', async () => { + const { getAllByTestId, getByText } = render(wrapper); + + await waitFor(() => { + expect(getByText('Triggers')).toBeInTheDocument(); + }); + + fireEvent.click(getAllByTestId('view-trigger')[0]); + await waitFor(() => { + expect(mockedUsedNavigate).toHaveBeenCalledWith('/trigger/1/edit'); + }); +}); diff --git a/src/containers/Trigger/TriggerList/TriggerList.tsx b/src/containers/Trigger/TriggerList/TriggerList.tsx index 179aafb5ec..794b2476d7 100644 --- a/src/containers/Trigger/TriggerList/TriggerList.tsx +++ b/src/containers/Trigger/TriggerList/TriggerList.tsx @@ -13,6 +13,7 @@ import { List } from 'containers/List/List'; import { Tooltip } from 'components/UI/Tooltip/Tooltip'; import styles from './TriggerList.module.css'; import { triggerInfo } from 'common/HelpData'; +import ViewIcon from 'assets/images/icons/ViewLight.svg?react'; dayjs.extend(relativeTime); const getTooltip = (frequency: any, days: any) => { @@ -74,6 +75,10 @@ export const TriggerList = () => { navigate(`/trigger/${id}/edit`, { state: 'copy' }); }; + const handleView = (id: any) => { + navigate(`/trigger/${id}/edit`); + }; + const additionalAction = () => [ { label: t('Copy'), @@ -81,6 +86,12 @@ export const TriggerList = () => { parameter: 'id', dialog: setDialog, }, + { + label: t('View'), + icon: , + parameter: 'id', + dialog: handleView, + }, ]; const columnNames: any = [ @@ -113,6 +124,10 @@ export const TriggerList = () => { searchParameter={['name']} additionalAction={additionalAction} sortConfig={{ sortBy: 'updated_at', sortOrder: 'desc' }} + restrictedAction={(item: any) => ({ + edit: false, + delete: true, + })} /> ); }; diff --git a/src/containers/Trigger/TriggerType/TriggerType.tsx b/src/containers/Trigger/TriggerType/TriggerType.tsx index 74bffd2243..a460d5ba0a 100644 --- a/src/containers/Trigger/TriggerType/TriggerType.tsx +++ b/src/containers/Trigger/TriggerType/TriggerType.tsx @@ -6,12 +6,14 @@ export interface TriggerTypeProps { groupType: string; isWhatsAppGroupEnabled: boolean; handleOnChange?: any; + disabled?: boolean; form: { dirty: any; touched: any; errors: any; setFieldValue: any; values: any }; } export const TriggerType = ({ groupType, isWhatsAppGroupEnabled, handleOnChange, + disabled = false, form: { setFieldValue }, }: TriggerTypeProps) => { const isChecked = (value: string) => groupType === value; @@ -40,7 +42,7 @@ export const TriggerType = ({ data-testid="radio-btn" value={CONTACTS_COLLECTION} checked={isChecked(CONTACTS_COLLECTION)} - control={} + control={} label={'WABA Collections'} className={styles.Label} /> @@ -50,7 +52,7 @@ export const TriggerType = ({ data-testid="radio-btn" value={WA_GROUPS_COLLECTION} checked={isChecked(WA_GROUPS_COLLECTION)} - control={} + control={} label={'WhatsApp Group Collections'} className={styles.Label} /> diff --git a/src/containers/WaGroups/GroupDetails.tsx/GroupDetails.tsx b/src/containers/WaGroups/GroupDetails.tsx/GroupDetails.tsx index 4b0f3c275b..6860e67723 100644 --- a/src/containers/WaGroups/GroupDetails.tsx/GroupDetails.tsx +++ b/src/containers/WaGroups/GroupDetails.tsx/GroupDetails.tsx @@ -223,7 +223,7 @@ export const GroupDetails = () => { return ( <> - +
{drawer} diff --git a/src/containers/WhatsAppForms/WhatsAppForms.tsx b/src/containers/WhatsAppForms/WhatsAppForms.tsx index 4800d14b19..9834ca2545 100644 --- a/src/containers/WhatsAppForms/WhatsAppForms.tsx +++ b/src/containers/WhatsAppForms/WhatsAppForms.tsx @@ -269,6 +269,7 @@ export const WhatsAppForms = () => { buttonState={{ text: 'Save Form', status: disabled, + show: true, }} customHandler={(error: string) => { setErrorMessage(formatError(error), 'An error occurred'); diff --git a/src/i18n/en/en.json b/src/i18n/en/en.json index 37b40fd93d..2fb9071395 100644 --- a/src/i18n/en/en.json +++ b/src/i18n/en/en.json @@ -31,6 +31,7 @@ "Your full name": "Your full name", "Your personal WhatsApp number": "Your personal WhatsApp number", "Register with ": "Register with ", + "Go Back": "Go Back", "Login to Glific": "Login to Glific", "Phone number": "Phone number", "New Password": "New Password", diff --git a/src/mocks/Template.tsx b/src/mocks/Template.tsx index 30a1cd79e7..92faf4c172 100644 --- a/src/mocks/Template.tsx +++ b/src/mocks/Template.tsx @@ -568,6 +568,34 @@ export const updateSessiontemplate = { }; export const templatesData = [ + { + id: '1', + bspId: null, + label: 'Test Template', + body: 'Test body', + shortcode: 'test', + category: 'ACCOUNT_UPDATE', + isReserved: false, + status: 'APPROVED', + reason: 'test reason', + isHsm: true, + isActive: true, + updatedAt: '2020-12-01T18:00:32Z', + numberParameters: 0, + translations: + '{"2":{"status":"approved","languageId":{"label":"Hindi","id":"2"},"label":"now","isHsm":false,"body":"hey","MessageMedia":null}}', + type: 'TEXT', + quality: null, + language: { + id: '1', + label: 'Hindi', + }, + MessageMedia: { + id: 1, + caption: 'Test', + sourceUrl: 'https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__340.jpg', + }, + }, { id: '87', bspId: null,