Skip to content

Commit

Permalink
perf: styled and environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
kris liu authored and kris liu committed Jul 20, 2022
1 parent f42d458 commit 1187a12
Show file tree
Hide file tree
Showing 21 changed files with 81 additions and 91 deletions.
3 changes: 2 additions & 1 deletion apps/storefront/.env.development
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
NODE_ENV=development
VITE_B2B_BASIC_URL=https://dev-v2.bundleb2b.net
VITE_B2B_BASIC_URL=https://dev-v2.bundleb2b.net
VITE_B2B_STOREHASH='rtmh8fqr05'
2 changes: 0 additions & 2 deletions apps/storefront/.env.production

This file was deleted.

2 changes: 0 additions & 2 deletions apps/storefront/.env.staging

This file was deleted.

1 change: 0 additions & 1 deletion apps/storefront/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"build:staging": "tsc && vite build --mode staging",
"lint": "eslint \"**/*.{ts,tsx}\" --fix",
"preview": "vite preview"
},
Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/components/spin/B3Sping.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
SpinCenter,
SpinTip,
SpinContext,
} from './style'
} from './styled'

interface B3SpingProps {
isSpinning: Boolean | undefined,
Expand Down
6 changes: 6 additions & 0 deletions apps/storefront/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ export const FILE_UPLOAD_ACCEPT_TYPE = [
'text/csv',
'image/*',
]

export const re = {
phone: /^((\(\+?[0-9]{0,2}\))|(\+?[0-9]{0,2}))?(\s|-)?((\([0-9]{1,5}\))|([0-9]{1,5}))((\s|-)?)([0-9]{2,4}){0,3}((\s|-)?)[0-9]{4}$/,
email: /^([A-Za-z0-9.!#$%&'*+-/=?^_`{|}~])+@([A-Za-z0-9\-.])+\.([A-Za-z][A-Za-z0-9]{1,64})$/,
password: /^(?=.*[0-9].*)(?=.*[A-Za-z].*).{7,}$/,
}
17 changes: 5 additions & 12 deletions apps/storefront/src/pages/registered/RegisterComplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
Box,
Alert,
} from '@mui/material'
import styled from '@emotion/styled'
import { useForm } from 'react-hook-form'

import { RegisteredContext } from './context/RegisteredContext'
Expand All @@ -18,9 +17,9 @@ import {
RegisterFileds, CustomFieldItems, Base64, validatorRules,
} from './config'

const InformationFourLabels = styled('h4')(() => ({
marginBottom: '20px',
}))
import { storeHash } from '../../utils'

import { InformationFourLabels, TipContent } from './styled'

interface RegisterCompleteProps {
handleBack: () => void,
Expand All @@ -30,12 +29,6 @@ interface RegisterCompleteProps {

type RegisterCompleteList = Array<any> | undefined

const TipContent = styled('div')(() => ({
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
}))

export default function RegisterComplete(props: RegisterCompleteProps) {
const { handleBack, activeStep, handleNext } = props

Expand Down Expand Up @@ -168,7 +161,7 @@ export default function RegisterComplete(props: RegisterCompleteProps) {
bcFields.addresses = [addresses]

const userItem: any = {
storeHash: (window as any).b3?.setting?.storeHash || 'rtmh8fqr05',
storeHash,
method: 'post',
url: '/v3/customers',
data: [bcFields],
Expand All @@ -181,7 +174,7 @@ export default function RegisterComplete(props: RegisterCompleteProps) {
const b2bFields: any = {}

b2bFields.customerId = customerId || ''
b2bFields.storeHash = (window as any).b3?.setting?.storeHash || 'rtmh8fqr05'
b2bFields.storeHash = storeHash
if (companyInformation) {
companyInformation.forEach((item: any) => {
b2bFields[item.name] = item?.default || ''
Expand Down
3 changes: 1 addition & 2 deletions apps/storefront/src/pages/registered/RegisterContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ import RegisterComplete from './RegisterComplete'

interface RegisterContentProps {
activeStep: number,
handleReset: () => void,
handleBack:() => void,
handleNext: () => void,
}

export default function RegisterContent(props: RegisterContentProps) {
const {
activeStep, handleReset, handleBack, handleNext,
activeStep, handleBack, handleNext,
} = props

const renderStep = (step: number): ReactNode => {
Expand Down
15 changes: 1 addition & 14 deletions apps/storefront/src/pages/registered/Registered.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import {
useEffect, useState, useContext,
} from 'react'

import styled from '@emotion/styled'

import { ImageListItem } from '@mui/material'
import { getBCRegisterCustomFields } from '../../shared/service/bc'
import {
Expand All @@ -28,18 +26,7 @@ import {
addressInformationFields,
} from './config'

const RegisteredContainer = styled('div')({
padding: '20px 20px',
})

const RegisteredImage = styled('div')({
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
width: '100%',
height: '150px',
})
import { RegisteredContainer, RegisteredImage } from './styled'

export default function Registered() {
const [activeStep, setActiveStep] = useState(0)
Expand Down
24 changes: 3 additions & 21 deletions apps/storefront/src/pages/registered/RegisteredAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import {

import { useForm } from 'react-hook-form'

import styled from '@emotion/styled'

import { B3CustomForm } from '../../components'
import RegisteredStepButton from './component/RegisteredStepButton'
import RegisteredSigleCheckBox from './component/RegisteredSigleCheckBox'
Expand All @@ -24,25 +22,9 @@ import { RegisterFileds, CustomFieldItems } from './config'

import { getB2BCompanyUserInfo } from '../../shared/service/b2b'

const InformationLabels = styled('h3')(() => ({
marginBottom: '20px',
}))

const InformationFourLabels = styled('h4')(() => ({
marginBottom: '20px',
}))

const TipContent = styled('div')(() => ({
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
}))

const TipLogin = styled('div')(() => ({
cursor: 'pointer',
color: '#1976d2',
borderBottom: '1px solid #1976d2',
}))
import {
InformationLabels, InformationFourLabels, TipContent, TipLogin,
} from './styled'

interface RegisteredAccountProps {
handleBack: () => void,
Expand Down
20 changes: 2 additions & 18 deletions apps/storefront/src/pages/registered/RegisteredDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
Alert,
} from '@mui/material'

import styled from '@emotion/styled'
import { useForm } from 'react-hook-form'

import { B3CustomForm } from '../../components'
Expand All @@ -27,24 +26,9 @@ import {
Base64,
} from './config'

import { validateBCCompanyExtraFields } from '../../shared/service/b2b'
import { InformationFourLabels, AddressBox, TipContent } from './styled'

const InformationFourLabels = styled('h4')(() => ({
marginBottom: '20px',
}))

const AddressBox = styled(Box)(() => ({
'& .MuiGrid-item': {
alignItems: 'flex-end',
display: 'flex',
},
}))

const TipContent = styled('div')(() => ({
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
}))
import { validateBCCompanyExtraFields } from '../../shared/service/b2b'

export default function RegisteredDetail(props: any) {
const { handleBack, handleNext, activeStep } = props
Expand Down
6 changes: 1 addition & 5 deletions apps/storefront/src/pages/registered/RegisteredFinish.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ import {
Box,
Button,
} from '@mui/material'
import styled from '@emotion/styled'
import { useNavigate } from 'react-router-dom'

import { RegisteredContext } from './context/RegisteredContext'

const StyleTipContainer = styled('p')(() => ({
textAlign: 'center',
margin: '2rem auto',
}))
import { StyleTipContainer } from './styled'

export default function RegisteredFinish() {
const { state, dispatch } = useContext(RegisteredContext)
Expand Down
8 changes: 2 additions & 6 deletions apps/storefront/src/pages/registered/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { re } from '../../constants'

export interface CustomFieldItems {
[key: string]: any
}
Expand Down Expand Up @@ -29,12 +31,6 @@ export type ContactInformationItems = Array<RegisterFileds>

export const steps = ['Account', 'Details', 'Finish']

export const re = {
phone: /^((\(\+?[0-9]{0,2}\))|(\+?[0-9]{0,2}))?(\s|-)?((\([0-9]{1,5}\))|([0-9]{1,5}))((\s|-)?)([0-9]{2,4}){0,3}((\s|-)?)[0-9]{4}$/,
email: /^([A-Za-z0-9.!#$%&'*+-/=?^_`{|}~])+@([A-Za-z0-9\-.])+\.([A-Za-z][A-Za-z0-9]{1,64})$/,
password: /^(?=.*[0-9].*)(?=.*[A-Za-z].*).{7,}$/,
}

const companyExtraFieldsType = ['text', 'multiline', 'number', 'dropdown']

export const Base64 = {
Expand Down
46 changes: 46 additions & 0 deletions apps/storefront/src/pages/registered/styled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import styled from '@emotion/styled'

export const StyleTipContainer = styled('p')(() => ({
textAlign: 'center',
margin: '2rem auto',
}))

export const InformationLabels = styled('h3')(() => ({
marginBottom: '20px',
}))

export const InformationFourLabels = styled('h4')(() => ({
marginBottom: '20px',
}))

export const AddressBox = styled('div')(() => ({
'& .MuiGrid-item': {
alignItems: 'flex-end',
display: 'flex',
},
}))

export const TipContent = styled('div')(() => ({
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
}))

export const TipLogin = styled('div')(() => ({
cursor: 'pointer',
color: '#1976d2',
borderBottom: '1px solid #1976d2',
}))

export const RegisteredContainer = styled('div')({
padding: '20px 20px',
})

export const RegisteredImage = styled('div')({
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
width: '100%',
height: '150px',
})
4 changes: 1 addition & 3 deletions apps/storefront/src/shared/service/b2b/graphql/register.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { B3Request } from '../../request/b3Fetch'

import {
convertArrayToGraphql,
convertArrayToGraphql, storeHash,
} from '../../../../utils'

interface CustomFieldItems {
[key: string]: any
}

const storeHash = (window as any).b3?.setting?.storeHash || 'rtmh8fqr05'

const getCompanyExtraFields = () => `{
companyExtraFields(storeHash: "${storeHash}") {
fieldName,
Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/shared/service/request/base.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const B2B_BASIC_URL = import.meta.env.VITE_B2B_BASIC_URL
const B2B_BASIC_URL = (window as any).b3?.setting?.B2B_URL || import.meta.env.VITE_B2B_BASIC_URL

enum RequestType {
B2BGraphql = 'B2BGraphql',
Expand Down
5 changes: 5 additions & 0 deletions apps/storefront/src/utils/basicConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const storeHash = (window as any).b3?.setting.storeHash || import.meta.env.VITE_B2B_STOREHASH

export {
storeHash,
}
3 changes: 3 additions & 0 deletions apps/storefront/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import {
convertObjectToGraphql,
} from './graphqlDataConvert'

import { storeHash } from './basicConfig'

export {
convertArrayToGraphql,
convertObjectToGraphql,
storeHash,
}
2 changes: 1 addition & 1 deletion apps/storefront/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"exclude": ["node_modules"],
"extends": "@b3/tsconfig/vite.json",
"compilerOptions": {
"outDir": "dist",
"outDir": "dist"
},
"include": ["src"]
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
],
"scripts": {
"build": "turbo run build",
"build:staging": "turbo run build:staging",
"dev": "turbo run dev --parallel",
"lint": "turbo run lint",
"prepare": "husky install"
Expand Down

0 comments on commit 1187a12

Please sign in to comment.