Skip to content

Commit

Permalink
feat: consume data provided by translation service backend
Browse files Browse the repository at this point in the history
  • Loading branch information
bc-marco authored and BrianJiang2021 committed Sep 28, 2023
1 parent c73d132 commit 1b21f20
Show file tree
Hide file tree
Showing 54 changed files with 695 additions and 481 deletions.
1 change: 1 addition & 0 deletions apps/storefront/.env-example
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
VITE_B2B_URL=http://localhost:9000
VITE_B2B_SOCKET_URL=http://localhost:9000
VITE_TRANSLATION_SERVICE_URL=http://localhost:5000
VITE_STORE_HASH=store_hash
VITE_CATPCHA_SETKEY=captcha_setkey
VITE_B2B_CLIENT_ID=client_id
Expand Down
10 changes: 8 additions & 2 deletions apps/storefront/src/components/B3StoreContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ReactNode, useContext, useLayoutEffect } from 'react'
import { GlobaledContext } from '@/shared/global'
import { getBCStoreChannelId } from '@/shared/service/b2b'
import { setHeadLessBcUrl, store } from '@/store'
import { B3SStorage, storeHash } from '@/utils'
import { B3SStorage, setGlobalTranslation, storeHash } from '@/utils'
import { getCurrentStoreInfo } from '@/utils/loginInfo'

import B3PageMask from './loadding/B3PageMask'
Expand All @@ -22,6 +22,7 @@ interface StoreItem {
b3ChannelId: number
type: string
platform: string
translationVersion: number
}

