Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mdshamoon committed Aug 9, 2023
2 parents dd8b7d8 + 8794bb4 commit bc8a2f3
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@
.OtherColumnText:hover > span {
visibility: visible;
opacity: 1;
transition: visibility 0s linear 0s, opacity 900ms;
transition:
visibility 0s linear 0s,
opacity 900ms;
}

.OtherColumnText > span {
visibility: hidden;
opacity: 0;
transition: visibility 0s linear 300ms, opacity 300ms;
transition:
visibility 0s linear 300ms,
opacity 300ms;
padding: 8px;
margin-left: -8px;
background: radial-gradient(white, transparent);
Expand Down Expand Up @@ -100,3 +104,12 @@
margin-bottom: 0px;
padding-bottom: 64px;
}

.DialogSubText {
text-align: left;
font-size: 16px;
}

.Title {
max-width: 460px !important;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ const ContactFieldList = () => {
const [itemToBeEdited, setItemToBeEdited] = useState<EditItemShape | any>(null);
const [error, setError] = useState<any>(null);

const [deleteContactField] = useMutation(DELETE_CONTACT_FIELDS, {
onError: () => {
setNotification('Sorry! An error occured while deleting the contact field', 'warning');
},
});

let dialog;

if (openDialog) {
Expand Down Expand Up @@ -144,7 +150,42 @@ const ContactFieldList = () => {
};

const listIcon = <ContactVariableIcon className={styles.ContactFieldIcon} color="primary.dark" />;
const dialogMessage = t('This action cannot be undone.');
const dialogMessage = ({ deleteItemID, deleteItemName, refetch, setDeleteItemID }: any) => {
const component = (
<div>
<p className={styles.DialogSubText}>
<strong> Available options:-</strong>
<br />
1. Delete only contact field (no impact on contacts).
<br />
2. Delete contact field and associated data (removes "{deleteItemName}" field from all
contacts).
</p>
</div>
);

return {
component,
props: {
buttonOk: 'Delete field',
buttonMiddle: 'Delete field & data',
additionalTitleStyles: styles.Title,
handleMiddle: () => {
deleteContactField({
variables: {
deleteAssoc: true,
id: deleteItemID,
},
onCompleted: () => {
setNotification('Contact field deleted successfully!');
refetch();
setDeleteItemID(null);
},
});
},
},
};
};
const dialogTitle = t('Are you sure you want to delete this contact field record?');

return (
Expand Down
8 changes: 5 additions & 3 deletions src/containers/List/List.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('<List /> actions', () => {
const { container } = render(listButtons);
await waitFor(() => {
const button = container.querySelector(
'button.MuiButton-containedPrimary'
'button.MuiButton-containedPrimary',
) as HTMLButtonElement;
fireEvent.click(button);
});
Expand Down Expand Up @@ -155,8 +155,10 @@ describe('DialogMessage tests', () => {
);
return {
component,
handleOkCallback: vi.fn(),
isConfirmed: true,
props: {
handleOk: vi.fn(),
disableOk: false,
},
};
};

Expand Down
43 changes: 23 additions & 20 deletions src/containers/List/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export const List = ({
{
variables: filterPayload(),
fetchPolicy: 'cache-first',
}
},
);

// Get item data here
Expand Down Expand Up @@ -324,32 +324,35 @@ export const List = ({
};

const useDelete = (message: string | any) => {
let component: any = {};
const props = { disableOk: false, handleOk: handleDeleteItem };
if (typeof message === 'string') {
component = message;
const props = { handleOk: handleDeleteItem };
return {
component: message,
props,
};
} else {
/**
* Custom component to render
* message should contain 3 params
* 1. component: Component to render
* 2. isConfirm: To check true or false value
* 3. handleOkCallback: Callback action to delete item
* 2. props: props to pass to dialog component
*/
const {
component: componentToRender,
isConfirmed,
handleOkCallback,
} = message(deleteItemID, deleteItemName);
component = componentToRender;
props.disableOk = !isConfirmed;
props.handleOk = () => handleOkCallback({ refetch: fetchQuery, setDeleteItemID });
}

return {
component,
props,
};
const dialogParams = {
deleteItemID,
deleteItemName,
refetch: refetchValues,
setDeleteItemID,
};
const { component, props } = message(dialogParams);
if (!props.handleOk) {
props.handleOk = handleDeleteItem;
}
return {
component,
props,
};
}
};

let dialogBox;
Expand Down Expand Up @@ -390,7 +393,7 @@ export const List = ({
function getIcons(
// id: number | undefined,
item: any,
allowedAction: any | null
allowedAction: any | null,
) {
// there might be a case when we might want to allow certain actions for reserved items
// currently we don't allow edit or delete for reserved items. hence return early
Expand Down
7 changes: 4 additions & 3 deletions src/containers/OrganizationList/OrganizationList.test.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { render, cleanup, fireEvent, act, screen } from '@testing-library/react';
import { render, cleanup, fireEvent, act, screen, waitFor } from '@testing-library/react';
import { MockedProvider } from '@apollo/client/testing';
import UserEvent from '@testing-library/user-event';
import { BrowserRouter as Router } from 'react-router-dom';

import { getAllOrganizations } from 'mocks/Organization';
import { deleteOrganization, getAllOrganizations } from 'mocks/Organization';
import { setUserSession } from 'services/AuthService';
import OrganizationList from './OrganizationList';

afterEach(cleanup);
const mocks = getAllOrganizations;
const mocks = [...getAllOrganizations, deleteOrganization];
setUserSession(JSON.stringify({ organization: { id: '1' }, roles: ['Admin'] }));

const props = { openExtensionModal: false, openCustomerModal: false };
Expand Down Expand Up @@ -73,4 +73,5 @@ test('Update status', async () => {
expect(confirmDeleteButton).toBeInTheDocument();

fireEvent.click(confirmDeleteButton);
await waitFor(() => {});
});
14 changes: 8 additions & 6 deletions src/containers/OrganizationList/OrganizationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const OrganizationList = ({
setNotification('Organization deleted successfully');
};

const deleteDialogue = (id: any, name: any) => {
const deleteDialogue = ({ deleteItemID, deleteItemName, refetch, setDeleteItemID }: any) => {
const component = (
<div>
<p className={styles.DialogSubText}>
Expand All @@ -131,16 +131,18 @@ export const OrganizationList = ({
/>
</div>
);

const isConfirmed = orgName === name;
const isConfirmed = orgName === deleteItemName;
console.log(orgName, deleteItemName);
const payload = {
isConfirmed,
deleteOrganizationID: id,
deleteOrganizationID: deleteItemID,
};
return {
component,
handleOkCallback: (val: any) => handleDeleteInActiveOrg({ payload, ...val }),
isConfirmed,
props: {
disableOk: !isConfirmed,
handleOk: () => handleDeleteInActiveOrg({ payload, refetch, setDeleteItemID }),
},
};
};

Expand Down
10 changes: 6 additions & 4 deletions src/containers/Ticket/Ticket.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test('Render component correctly with the values', async () => {
render(
<MockedProvider mocks={mocks}>
<Ticket selectedTicket={'1'} setOpenDialog={setOpenDialogMock} />
</MockedProvider>
</MockedProvider>,
);

expect(screen.getByText('Loading...')).toBeInTheDocument();
Expand All @@ -28,7 +28,9 @@ test('Render component correctly with the values', async () => {
});

// should have the heading as the issue
expect(screen.getByTestId('formLayout')).toHaveTextContent('Please resolve this issue');
// also should have remarks
expect(screen.getByTestId('formLayout')).toHaveTextContent('The issue was resolved');
await waitFor(() => {
expect(screen.getByTestId('formLayout')).toHaveTextContent('Please resolve this issue');
// also should have remarks
expect(screen.getByTestId('formLayout')).toHaveTextContent('The issue was resolved');
});
});
4 changes: 2 additions & 2 deletions src/graphql/mutations/ContactFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export const UPDATE_CONTACT_FIELDS = gql`
`;

export const DELETE_CONTACT_FIELDS = gql`
mutation deleteContactsField($id: ID!) {
deleteContactsField(id: $id) {
mutation deleteContactsField($id: ID!, $deleteAssoc: Boolean) {
deleteContactsField(id: $id, deleteAssoc: $deleteAssoc) {
contactsField {
valueType
updatedAt
Expand Down
14 changes: 13 additions & 1 deletion src/mocks/Organization.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UPDATE_CREDENTIAL } from 'graphql/mutations/Organization';
import { DELETE_INACTIVE_ORGANIZATIONS, UPDATE_CREDENTIAL } from 'graphql/mutations/Organization';
import {
GET_ORGANIZATION,
USER_LANGUAGES,
Expand Down Expand Up @@ -722,6 +722,18 @@ export const getAllOrganizations = [
},
];

export const deleteOrganization = {
request: {
query: DELETE_INACTIVE_ORGANIZATIONS,
variables: { isConfirmed: false, deleteOrganizationID: '2' },
},
result: {
data: {
organization: null,
},
},
};

export const getOrganizationBSP = {
request: {
query: GET_ORGANIZATION_PROVIDER,
Expand Down

0 comments on commit bc8a2f3

Please sign in to comment.