Skip to content

Commit

Permalink
Merge pull request #172 from vtex-apps/feature/pii
Browse files Browse the repository at this point in the history
Feature/pii
  • Loading branch information
beatrizmaselli authored Apr 18, 2024
2 parents 59f00c6 + a83c84d commit 43b624e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
6 changes: 6 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,12 @@ To apply CSS customizations to this and other blocks, follow the instructions in
| `wishlistIconContainer` |
| `emptyMessage` |

## PII Compliance

This app can be used in a Personal Identifiable Information (PII) compliant account. In this case, shopperId is the Profile ID.

**Note**: If you are changing type of the account from regular to PII, you must replace the email values with profile ID values in the WishList data entity!

<!-- DOCS-IGNORE:start -->

## Contributors ✨
Expand Down
14 changes: 10 additions & 4 deletions react/AddProductBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React, {
useEffect,
SyntheticEvent,
} from 'react'
import { useMutation, useLazyQuery } from 'react-apollo'
import { useMutation, useLazyQuery, useQuery } from 'react-apollo'
import { defineMessages, useIntl } from 'react-intl'
import { ProductContext } from 'vtex.product-context'
import { Button, ToastContext } from 'vtex.styleguide'
Expand All @@ -18,6 +18,7 @@ import { getSession } from './modules/session'
import storageFactory from './utils/storage'
import checkItem from './queries/checkItem.gql'
import addToList from './queries/addToList.gql'
import profile from './queries/profile.gql'
import removeFromList from './queries/removeFromList.gql'
import styles from './styles.css'