export interface StoreBasicInfo {
Expand Down Expand Up @@ -52,13 +53,14 @@ export default function B3StoreContainer(props: B3StoreContainerProps) {
storeBasicInfo.multiStorefrontEnabled
)

if (!storeInfo?.channelId) return
if (!storeInfo) return

const {
channelId,
b3ChannelId: b2bChannelId,
b2bEnabled: storeEnabled,
platform,
translationVersion,
} = storeInfo

const bcUrl =
Expand All @@ -84,6 +86,10 @@ export default function B3StoreContainer(props: B3StoreContainerProps) {
showPageMask(dispatch, false)
}

if (translationVersion > 0) {
setGlobalTranslation({ translationVersion, channelId })
}

store.dispatch(setHeadLessBcUrl(bcUrl))
B3SStorage.set('timeFormat', storeBasicInfo.timeFormat)
B3SStorage.set('B3channelId', channelId)
Expand Down
6 changes: 4 additions & 2 deletions apps/storefront/src/components/layout/B3Nav.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useContext } from 'react'
import { useLocation, useNavigate } from 'react-router-dom'
import { useB3Lang } from '@b3/lang'
import {
Badge,
List,
Expand Down Expand Up @@ -29,6 +30,7 @@ export default function B3Nav({ closeSidebar }: B3NavProps) {
const [isMobile] = useMobile()
const navigate = useNavigate()
const location = useLocation()
const b3Lang = useB3Lang()

const { dispatch } = useContext(DynamicallyVariableedContext)

Expand Down Expand Up @@ -170,7 +172,7 @@ export default function B3Nav({ closeSidebar }: B3NavProps) {
onClick={() => handleClick(item)}
selected={activePath(item.path)}
>
<ListItemText primary={item.name} />
<ListItemText primary={b3Lang(item.idLang)} />
</ListItemButton>
</Badge>
</ListItem>
Expand All @@ -182,7 +184,7 @@ export default function B3Nav({ closeSidebar }: B3NavProps) {
onClick={() => handleClick(item)}
selected={activePath(item.path)}
>
<ListItemText primary={item.name} />
<ListItemText primary={b3Lang(item.idLang)} />
</ListItemButton>
</ListItem>
)
Expand Down
11 changes: 8 additions & 3 deletions apps/storefront/src/components/layout/B3RenderRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
import type { OpenPageState } from '@b3/hooks'

import Loading from '@/components/loadding/Loading'
// import { B3Layout, Loading } from '@/components'
import { RegisteredProvider } from '@/pages/registered/context/RegisteredContext'
import { GlobaledContext } from '@/shared/global'
import {
Expand All @@ -25,8 +24,7 @@ import {
RouteFirstLevelItem,
RouteItem,
} from '@/shared/routes/routes'

// import B3LayoutTip from './B3LayoutTip'
import { setTranslation } from '@/utils'

const B3Layout = lazy(() => import('@/components/layout/B3Layout'))

Expand Down Expand Up @@ -60,6 +58,13 @@ export default function B3RenderRouter(props: B3RenderRouterProps) {
}
}, [openUrl])

useEffect(() => {
const [, page] = location.pathname.split('/')
if (!page) return

setTranslation({ channelId: globaledState.currentChannelId, page })
}, [location.pathname])

return (
<Suspense fallback={<Loading />}>
<B3LayoutTip />
Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/pages/dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ function Dashboard(props: DashboardProps) {
borderRadius: '10px',
}}
>
Selected
{b3Lang('dashboard.selected')}
</Box>
)}
</Box>
Expand Down
49 changes: 28 additions & 21 deletions apps/storefront/src/pages/invoice/Invoice.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ReactElement, useContext, useEffect, useRef, useState } from 'react'
import { useLocation, useNavigate } from 'react-router-dom'
import { useB3Lang } from '@b3/lang'
import {
Box,
Button,
Expand Down Expand Up @@ -68,6 +69,7 @@ const initFilter = {

function Invoice() {
const currentDate = new Date().getTime()
const b3Lang = useB3Lang()
const {
state: { role, isAgenting },
} = useContext(GlobaledContext)
Expand Down Expand Up @@ -97,8 +99,9 @@ function Invoice() {
const [filterData, setFilterData] =
useState<Partial<FilterSearchProps> | null>()

const [exportCsvText, setExportCsvText] =
useState<string>('Export all as CSV')
const [exportCsvText, setExportCsvText] = useState<string>(
b3Lang('invoice.exportCsvText')
)

const [filterChangeFlag, setFilterChangeFlag] = useState(false)
const [filterLists, setFilterLists] = useState<InvoiceListNode[]>([])
Expand Down Expand Up @@ -248,7 +251,7 @@ function Invoice() {
const pdfUrl = await handlePrintPDF(id, isPayNow)

if (!pdfUrl) {
snackbar.error('pdf url resolution error')
snackbar.error(b3Lang('invoice.pdfUrlResolutionError'))
return
}

Expand Down Expand Up @@ -483,7 +486,7 @@ function Invoice() {
const columnAllItems: TableColumnItem<InvoiceList>[] = [
{
key: 'id',
title: 'Invoice',
title: b3Lang('invoice.headers.invoice'),
isSortable: true,
render: (item: InvoiceList) => (
<Box
Expand All @@ -505,7 +508,7 @@ function Invoice() {
},
{
key: 'orderNumber',
title: 'Order',
title: b3Lang('invoice.headers.order'),
isSortable: true,
render: (item: InvoiceList) => (
<Box
Expand All @@ -527,15 +530,15 @@ function Invoice() {
},
{
key: 'createdAt',
title: 'Invoice date',
title: b3Lang('invoice.headers.invoiceDate'),
isSortable: true,
render: (item: InvoiceList) =>
`${item.createdAt ? displayFormat(+item.createdAt) : '–'}`,
width: '10%',
},
{
key: 'updatedAt',
title: 'Due date',
title: b3Lang('invoice.headers.dueDate'),
isSortable: true,
render: (item: InvoiceList) => {
const { dueDate, status } = item
Expand All @@ -556,7 +559,7 @@ function Invoice() {
},
{
key: 'originalBalance',
title: 'Invoice total',
title: b3Lang('invoice.headers.invoiceTotal'),
isSortable: true,
render: (item: InvoiceList) => {
const { originalBalance } = item
Expand All @@ -570,7 +573,7 @@ function Invoice() {
},
{
key: 'openBalance',
title: 'Amount due',
title: b3Lang('invoice.headers.amountDue'),
isSortable: true,
render: (item: InvoiceList) => {
const { openBalance } = item
Expand All @@ -584,7 +587,7 @@ function Invoice() {
},
{
key: 'openBalanceToPay',
title: 'Amount to pay',
title: b3Lang('invoice.headers.amountToPay'),
render: (item: InvoiceList) => {
const { openBalance, id } = item
const currentCode = openBalance.code || 'USD'
Expand Down Expand Up @@ -651,7 +654,7 @@ function Invoice() {
},
{
key: 'status',
title: 'Status',
title: b3Lang('invoice.headers.status'),
isSortable: true,
render: (item: InvoiceList) => {
const { status, dueDate } = item
Expand All @@ -667,7 +670,7 @@ function Invoice() {
},
{
key: 'companyName',
title: 'Action',
title: b3Lang('invoice.headers.action'),
render: (row: InvoiceList) => {
const { id } = row
let actionRow = row
Expand Down Expand Up @@ -699,7 +702,7 @@ function Invoice() {
]

useEffect(() => {
let exportCsvTexts = 'Export all as CSV'
let exportCsvTexts = b3Lang('invoice.exportCsvText')

const filtering = filterData ? isFiltering(filterData) : false
const currentCheckedArr = filtering
Expand All @@ -713,13 +716,13 @@ function Invoice() {
if (filtering) {
exportCsvTexts =
currentCheckedArr.length > 0
? 'Export selected as CSV'
: 'Export filtered as CSV'
? b3Lang('invoice.exportSelectedAsCsv')
: b3Lang('invoice.exportFilteredAsCsv')
} else {
exportCsvTexts =
currentCheckedArr.length > 0
? 'Export selected as CSV'
: 'Export all as CSV'
? b3Lang('invoice.exportSelectedAsCsv')
: b3Lang('invoice.exportCsvText')
}

setExportCsvText(exportCsvTexts)
Expand Down Expand Up @@ -749,7 +752,7 @@ function Invoice() {
handleFilterChange={handleFilterChange}
startPicker={{
isEnabled: true,
label: 'From',
label: b3Lang('invoice.filter.from'),
defaultValue:
typeof filterData?.beginDateAt === 'number'
? +filterData.beginDateAt * 1000
Expand All @@ -758,7 +761,7 @@ function Invoice() {
}}
endPicker={{
isEnabled: true,
label: 'To',
label: b3Lang('invoice.filter.to'),
defaultValue:
typeof filterData?.endDateAt === 'number'
? +filterData.endDateAt * 1000
Expand All @@ -781,7 +784,9 @@ function Invoice() {
color: '#000000',
}}
>
{`Open: ${currencyFormat(unpaidAmount)}`}
{b3Lang('invoice.openUnpaid', {
unpaid: currencyFormat(unpaidAmount),
})}
</Typography>
{document.body.clientWidth >= 465 && (
<Typography
Expand All @@ -799,7 +804,9 @@ function Invoice() {
color: '#D32F2F',
}}
>
{`Overdue: ${currencyFormat(overdueAmount)}`}
{b3Lang('invoice.overdueAmount', {
overdue: currencyFormat(overdueAmount),
})}
</Typography>
</Box>
</Box>
Expand Down
14 changes: 8 additions & 6 deletions apps/storefront/src/pages/invoice/InvoiceItemCard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ReactElement } from 'react'
import { useNavigate } from 'react-router-dom'
import { useB3Lang } from '@b3/lang'
import styled from '@emotion/styled'
import {
Box,
Expand Down Expand Up @@ -50,6 +51,7 @@ export function InvoiceItemCard(props: InvoiceItemCardProps) {
handleGetCorrespondingCurrency,
addBottom,
} = props
const b3Lang = useB3Lang()
const navigate = useNavigate()

const { id, status, dueDate, openBalance } = item
Expand All @@ -64,7 +66,7 @@ export function InvoiceItemCard(props: InvoiceItemCardProps) {
const columnAllItems: TableColumnItem<InvoiceList>[] = [
{
key: 'orderNumber',
title: 'Order',
title: b3Lang('invoice.invoiceItemCardHeader.order'),
render: () => (
<Box
sx={{
Expand All @@ -82,12 +84,12 @@ export function InvoiceItemCard(props: InvoiceItemCardProps) {
},
{
key: 'createdAt',
title: 'Invoice date',
title: b3Lang('invoice.invoiceItemCardHeader.invoiceDate'),
render: () => `${item.createdAt ? displayFormat(+item.createdAt) : '–'}`,
},
{
key: 'updatedAt',
title: 'Due date',
title: b3Lang('invoice.invoiceItemCardHeader.dueDate'),
render: () => {
const { dueDate, status } = item
const isOverdue = currentDate > dueDate * 1000 && status !== 2
Expand All @@ -106,7 +108,7 @@ export function InvoiceItemCard(props: InvoiceItemCardProps) {
},
{
key: 'originalBalance',
title: 'Invoice total',
title: b3Lang('invoice.invoiceItemCardHeader.invoiceTotal'),
render: () => {
const { originalBalance } = item
const originalAmount = +originalBalance.value
Expand All @@ -116,7 +118,7 @@ export function InvoiceItemCard(props: InvoiceItemCardProps) {
},
{
key: 'openBalance',
title: 'Amount due',
title: b3Lang('invoice.invoiceItemCardHeader.amountDue'),
render: () => {
const { openBalance } = item

Expand All @@ -127,7 +129,7 @@ export function InvoiceItemCard(props: InvoiceItemCardProps) {
},
{
key: 'openBalanceToPay',
title: 'Amount to pay',
title: b3Lang('invoice.invoiceItemCardHeader.amountToPay'),
render: () => {
const { openBalance, id } = item
let valuePrice = openBalance.value
Expand Down
Loading

0 comments on commit 1b21f20

Please sign in to comment.