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

Not found SKUs message logic added #124

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion messages/context.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,8 @@
"store/affiliate.register.errorURLInUse": "Affiliate url is already in use",
"store/affiliate.register.errorAffiliateExists": "Affiliate already exists, email is already in use",
"store/affiliate.register.errorAffiliateNotFound": "Affiliate not found, there is no affiliate with this email",
"store/affiliate.register.errorEmailAlreadyInUse": "The email is already being used by some other affiliate"
"store/affiliate.register.errorEmailAlreadyInUse": "The email is already being used by some other affiliate",
"admin/affiliate.commissionWarning": "The last spreadsheet has SKUs not found in the store, this will not cancel the process, it will just not add the specific not found value",
"admin/affiliate.commissionSuccess": "All spreadsheet SKUs that have been verified so far have been found in the store",
"admin/affiliate.verifySKUs": "Verify SKUs"
}
5 changes: 4 additions & 1 deletion messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,8 @@
"store/affiliate.register.errorURLInUse": "Affiliate url is already in use",
"store/affiliate.register.errorAffiliateExists": "Affiliate already exists, email is already in use",
"store/affiliate.register.errorAffiliateNotFound": "Affiliate not found, there is no affiliate with this email",
"store/affiliate.register.errorEmailAlreadyInUse": "The email is already being used by some other affiliate"
"store/affiliate.register.errorEmailAlreadyInUse": "The email is already being used by some other affiliate",
"admin/affiliate.commissionWarning": "The last spreadsheet has SKUs not found in the store, this will not cancel the process, it will just not add the specific not found value",
"admin/affiliate.commissionSuccess": "All spreadsheet SKUs that have been verified so far have been found in the store",
"admin/affiliate.verifySKUs": "Verify SKUs"
}
5 changes: 4 additions & 1 deletion messages/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,8 @@
"store/affiliate.register.errorURLInUse": "Essa URL de Afiliado já está em uso",
"store/affiliate.register.errorAffiliateExists": "O Afiliado já existe, esse email já está em uso",
"store/affiliate.register.errorAffiliateNotFound": "Afiliado não encontrado, esse email não está sendo usado por nenhum afiliado",
"store/affiliate.register.errorEmailAlreadyInUse": "Esse email já está em uso por outro afiliado"
"store/affiliate.register.errorEmailAlreadyInUse": "Esse email já está em uso por outro afiliado",
"admin/affiliate.commissionWarning": "A última planilha possui SKUs não encontrados na loja, isso não cancelará o processo, apenas não adicionará o valor específico não encontrado",
"admin/affiliate.commissionSuccess": "Todos os SKUs da planilha que foram verificados até agora foram encontrados na loja",
"admin/affiliate.verifySKUs": "Verificar SKUs"
}
30 changes: 30 additions & 0 deletions react/components/admin/commissions/CommissionsNotFound.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react'
import { Alert } from '@vtex/admin-ui'
import { useIntl } from 'react-intl'

import { messages } from '../../../utils/messages'

interface CommissionsNotFoundProps {
notFound: boolean
}

function CommissionsNotFound(props: CommissionsNotFoundProps) {
const { notFound } = props
const intl = useIntl()

return (
<>
{notFound === true ? (
<Alert variant="warning">
{intl.formatMessage(messages.affiliateCommissionWarning)}
</Alert>
) : (
<Alert variant="positive">
{intl.formatMessage(messages.affiliateCommissionSuccess)}
</Alert>
)}
</>
)
Comment on lines +15 to +27
Copy link
Contributor

Choose a reason for hiding this comment

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

Use prevent return in this case I think it's a better idea.

Suggested change
return (
<>
{notFound === true ? (
<Alert variant="warning">
{intl.formatMessage(messages.affiliateCommissionWarning)}
</Alert>
) : (
<Alert variant="positive">
{intl.formatMessage(messages.affiliateCommissionSuccess)}
</Alert>
)}
</>
)
if (notFound) {
return (
<Alert variant="warning">
{intl.formatMessage(messages.affiliateCommissionWarning)}
</Alert>
)
}
return (
<Alert variant="positive">
{intl.formatMessage(messages.affiliateCommissionSuccess)}
</Alert>
)

}

