Skip to content
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

My Account - Create wishlist UI #2766

Merged
merged 23 commits into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3f44358
Initial stuff
revanth0212 Oct 5, 2020
da6bdd3
Added base modal code.
revanth0212 Oct 6, 2020
2c7ae95
Added rest of the modal UI.
revanth0212 Oct 6, 2020
9c31d60
Using Dialog component.
revanth0212 Oct 7, 2020
54cce93
Added prop types.
revanth0212 Oct 7, 2020
79f548c
Merge remote-tracking branch 'origin/develop' into revanth/my_account…
revanth0212 Oct 7, 2020
ed7ef49
Added useCreateWishList docs.
revanth0212 Oct 7, 2020
a5f5598
Added missing wishlist talon docs.
revanth0212 Oct 7, 2020
203f2f9
Minor.
revanth0212 Oct 8, 2020
fdaf439
Minor.
revanth0212 Oct 8, 2020
f830846
Added cancel button classes for extensibility.
revanth0212 Oct 8, 2020
7ce6516
Changed buttons css.
revanth0212 Oct 8, 2020
94b4a88
Added create wish list tests.
revanth0212 Oct 12, 2020
d963651
Added useCreateWishlist tests.
revanth0212 Oct 13, 2020
53a5354
Update based on PR comments.
revanth0212 Oct 13, 2020
e161727
Addressed PR CSS changes.
revanth0212 Oct 13, 2020
79621d4
Merge branch 'develop' into revanth/my_account_create_list
revanth0212 Oct 13, 2020
25a4af2
Minor.
revanth0212 Oct 13, 2020
78ef7a1
Snapshot update.
revanth0212 Oct 13, 2020
9463645
Merge branch 'develop' into revanth/my_account_create_list
dpatil-magento Oct 13, 2020
dfd7619
Swapping public and private radio buttons.
revanth0212 Oct 14, 2020
2a0d65e
Merge branch 'revanth/my_account_create_list' of https://github.com/m…
revanth0212 Oct 14, 2020
49d67ab
Merge branch 'develop' into revanth/my_account_create_list
dpatil-magento Oct 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions packages/peregrine/lib/talons/WishlistPage/useCreateWishlist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { useState, useCallback } from 'react';

/**
* @function
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why @function js doc ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is part of the new Docs initiate we have started for the code. I modeled this after @jcalcaben's previous PR. @jcalcaben is this as expected?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@larsroettig this is used to help me auto-generate reference docs from the source code

@revanth0212 yes, this looks like the proper format

*
* @returns {CreateWishListProps}
*/
export const useCreateWishlist = () => {
const [isModalOpen, setIsModalOpen] = useState(false);

const showModal = useCallback(() => {
setIsModalOpen(true);
}, []);

const hideModal = useCallback(() => {
setIsModalOpen(false);
}, []);

const createList = useCallback(data => {
// TODO create list mutation is not available yet
// Will be handled in PWA-989
console.log('Creating wish list with data: ', data);
setIsModalOpen(false);
}, []);

return {
createList,
isModalOpen,
hideModal,
showModal
};
};

/**
* JSDoc type definitions
*/

/**
* Props data to use when rendering the Create Wishlist component.
*
* @typedef {Object} CreateWishListProps
*
* @property {Function} createList Callback to be called while creating new list
* @property {Boolean} isModalOpen Boolean which represents if the create modal is open or not
* @property {Function} hideModal Callback to hide the create modal by modifying the value of isModalOpen
* @property {Function} showModal Callback to show the create modal by modifying the value of isModalOpen
*/
19 changes: 19 additions & 0 deletions packages/peregrine/lib/talons/WishlistPage/useWishlist.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { useCallback, useState } from 'react';

/**
* @function
*
* @returns {WishListProps}
*/
export const useWishlist = () => {
const [isOpen, setIsOpen] = useState(true);

Expand All @@ -17,3 +22,17 @@ export const useWishlist = () => {
isOpen
};
};

/**
* JSDoc type definitions
*/

/**
* Props data to use when rendering the Wishlist component.
*
* @typedef {Object} WishListProps
*
* @property {Function} handleActionMenuClick Callback to handle action menu clicks
* @property {Function} handleContentToggle Callback to handle list expand toggle
* @property {Boolean} isOpen Boolean which represents if the content is expanded or not
*/
35 changes: 35 additions & 0 deletions packages/peregrine/lib/talons/WishlistPage/useWishlistItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ import { useMutation } from '@apollo/client';

