Skip to content

Commit

Permalink
feat: clean-up ui functions, close modal on save
Browse files Browse the repository at this point in the history
  • Loading branch information
dleard committed Jun 15, 2020
1 parent a381e7d commit 18476aa
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 28 deletions.
5 changes: 4 additions & 1 deletion app/containers/Products/LinkedProductModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ export const LinkedProductModalComponent: React.FunctionComponent<Props> = ({
>
Save
</Button>
<Button variant="danger" onClick={setLinkProductModalShow}>
<Button
variant="danger"
onClick={() => setLinkProductModalShow(false)}
>
Cancel
</Button>
</div>
Expand Down
50 changes: 25 additions & 25 deletions app/containers/Products/ProductRowItemContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
faShareAlt
} from '@fortawesome/free-solid-svg-icons';
import createLinkedProductMutation from 'mutations/linked_product/createLinkedProductMutation';
// Import updateLinkedProductMutation from 'mutations/linked_product/updateLinkedProductMutation';
import updateLinkedProductMutation from 'mutations/linked_product/updateLinkedProductMutation';
import InnerModal from './InnerProductBenchmarkModal';
import LinkedProductModal from './LinkedProductModal';

Expand Down Expand Up @@ -147,7 +147,7 @@ export const ProductRowItemComponent: React.FunctionComponent<Props> = ({
const createLinkedProduct = async (newLink: number) => {
const variables = {
input: {
LinkedProduct: {
linkedProduct: {
productId: product.rowId,
linkedProductId: newLink,
isDeleted: false
Expand All @@ -163,26 +163,27 @@ export const ProductRowItemComponent: React.FunctionComponent<Props> = ({
console.log(response);
};

// TODO: GET ID OF PRODUCT LINK (add to db function?)
const removeLinkedProduct = async (removeLink: number) => {
console.log(removeLink);
// Const variables = {
// input: {
// id: removeLink.id
// linkedProduct: {
// productId: product.rowId,
// linkedProductId: removeLink,
// isDeleted: true
// }
// }
// };
const removeLinkedProduct = async (removeLink: {
productRowId: number;
linkId: number;
}) => {
const variables = {
input: {
rowId: removeLink.linkId,
linkedProductPatch: {
productId: product.rowId,
linkedProductId: removeLink.productRowId,
isDeleted: true
}
}
};

// const response = await updateLinkedProductMutation(
// relay.environment,
// variables
// );
// handleUpdateProductCount((productCount += 1));
// console.log(response);
const response = await updateLinkedProductMutation(
relay.environment,
variables
);
handleUpdateProductCount((productCount += 1));
console.log(response);
};

const linkData = [];
Expand All @@ -195,7 +196,6 @@ export const ProductRowItemComponent: React.FunctionComponent<Props> = ({
});

const saveLinkedProducts = async (newData: IChangeEvent) => {
console.log(newData);
const previousLinks = [];
const newLinks = [];

Expand All @@ -208,18 +208,18 @@ export const ProductRowItemComponent: React.FunctionComponent<Props> = ({

newLinks.forEach(async (id) => {
if (!previousLinks.includes(id)) {
console.log('ADD:', id);
const response = await createLinkedProduct(id);
console.log(response);
}
});

previousLinks.forEach(async (id, index) => {
if (!newLinks.includes(id)) {
console.log('REMOVE:', id);
const response = await removeLinkedProduct(newData[index]);
const response = await removeLinkedProduct(linkData[index]);
console.log(response);
}
});
setLinkProductModalShow(false);
};

/** Modals **/
Expand Down
6 changes: 4 additions & 2 deletions app/mutations/linked_product/updateLinkedProductMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import {
import BaseMutation from 'mutations/BaseMutation';

const mutation = graphql`
mutation updateLinkedProductMutation($input: UpdateLinkedProductInput!) {
updateLinkedProduct(input: $input) {
mutation updateLinkedProductMutation(
$input: UpdateLinkedProductByRowIdInput!
) {
updateLinkedProductByRowId(input: $input) {
linkedProduct {
id
productId
Expand Down

0 comments on commit 18476aa

Please sign in to comment.