export default CommissionsNotFound
52 changes: 44 additions & 8 deletions react/components/admin/commissions/ImportDropzone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,37 @@ import React, { useCallback, useState, useMemo } from 'react'
import { useIntl } from 'react-intl'
import { Dropzone } from 'vtex.styleguide'
import { Text, Box, Button, Flex, useToast } from '@vtex/admin-ui'
import { useMutation } from 'react-apollo'
import { useMutation, useLazyQuery } from 'react-apollo'
import * as XLSX from 'xlsx'

import CommissionsNotFound from './CommissionsNotFound'
import { messages } from '../../../utils/messages'
import IMPORT_COMMISSIONS from '../../../graphql/importCommissionsBySKU.graphql'
import GET_LAST_IMPORTED_COMMISSION_FILE_INFO from '../../../graphql/getLastImportInfo.graphql'
import GET_NOT_FOUND_SKUS from '../../../graphql/getNotFoundSKUs.graphql'
import DELETE_NOT_FOUND_SKUS from '../../../graphql/deleteNotFoundSKUs.graphql'

interface NotFoundInterface {
getNotFoundCommissions: boolean | undefined
}

const ImportDropzone: FC = () => {
const intl = useIntl()
const showToast = useToast()
const [file, setFile] = useState<File>()
const [verifyDisabled, setVerifyDisabled] = useState(true)

const [getNotFoundSKUs, { data: dataSKUs }] = useLazyQuery<NotFoundInterface>(
GET_NOT_FOUND_SKUS,
{
notifyOnNetworkStatusChange: true,
fetchPolicy: 'network-only',
}
)

const [deleteNotFoundSKUs] = useMutation(DELETE_NOT_FOUND_SKUS, {
notifyOnNetworkStatusChange: true,
})

const [importData, { loading: importLoading }] = useMutation(
IMPORT_COMMISSIONS,
Expand All @@ -25,6 +45,8 @@ const ImportDropzone: FC = () => {
],
awaitRefetchQueries: true,
onCompleted: () => {
setVerifyDisabled(false)
deleteNotFoundSKUs()
showToast({
variant: 'positive',
message: intl.formatMessage(messages.importFileSuccessMessage),
Expand Down Expand Up @@ -108,14 +130,28 @@ const ImportDropzone: FC = () => {
</div>
</Dropzone>
<Flex justify="flex-end" csx={{ marginY: '8px' }}>
<Button
disabled={isButtonDisabled}
loading={importLoading}
onClick={handleSubmit}
>
{intl.formatMessage(messages.sendFileLabel)}
</Button>
<div className="flex flex-column ">
<Button
className="mt2"
disabled={isButtonDisabled}
loading={importLoading}
onClick={handleSubmit}
>
{intl.formatMessage(messages.sendFileLabel)}
</Button>
<Button
variant="secondary"
className="mt2"
disabled={verifyDisabled}
onClick={() => getNotFoundSKUs()}
>
{intl.formatMessage(messages.affiliateVerifySKUs)}
</Button>
</div>
</Flex>
{dataSKUs?.getNotFoundCommissions !== undefined ? (
<CommissionsNotFound notFound={dataSKUs.getNotFoundCommissions} />
) : null}
Comment on lines +152 to +154
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
{dataSKUs?.getNotFoundCommissions !== undefined ? (
<CommissionsNotFound notFound={dataSKUs.getNotFoundCommissions} />
) : null}
{dataSKUs?.getNotFoundCommissions && <CommissionsNotFound notFound={dataSKUs.getNotFoundCommissions} />}

</>
)
}
Expand Down
3 changes: 3 additions & 0 deletions react/graphql/deleteNotFoundSKUs.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mutation setNotFound {
deleteNotFounds
}
3 changes: 3 additions & 0 deletions react/graphql/getNotFoundSKUs.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
query getNotFoundSKUs {
getNotFoundCommissions
}
9 changes: 9 additions & 0 deletions react/utils/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ export const messages = defineMessages({
},
noLastFileLabel: { id: 'admin/import.no.last.file.label' },
editAffiliateApproveStatusTitle: { id: 'admin/edit.affiliate.approve.title' },
affiliateCommissionWarning: {
id: 'admin/affiliate.commissionWarning',
},
affiliateCommissionSuccess: {
id: 'admin/affiliate.commissionSuccess',
},
affiliateVerifySKUs: {
id: 'admin/affiliate.verifySKUs',
},
})

export const storeMessages = defineMessages({
Expand Down