forked from labring/sealos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:desktop support theme (labring#3800)
* feat:desktop support theme Signed-off-by: jingyang <[email protected]> * fix --------- Signed-off-by: jingyang <[email protected]>
- Loading branch information
Showing
25 changed files
with
1,040 additions
and
813 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
73 changes: 73 additions & 0 deletions
73
frontend/desktop/src/components/signin/auth/useAuthList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import useSessionStore from '@/stores/session'; | ||
import { Button, Flex, Image } from '@chakra-ui/react'; | ||
import { MouseEventHandler } from 'react'; | ||
|
||
type useAuthListProps = { | ||
needGithub: boolean; | ||
needWechat: boolean; | ||
wechat_client_id: string; | ||
github_client_id: string; | ||
callback_url: string; | ||
}; | ||
|
||
const useAuthList = ({ | ||
needGithub, | ||
needWechat, | ||
wechat_client_id, | ||
github_client_id, | ||
callback_url | ||
}: useAuthListProps) => { | ||
const { generateState, setProvider } = useSessionStore(); | ||
|
||
const oauthLogin = async ({ url, provider }: { url: string; provider?: 'github' | 'wechat' }) => { | ||
setProvider(provider); | ||
window.location.href = url; | ||
}; | ||
|
||
const authList: { src: string; cb: MouseEventHandler; need: boolean }[] = [ | ||
{ | ||
src: '/images/github.svg', | ||
cb: (e) => { | ||
e.preventDefault(); | ||
const state = generateState(); | ||
oauthLogin({ | ||
provider: 'github', | ||
url: `https://github.com/login/oauth/authorize?client_id=${github_client_id}&redirect_uri=${callback_url}&scope=user:email%20read:user&state=${state}` | ||
}); | ||
}, | ||
need: needGithub | ||
}, | ||
{ | ||
src: '/images/wechat.svg', | ||
cb: (e) => { | ||
e.preventDefault(); | ||
const state = generateState(); | ||
oauthLogin({ | ||
provider: 'wechat', | ||
url: `https://open.weixin.qq.com/connect/qrconnect?appid=${wechat_client_id}&redirect_uri=${callback_url}&response_type=code&state=${state}&scope=snsapi_login&#wechat_redirect` | ||
}); | ||
}, | ||
need: needWechat | ||
} | ||
]; | ||
|
||
const AuthList = () => { | ||
return ( | ||
<Flex gap={'14px'}> | ||
{authList | ||
.filter((item) => item.need) | ||
.map((item, index) => ( | ||
<Button key={index} onClick={item.cb} borderRadius={'full'} variant={'unstyled'}> | ||
<Image src={item.src} borderRadius={'full'} alt={item.src}></Image> | ||
</Button> | ||
))} | ||
</Flex> | ||
); | ||
}; | ||
|
||
return { | ||
AuthList | ||
}; | ||
}; | ||
|
||
export default useAuthList; |
62 changes: 62 additions & 0 deletions
62
frontend/desktop/src/components/signin/auth/useCustomError.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { Flex, Img, Button, Text } from '@chakra-ui/react'; | ||
import React, { useState, useEffect } from 'react'; | ||
import warnIcon from 'public/icons/warning.svg'; | ||
import closeIcon from 'public/icons/close_white.svg'; | ||
import { useTranslation } from 'next-i18next'; | ||
|
||
const useCustomError = () => { | ||
const { t } = useTranslation(); | ||
const [error, setError] = useState(''); | ||
|
||
const showError = (errorMessage: string, duration = 5000) => { | ||
setError(errorMessage); | ||
setTimeout(() => { | ||
setError(''); | ||
}, duration); | ||
}; | ||
|
||
const closeError = () => { | ||
setError(''); | ||
}; | ||
|
||
const ErrorComponent = () => { | ||
useEffect(() => { | ||
if (error) { | ||
const timeout = setTimeout(() => { | ||
closeError(); | ||
}, 5000); // 默认 5000 毫秒(5秒)后自动关闭错误消息 | ||
return () => clearTimeout(timeout); | ||
} | ||
}, [error]); | ||
|
||
return error ? ( | ||
<Flex | ||
position={'absolute'} | ||
top="0" | ||
bg={'rgba(249, 78, 97, 1)'} | ||
transform={'translateY(-50%)'} | ||
width="266px" | ||
minH="42px" | ||
mb="14px" | ||
borderRadius="4px" | ||
p="10px" | ||
> | ||
<Img src={warnIcon.src} mr={'8px'} /> | ||
<Text color={'#fff'}>{t(error)}</Text> | ||
<Button | ||
variant={'unstyled'} | ||
ml={'auto'} | ||
display={'flex'} | ||
justifyContent={'flex-end'} | ||
onClick={closeError} | ||
> | ||
<Img src={closeIcon.src} /> | ||
</Button> | ||
</Flex> | ||
) : null; | ||
}; | ||
|
||
return { showError, ErrorComponent }; | ||
}; | ||
|
||
export default useCustomError; |
34 changes: 34 additions & 0 deletions
34
frontend/desktop/src/components/signin/auth/useLanguage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import LangSelect from '@/components/LangSelect'; | ||
import { Box, Flex, UseDisclosureReturn } from '@chakra-ui/react'; | ||
import { I18n } from 'next-i18next'; | ||
|
||
type LanguageType = { disclosure: UseDisclosureReturn; i18n: I18n | null }; | ||
|
||
const Language = ({ disclosure, i18n }: LanguageType) => { | ||
return ( | ||
<Flex | ||
alignItems={'center'} | ||
position={'absolute'} | ||
top={'42px'} | ||
right={'42px'} | ||
cursor={'pointer'} | ||
gap={'16px'} | ||
> | ||
<Flex | ||
w="36px" | ||
h="36px" | ||
borderRadius={'50%'} | ||
background={'rgba(244, 246, 248, 0.7)'} | ||
justifyContent={'center'} | ||
alignItems={'center'} | ||
position={'relative'} | ||
boxShadow={'0px 1.2px 2.3px rgba(0, 0, 0, 0.2)'} | ||
> | ||
<Box onClick={() => disclosure.onOpen()}>{i18n?.language === 'en' ? 'en' : '中'}</Box> | ||
<LangSelect disclosure={disclosure} i18n={i18n} /> | ||
</Flex> | ||
</Flex> | ||
); | ||
}; | ||
|
||
export default Language; |
Oops, something went wrong.