import { useCartContext } from '../../context/cart';

/**
* @function
*
* @param {String} props.childSku SKU of the child item
* @param {WishlistItemMutations} props.mutations GraphQL mutations for the Wishlist Item component
* @param {String} props.sku SKU of the item
*
* @returns {WishlistItemProps}
*/
export const useWishlistItem = props => {
const { childSku, mutations, sku } = props;
const { addWishlistItemToCartMutation } = mutations;
Expand Down Expand Up @@ -53,3 +62,29 @@ export const useWishlistItem = props => {
isLoading: loading
};
};

/**
* JSDoc type definitions
*/

/**
* GraphQL mutations for the Wishlist Item component
*
* @typedef {Object} WishlistItemMutations
*
* @property {GraphQLAST} addWishlistItemToCartMutation Mutation to add item to the cart
*
* @see [`wishlistItem.gql.js`]{@link https://github.com/magento/pwa-studio/blob/develop/packages/venia-ui/lib/components/WishlistPage/wishlistItem.gql.js}
* for queries used in Venia
*/

/**
* Props data to use when rendering the Wishlist Item component
*
* @typedef {Object} WishlistItemProps
*
* @property {Function} handleAddToCart Callback to handle item addition to cart
* @property {Function} handleMoreActions Callback to handle more actions
* @property {Boolean} hasError Boolean which represents if there were errors during the mutation
* @property {Boolean} isLoading Boolean which represents if data is loading
*/
43 changes: 43 additions & 0 deletions packages/peregrine/lib/talons/WishlistPage/useWishlistPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ import { useQuery } from '@apollo/client';
import { useUserContext } from '../../context/user';
import { useTypePolicies } from '../../hooks/useTypePolicies';

/**
* @function
*
* @param {WishlistQueries} props.queries Wishlist Page queries
* @param {WishlistTypes} props.types Wishlist Page GQL types
*
* @returns {WishlistPageProps}
*/
export const useWishlistPage = props => {
const { queries, types } = props;
const { getCustomerWishlistQuery } = queries;
Expand Down Expand Up @@ -39,3 +47,38 @@ export const useWishlistPage = props => {
wishlists: derivedWishlists
};
};

/**
* JSDoc type definitions
*/

/**
* GraphQL mutations for the Wishlist Page
*
* @typedef {Object} WishlistQueries
*
* @property {GraphQLAST} getCustomerWishlistQuery Query to get customer wish lists
*
* @see [`wishlistPage.gql.js`]{@link https://github.com/magento/pwa-studio/blob/develop/packages/venia-ui/lib/components/WishlistPage/wishlistPage.gql.js}
* for queries used in Venia
*/

/**
* GraphQL types for the Wishlist Page
*
* @typedef {Object} WishlistTypes
*
* @property {Function} Customer.fields.wishlists.read
*
* @see [`wishlistPage.gql.js`]{@link https://github.com/magento/pwa-studio/blob/develop/packages/venia-ui/lib/components/WishlistPage/wishlistPage.gql.js}
* for queries used in Venia
*/

/**
* Props data to use when rendering the Wishlist Item component
*
* @typedef {Object} WishlistPageProps
*
* @property {Map} errors A map of all the GQL query errors
* @property {Object} wishlists List of all customer wishlists
*/
4 changes: 4 additions & 0 deletions packages/venia-ui/lib/components/Dialog/dialog.css
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@
composes: root_highPriority from '../Button/button.css';
}

.cancelButton {
composes: root_lowPriority from '../Button/button.css';
}

/*
* Mobile-specific styles.
*
Expand Down
4 changes: 4 additions & 0 deletions packages/venia-ui/lib/components/Dialog/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ const Dialog = props => {
const confirmButtonDisabled =
shouldDisableAllButtons || shouldDisableConfirmButton;

const cancelButtonClasses = {
root_lowPriority: classes.cancelButton
};
const confirmButtonClasses = {
root_highPriority: classes.confirmButton
};
Expand Down Expand Up @@ -97,6 +100,7 @@ const Dialog = props => {
<div className={classes.contents}>{children}</div>
<div className={classes.buttons}>
<Button
classes={cancelButtonClasses}
disabled={shouldDisableAllButtons}
onClick={onCancel}
priority="low"
Expand Down
Loading