Expand Down Expand Up @@ -152,10 +153,13 @@ const AddBtn: FC<AddBtnProps> = ({ toastURL = '/account/#wishlist' }) => {
const { navigate, history, route, account } = useRuntime()
const { push } = usePixel()
const handles = useCssHandles(CSS_HANDLES)
const { showToast } = useContext(ToastContext)
const { showToast } = useContext(ToastContext) as any

Check warning on line 156 in react/AddProductBtn.tsx

View workflow job for this annotation

GitHub Actions / QE / Lint Node.js

Unexpected any. Specify a different type
const { selectedItem, product } = useContext(ProductContext) as any
const sessionResponse: any = useSessionResponse()
const [handleCheck, { data, loading, called }] = useLazyQuery(checkItem)
const { data: profileData } = useQuery(profile, {
ssr: false

Check failure on line 161 in react/AddProductBtn.tsx

View workflow job for this annotation

GitHub Actions / QE / Lint Node.js

Insert `,`
})

const [productId] = String(product?.productId).split('-')
const sku = product?.sku?.itemId
Expand Down Expand Up @@ -215,7 +219,8 @@ const AddBtn: FC<AddBtnProps> = ({ toastURL = '/account/#wishlist' }) => {
if (sessionResponse) {
isAuthenticated =
sessionResponse?.namespaces?.profile?.isAuthenticated?.value === 'true'
shopperId = sessionResponse?.namespaces?.profile?.email?.value ?? null

shopperId = !profileData?.profile?.pii? sessionResponse?.namespaces?.profile?.email?.value : sessionResponse?.namespaces?.profile?.id?.value?? null

Check failure on line 223 in react/AddProductBtn.tsx

View workflow job for this annotation

GitHub Actions / QE / Lint Node.js

Replace `?·sessionResponse?.namespaces?.profile?.email?.value·:·sessionResponse?.namespaces?.profile?.id?.value` with `⏎······?·sessionResponse?.namespaces?.profile?.email?.value⏎······:·sessionResponse?.namespaces?.profile?.id?.value·`

localStore.setItem(
'wishlist_isAuthenticated',
Expand Down Expand Up @@ -353,7 +358,8 @@ const AddBtn: FC<AddBtnProps> = ({ toastURL = '/account/#wishlist' }) => {
}

if (
data?.checkList?.inList !== true &&
data?.checkList &&
data.checkList.inList !== true &&
productCheck[productId] === undefined &&
wishListed.find(
(item: any) => item.productId === productId && item.sku === sku
Expand Down
14 changes: 12 additions & 2 deletions react/ProductSummaryWishlist.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useMemo, useState, useEffect, FC } from 'react'
import { useLazyQuery } from 'react-apollo'
import { useLazyQuery, useQuery } from 'react-apollo'
// @ts-expect-error - useTreePath is a private API
import { ExtensionPoint, useRuntime, useTreePath } from 'vtex.render-runtime'
import { useListContext, ListContextProvider } from 'vtex.list-context'
Expand All @@ -14,6 +14,7 @@ import productsQuery from './queries/productById.gql'
import ViewLists from './queries/viewLists.gql'
import { getSession } from './modules/session'
import storageFactory from './utils/storage'
import profile from './queries/profile.gql'

const localStore = storageFactory(() => sessionStorage)

Expand Down Expand Up @@ -73,11 +74,20 @@ const ProductSummaryList: FC<ProductSummaryProps> = ({
fetchPolicy: 'network-only',
}
)
const { data: profileData } = useQuery(profile, {
ssr: false

Check failure on line 78 in react/ProductSummaryWishlist.tsx

View workflow job for this annotation

GitHub Actions / QE / Lint Node.js

Insert `,`
})

if (sessionResponse) {
isAuthenticated =
sessionResponse?.namespaces?.profile?.isAuthenticated?.value === 'true'
shopperId = sessionResponse?.namespaces?.profile?.email?.value ?? null

if (profileData) {
shopperId = profileData.profile.pii? sessionResponse?.namespaces?.profile?.id?.value : sessionResponse?.namespaces?.profile?.email?.value

Check failure on line 86 in react/ProductSummaryWishlist.tsx

View workflow job for this annotation

GitHub Actions / QE / Lint Node.js

Replace `?·sessionResponse?.namespaces?.profile?.id?.value` with `⏎········?·sessionResponse?.namespaces?.profile?.id?.value⏎·······`
}

Check failure on line 87 in react/ProductSummaryWishlist.tsx

View workflow job for this annotation

GitHub Actions / QE / Lint Node.js

Delete `⏎···`
else {
shopperId = null
}

localStore.setItem(
'wishlist_isAuthenticated',
Expand Down
6 changes: 2 additions & 4 deletions react/WishlistAdmin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ const WishlistAdmin: FC<any> = ({ intl }) => {
const { loading } = state

const downloadWishlist = (allWishlists: any) => {
const header = ['Email', 'Product ID', 'SKU', 'Title']
const header = ['Shopper ID', 'Product ID', 'SKU', 'Title']
const data: any = []

for (const shopper of allWishlists) {
const wishlists = shopper.listItemsWrapper
for (const wishlist of wishlists) {
for (const wishlistItem of wishlist.listItems) {
const shopperData = {
Email: shopper.email,
'Shopper ID': shopper.email,
'Product ID': wishlistItem.productId,
SKU: wishlistItem.sku,
Title: wishlistItem.title,
Expand Down Expand Up @@ -108,7 +108,6 @@ const WishlistAdmin: FC<any> = ({ intl }) => {

const GetAllWishlists = async () => {
setState({ ...state, loading: true })
console.log(loading)

if (!queryLoading) {
const parsedData = data?.exportList
Expand Down Expand Up @@ -152,7 +151,6 @@ const WishlistAdmin: FC<any> = ({ intl }) => {
options={options}
value={selected1}
onChange={(event: any) => {
console.log(event.target.value)
setSelected1(event.target.value)
setTimeout(()=>{refetch()},500)

Expand Down
5 changes: 5 additions & 0 deletions react/queries/profile.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
query Profile {
profile @context(provider: "vtex.store-graphql") {
pii
}
}

0 comments on commit 43b624e

Please sign in to comment.