Skip to content

Commit

Permalink
Merge branch 'master' into error-banner
Browse files Browse the repository at this point in the history
  • Loading branch information
kurund authored Apr 9, 2024
2 parents 5345638 + a7bcdd3 commit 153ae47
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 32 deletions.
6 changes: 4 additions & 2 deletions src/components/UI/Heading/Heading.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

.HeadingWrapper {
margin-left: 46px;
display: flex;
gap: 10px;
align-items: flex-start;
}

.TextHeading {
Expand All @@ -34,7 +37,6 @@
}

.BackIcon {
margin-left: -10px;
margin-right: 10px;
cursor: pointer;
margin-top: 10px;
}
36 changes: 36 additions & 0 deletions src/components/UI/Heading/Heading.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { describe } from 'vitest';
import { Heading } from './Heading';
import { fireEvent, render, waitFor } from '@testing-library/react';
import { MemoryRouter } from 'react-router';

const wrapper = (
<MemoryRouter>
<Heading backLink={'/back-link'} formTitle={'Heading Title'} />
</MemoryRouter>
);

const mockedUsedNavigate = vi.fn();
vi.mock('react-router-dom', async () => ({
...(await vi.importActual('react-router-dom')),
useNavigate: () => mockedUsedNavigate,
}));

describe('Heading', () => {
test('it should have Heading Title as heading', async () => {
const { getByText } = render(wrapper);

await waitFor(() => {
expect(getByText('Heading Title')).toBeInTheDocument();
});
});

test('it should navigate to the back link', async () => {
const { getByTestId } = render(wrapper);

fireEvent.click(getByTestId('back-button'));

await waitFor(() => {
expect(mockedUsedNavigate).toHaveBeenCalled();
});
});
});
22 changes: 10 additions & 12 deletions src/components/UI/Heading/Heading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,17 @@ export const Heading = ({ formTitle, helpData, showHeaderHelp = true, backLink }
return (
<div className={styles.Heading} data-testid="heading">
<div className={styles.HeadingWrapper}>
<div className={styles.HeadingTitle}>
{backLink && (
<BackIcon
onClick={() => navigate(backLink)}
className={styles.BackIcon}
data-testid="back-button"
/>
)}
<div className={styles.TitleText}>{formTitle}</div>
{helpData ? <HelpIcon helpData={helpData} /> : ''}
<div className={styles.BackIcon}>
{backLink && <BackIcon onClick={() => navigate(backLink)} data-testid="back-button" />}
</div>
<div className={styles.TextHeading}>
{showHeaderHelp ? `Please enter below details.` : ''}
<div>
<div className={styles.HeadingTitle}>
<div className={styles.TitleText}>{formTitle}</div>
{!helpData ? <HelpIcon helpData={helpData} /> : ''}
</div>
<div className={styles.TextHeading}>
{showHeaderHelp ? `Please enter below details.` : ''}
</div>
</div>
</div>
</div>
Expand Down
4 changes: 3 additions & 1 deletion src/containers/Collection/Collection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const Collection = () => {
const { t } = useTranslation();
const location = useLocation();
const groups: boolean = location.pathname.includes('group');
const redirectLink = groups ? 'group/collection' : 'collection';
const groupType = groups ? WA_GROUPS_COLLECTION : CONTACTS_COLLECTION;
const searchQuery = groups ? GROUP_SEARCH_QUERY : SEARCH_QUERY;
const searchVariables = groups
Expand Down Expand Up @@ -210,10 +211,11 @@ export const Collection = () => {
listItemName="collection"
dialogMessage={dialogMessage}
formFields={formFields}
redirectionLink={`${groups ? 'group/' : ''}collection`}
redirectionLink={redirectLink}
listItem="group"
icon={collectionIcon}
helpData={collectionInfo}
backLinkButton={`/${redirectLink}`}
/>
);
};
Expand Down
1 change: 1 addition & 0 deletions src/containers/Flow/Flow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ export const Flow = () => {
copyNotification={t('Copy of the flow has been created!')}
customHandler={customHandler}
helpData={flowInfo}
backLinkButton="/flow"
/>
);
};
Expand Down
20 changes: 3 additions & 17 deletions src/containers/Form/FormLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, Fragment, useEffect } from 'react';
import { Navigate, Link, useParams } from 'react-router-dom';
import { Navigate, useParams } from 'react-router-dom';
import { Formik, Form, Field } from 'formik';
// eslint-disable-next-line no-unused-vars
import { DocumentNode, ApolloError, useQuery, useMutation } from '@apollo/client';
Expand All @@ -18,7 +18,6 @@ import { GET_ROLE_NAMES } from 'graphql/queries/Role';
import { AutoComplete } from 'components/UI/Form/AutoComplete/AutoComplete';
import { Heading } from 'components/UI/Heading/Heading';
import DeleteIcon from 'assets/images/icons/Delete/White.svg?react';
import BackIcon from 'assets/images/icons/Back.svg?react';
import { organizationHasDynamicRole } from 'common/utils';
import { getUserRole } from 'context/role';
import styles from './FormLayout.module.css';
Expand Down Expand Up @@ -61,10 +60,7 @@ export interface FormLayoutProps {
title?: string;
cancelAction?: Function;
getLanguageId?: Function;
backLinkButton?: {
text: string;
link: string;
};
backLinkButton?: string;
isAttachment?: boolean;
getMediaId?: any;
customStyles?: any;
Expand Down Expand Up @@ -623,16 +619,7 @@ export const FormLayout = ({
formTitle = `Add a new ${listItemName}`; // case when adding a new item
}

let heading = <Heading formTitle={formTitle} />;

const backLink = backLinkButton ? (
<div className={styles.BackLink}>
<Link to={backLinkButton.link}>
<BackIcon />
{backLinkButton.text}
</Link>
</div>
) : null;
let heading = <Heading backLink={backLinkButton} formTitle={formTitle} />;

return (
<div
Expand All @@ -641,7 +628,6 @@ export const FormLayout = ({
>
{dialogBox}
{!noHeading && heading}
{backLink}
{form}
</div>
);
Expand Down
1 change: 1 addition & 0 deletions src/containers/InteractiveMessage/InteractiveMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ export const InteractiveMessage = () => {
saveOnPageChange={false}
buttonState={{ text: t('Validating URL'), status: validatingURL }}
helpData={interactiveMessageInfo}
backLinkButton={'/interactive-message'}
/>
<div className={styles.Simulator}>
<Simulator
Expand Down
1 change: 1 addition & 0 deletions src/containers/Search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ export const Search = ({ type, search, searchId, ...props }: SearchProps) => {
type={type}
afterSave={saveHandler}
helpData={searchInfo}
backLinkButton="/search"
/>
</>
);
Expand Down
1 change: 1 addition & 0 deletions src/containers/SheetIntegration/SheetIntegration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export const SheetIntegration = () => {
listItem="sheet"
icon={sheetIcon}
languageSupport={false}
backLinkButton="/sheet-integration"
/>
);
};
Expand Down
1 change: 1 addition & 0 deletions src/containers/Template/Form/Template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,7 @@ const Template = ({
afterSave={!defaultAttribute.isHsm ? afterSave : undefined}
type={mode}
copyNotification={copyMessage}
backLinkButton={`/${redirectionLink}`}
/>
);
};
Expand Down
1 change: 1 addition & 0 deletions src/containers/Trigger/Trigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ export const Trigger = () => {
icon={triggerIcon}
customStyles={styles.Triggers}
helpData={triggerInfo}
backLinkButton="/trigger"
/>
);
};
Expand Down

0 comments on commit 153ae47

Please sign in to comment.