Skip to content

Commit

Permalink
4.8.16 test (#3437)
Browse files Browse the repository at this point in the history
* perf: auto login code

* perf: invoice phone
  • Loading branch information
c121914yu authored Dec 19, 2024
1 parent 1f4e5f6 commit a997f27
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 108 deletions.
1 change: 1 addition & 0 deletions packages/web/i18n/en/account_bill.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"support_wallet_bill_tag_invoice": "bill invoice",
"support_wallet_invoicing": "Invoicing",
"time": "time",
"total_amount": "lump sum",
"type": "type",
"unit_code": "unified credit code",
"unit_code_void": "Unified credit code format error",
Expand Down
5 changes: 3 additions & 2 deletions packages/web/i18n/zh-CN/account_bill.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"company_phone": "公司电话",
"completed": "已完成",
"confirm": "确认",
"default_header": "默认抬头",
"detail": "详情",
"contact_phone": "联系电话",
"contact_phone_void": "联系电话格式错误",
"default_header": "默认抬头",
"detail": "详情",
"email_address": "邮箱地址",
"extra_ai_points": "额外 AI 积分",
"extra_dataset_size": "额外知识库容量",
Expand Down Expand Up @@ -45,6 +45,7 @@
"support_wallet_bill_tag_invoice": "账单发票",
"support_wallet_invoicing": "开票",
"time": "时间",
"total_amount": "总金额",
"type": "类型",
"unit_code": "统一信用代码",
"unit_code_void": "统一信用代码格式错误",
Expand Down
1 change: 1 addition & 0 deletions packages/web/i18n/zh-Hant/account_bill.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"support_wallet_bill_tag_invoice": "帳單發票",
"support_wallet_invoicing": "開票",
"time": "時間",
"total_amount": "總金額",
"type": "類型",
"unit_code": "統一信用代碼",
"unit_code_void": "統一信用代碼格式錯誤",
Expand Down
125 changes: 64 additions & 61 deletions projects/app/src/pages/account/bill/components/ApplyInvoiceModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
Button,
Checkbox,
Flex,
ModalBody,
ModalFooter,
Table,
TableContainer,
Tbody,
Expand Down Expand Up @@ -118,19 +120,69 @@ const ApplyInvoiceModal = ({ onClose }: { onClose: () => void }) => {
isOpen={true}
isCentered
iconSrc="/imgs/modal/invoice.svg"
minHeight={isOpenSettleModal ? '46.4rem' : '42.25rem'}
w={'43rem'}
onClose={onClose}
isLoading={isLoading}
title={t('account_bill:support_wallet_apply_invoice')}
>
{!isOpenSettleModal ? (
<Box px={['1.6rem', '3.25rem']} py={['1rem', '2rem']}>
<Box fontWeight={500} fontSize={'1rem'} pb={'0.75rem'}>
{t('account_bill:support_wallet_apply_invoice')}
</Box>
<Box h={'27.9rem'} overflow={'auto'}>
<TableContainer>
{isOpenSettleModal ? (
<>
<ModalBody>
<Box w={'100%'} fontSize={'0.875rem'}>
<Flex w={'100%'} justifyContent={'space-between'}>
<Box>{t('account_bill:total_amount')}</Box>
<Box>{t('account_bill:yuan', { amount: formatStorePrice2Read(totalPrice) })}</Box>
</Flex>
<Box w={'100%'} py={4}>
<Divider showBorderBottom={false} />
</Box>
</Box>
<MyBox isLoading={isLoadingHeader}>
<Flex justify={'center'}>
<InvoiceHeaderSingleForm inputForm={inputForm} required />
</Flex>
</MyBox>
<Flex
align={'center'}
w={'19.8rem'}
h={'1.75rem'}
mt={4}
px={'0.75rem'}
py={'0.38rem'}
bg={'blue.50'}
borderRadius={'sm'}
color={'blue.600'}
>
<MyIcon name="infoRounded" w={'14px'} h={'14px'} />
<Box ml={2} fontSize={'0.6875rem'}>
{t('account_bill:invoice_sending_info')}
</Box>
</Flex>
</ModalBody>
<ModalFooter>
<Button variant={'outline'} mr={'0.75rem'} px="0" onClick={handleBack}>
<Flex alignItems={'center'}>
<Box px={'1.25rem'} py={'0.5rem'}>
{t('account_bill:back')}
</Box>
</Flex>
</Button>
<Button isLoading={isSubmitting} px="0" onClick={inputForm.handleSubmit(onSubmitApply)}>
<Flex alignItems={'center'}>
<Box px={'1.25rem'} py={'0.5rem'}>
{t('account_bill:confirm')}
</Box>
</Flex>
</Button>
</ModalFooter>
</>
) : (
<>
<ModalBody>
<Box fontWeight={500} fontSize={'1rem'} pb={'0.75rem'}>
{t('account_bill:support_wallet_apply_invoice')}
</Box>
<TableContainer minH={'50vh'}>
<Table>
<Thead>
<Tr>
Expand Down Expand Up @@ -202,8 +254,8 @@ const ApplyInvoiceModal = ({ onClose }: { onClose: () => void }) => {
</Flex>
)}
</TableContainer>
</Box>
<Flex pt={'2.5rem'} justify={'flex-end'}>
</ModalBody>
<ModalFooter>
<Button
variant={'primary'}
px="0"
Expand All @@ -221,57 +273,8 @@ const ApplyInvoiceModal = ({ onClose }: { onClose: () => void }) => {
</Box>
</Flex>
</Button>
</Flex>
</Box>
) : (
<Box px={['1.6rem', '3.25rem']} py={['1rem', '2rem']}>
<Box w={'100%'} fontSize={'0.875rem'}>
<Flex w={'100%'} justifyContent={'space-between'}>
<Box>{t('account_bill:support_wallet_amount')}</Box>
<Box>{t('account_bill:yuan', { amount: formatStorePrice2Read(totalPrice) })}</Box>
</Flex>
<Box w={'100%'} py={4}>
<Divider showBorderBottom={false} />
</Box>
</Box>
<MyBox isLoading={isLoadingHeader}>
<Flex justify={'center'}>
<InvoiceHeaderSingleForm inputForm={inputForm} required />
</Flex>
</MyBox>
<Flex
align={'center'}
w={'19.8rem'}
h={'1.75rem'}
mt={4}
px={'0.75rem'}
py={'0.38rem'}
bg={'blue.50'}
borderRadius={'sm'}
color={'blue.600'}
>
<MyIcon name="infoRounded" w={'14px'} h={'14px'} />
<Box ml={2} fontSize={'0.6875rem'}>
{t('account_bill:invoice_sending_info')}
</Box>
</Flex>
<Flex justify={'flex-end'} w={'100%'} pt={[3, 7]}>
<Button variant={'outline'} mr={'0.75rem'} px="0" onClick={handleBack}>
<Flex alignItems={'center'}>
<Box px={'1.25rem'} py={'0.5rem'}>
{t('account_bill:back')}
</Box>
</Flex>
</Button>
<Button isLoading={isSubmitting} px="0" onClick={inputForm.handleSubmit(onSubmitApply)}>
<Flex alignItems={'center'}>
<Box px={'1.25rem'} py={'0.5rem'}>
{t('account_bill:confirm')}
</Box>
</Flex>
</Button>
</Flex>
</Box>
</ModalFooter>
</>
)}
</MyModal>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ export const InvoiceHeaderSingleForm = ({
{...styles}
placeholder={t('account_bill:unit_code')}
{...register('unifiedCreditCode', {
required,
pattern: { value: /^[A-Z0-9]{18}$/, message: t('account_bill:unit_code_void') }
required
})}
/>
</Flex>
Expand Down Expand Up @@ -157,8 +156,7 @@ export const InvoiceHeaderSingleForm = ({
{...register('contactPhone', {
required,
pattern: {
value:
/^(?:\+?\d{1,3}[- ]?)?(?:\(\d{1,4}\)|\d{1,4})?[- ]?\d{1,4}[- ]?\d{1,4}[- ]?\d{1,9}$/,
value: /^[1]{1}[0-9]{10}$/,
message: t('account_bill:contact_phone_void')
}
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { OAuthEnum } from '@fastgpt/global/support/user/constant';
import MyIcon from '@fastgpt/web/components/common/Icon';
import { customAlphabet } from 'nanoid';
import { useRouter } from 'next/router';
import { Dispatch, useEffect, useMemo, useRef } from 'react';
import { Dispatch, useCallback, useEffect, useMemo, useRef } from 'react';
import { useTranslation } from 'next-i18next';
import I18nLngSelector from '@/components/Select/I18nLngSelector';
import { useSystem } from '@fastgpt/web/hooks/useSystem';
Expand All @@ -23,7 +23,6 @@ interface Props {
const FormLayout = ({ children, setPageType, pageType }: Props) => {
const { t } = useTranslation();
const router = useRouter();
const { toast } = useToast();

const { setLoginStore, feConfigs } = useSystemStore();
const { lastRoute = '/app/list' } = router.query as { lastRoute: string };
Expand Down Expand Up @@ -100,25 +99,23 @@ const FormLayout = ({ children, setPageType, pageType }: Props) => {
[feConfigs?.sso?.url, oAuthList.length]
);

const formatUrl = useMemo(() => {
if (feConfigs?.sso?.url) {
return `${feConfigs.sso.url}/login/oauth/authorize?redirect_uri=${encodeURIComponent(redirectUri)}&state=${state.current}`;
}
return '';
}, [feConfigs.sso, redirectUri]);
const onClickSso = useCallback(() => {
if (!feConfigs?.sso?.url) return;
setLoginStore({
provider: OAuthEnum.sso,
lastRoute,
state: state.current
});
const url = `${feConfigs.sso.url}/login/oauth/authorize?redirect_uri=${encodeURIComponent(redirectUri)}&state=${state.current}`;

useEffect(() => {
if (formatUrl && feConfigs?.sso?.autoLogin) {
setLoginStore({
provider: OAuthEnum.sso,
lastRoute,
state: state.current
});
window.open(url, '_self');
}, [feConfigs?.sso?.url, lastRoute, redirectUri, setLoginStore]);

window.open(formatUrl, '_self');
useEffect(() => {
if (feConfigs?.sso?.autoLogin) {
onClickSso();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [feConfigs.sso]);
}, [feConfigs?.sso?.autoLogin]);

return (
<Flex flexDirection={'column'} h={'100%'}>
Expand Down Expand Up @@ -186,22 +183,7 @@ const FormLayout = ({ children, setPageType, pageType }: Props) => {
h={'40px'}
borderRadius={'sm'}
leftIcon={<MyImage alt="" src={feConfigs.sso.icon as any} w="20px" />}
onClick={() => {
if (!formatUrl) {
toast({
title: 'SSO URL is not set',
status: 'error'
});
return;
}
setLoginStore({
provider: OAuthEnum.sso,
lastRoute,
state: state.current
});

window.open(formatUrl, '_self');
}}
onClick={onClickSso}
>
{feConfigs.sso.title}
</Button>
Expand Down
13 changes: 7 additions & 6 deletions projects/app/src/pages/login/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useCallback, useEffect } from 'react';
import React, { useState, useCallback, useEffect, useMemo } from 'react';
import {
Box,
Button,
Expand Down Expand Up @@ -73,18 +73,19 @@ const Login = ({ ChineseRedirectUrl }: { ChineseRedirectUrl: string }) => {
[lastRoute, router, setUserInfo]
);

function DynamicComponent({ type }: { type: `${LoginPageTypeEnum}` }) {
const DynamicComponent = useMemo(() => {
const TypeMap = {
[LoginPageTypeEnum.passwordLogin]: LoginForm,
[LoginPageTypeEnum.register]: RegisterForm,
[LoginPageTypeEnum.forgetPassword]: ForgetPasswordForm,
[LoginPageTypeEnum.wechat]: WechatForm
};

const Component = TypeMap[type];
// @ts-ignore
const Component = TypeMap[pageType];

return <Component setPageType={setPageType} loginSuccess={loginSuccess} />;
}
}, [pageType, loginSuccess]);

/* default login type */
useEffect(() => {
Expand All @@ -99,7 +100,7 @@ const Login = ({ ChineseRedirectUrl }: { ChineseRedirectUrl: string }) => {

// init store
setLastChatAppId('');
}, [feConfigs.oauth]);
}, [feConfigs?.oauth, setLastChatAppId]);

const {
isOpen: isOpenRedirect,
Expand Down Expand Up @@ -171,7 +172,7 @@ const Login = ({ ChineseRedirectUrl }: { ChineseRedirectUrl: string }) => {
>
<Box w={['100%', '380px']} flex={'1 0 0'}>
{pageType ? (
<DynamicComponent type={pageType} />
DynamicComponent
) : (
<Center w={'full'} h={'full'} position={'relative'}>
<Loading fixed={false} />
Expand Down
2 changes: 1 addition & 1 deletion projects/app/src/web/context/useInitApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const useInitApp = () => {
if (sourceDomain) return sourceDomain;
return document.referrer;
})();

console.log(formatSourceDomain, '-=-=');
if (formatSourceDomain && !sessionStorage.getItem('sourceDomain')) {
sessionStorage.setItem('sourceDomain', formatSourceDomain);
}
Expand Down

0 comments on commit a997f27

Please sign in to comment.