|
1 |
| -import React from 'react'; |
| 1 | +import React, { useEffect } from 'react'; |
2 | 2 |
|
3 | 3 | import { Box, Button, Stack, Text } from '@chakra-ui/react';
|
4 | 4 | import { signIn } from 'next-auth/react';
|
5 | 5 | import { useTranslation } from 'react-i18next';
|
6 |
| -import { FiGithub, FiInfo } from 'react-icons/fi'; |
| 6 | +import { FiGithub, FiGitlab, FiInfo } from 'react-icons/fi'; |
7 | 7 |
|
8 | 8 | import { Icon } from '@/components';
|
9 | 9 |
|
10 |
| -export const LoginForm = ({ onSuccess = () => undefined, ...rest }: TODO) => { |
| 10 | +export const LoginForm = ({ |
| 11 | + onSuccess = () => undefined, |
| 12 | + provider, |
| 13 | + ...rest |
| 14 | +}: TODO) => { |
11 | 15 | const { t } = useTranslation();
|
| 16 | + useEffect(() => { |
| 17 | + if (provider === undefined) { |
| 18 | + provider = 'github'; |
| 19 | + } |
| 20 | + }, []); |
12 | 21 |
|
13 | 22 | return (
|
14 |
| - <Stack {...rest}> |
15 |
| - <Button |
16 |
| - w="full" |
17 |
| - colorScheme="github" |
18 |
| - bg="github.800" |
19 |
| - color="white" |
20 |
| - leftIcon={<FiGithub />} |
21 |
| - ms="auto" |
22 |
| - onClick={() => signIn('github')} |
23 |
| - > |
24 |
| - {t('auth:login.actions.github.login')} |
25 |
| - </Button> |
26 |
| - <Box borderRadius="md" bg="github.100" color="github.800" p="4"> |
27 |
| - <Text> |
28 |
| - <Icon icon={FiInfo} /> Only users from{' '} |
29 |
| - <Text as="span" fontWeight="medium"> |
30 |
| - {process.env.NEXT_PUBLIC_GITHUB_ALLOWED_ORGANIZATIONS} |
31 |
| - </Text>{' '} |
32 |
| - GitHub organisation(s) will be able to use the application once logged |
33 |
| - in. |
34 |
| - </Text> |
35 |
| - </Box> |
36 |
| - </Stack> |
| 23 | + <> |
| 24 | + {provider === 'github' ? ( |
| 25 | + <Stack {...rest}> |
| 26 | + <Button |
| 27 | + w="full" |
| 28 | + colorScheme="github" |
| 29 | + bg="github.800" |
| 30 | + color="white" |
| 31 | + leftIcon={<FiGithub />} |
| 32 | + ms="auto" |
| 33 | + onClick={() => signIn('github')} |
| 34 | + > |
| 35 | + {t('auth:login.actions.github.login')} |
| 36 | + </Button> |
| 37 | + <Box borderRadius="md" bg="github.100" color="github.800" p="4"> |
| 38 | + <Text> |
| 39 | + <Icon icon={FiInfo} /> Only users from{' '} |
| 40 | + <Text as="span" fontWeight="medium"> |
| 41 | + {process.env.NEXT_PUBLIC_GITHUB_ALLOWED_ORGANIZATIONS} |
| 42 | + </Text>{' '} |
| 43 | + GitHub organisation(s) will be able to use the application once |
| 44 | + logged in. |
| 45 | + </Text> |
| 46 | + </Box> |
| 47 | + </Stack> |
| 48 | + ) : ( |
| 49 | + <Stack> |
| 50 | + <Button |
| 51 | + w="full" |
| 52 | + colorScheme="gitlab" |
| 53 | + bg="github.800" |
| 54 | + color="white" |
| 55 | + leftIcon={<FiGitlab />} |
| 56 | + ms="auto" |
| 57 | + onClick={() => signIn('gitlab')} |
| 58 | + > |
| 59 | + {t('auth:login.actions.gitlab.login')} |
| 60 | + </Button> |
| 61 | + <Box borderRadius="md" bg="github.100" color="github.800" p="4"> |
| 62 | + <Text> |
| 63 | + <Icon icon={FiInfo} /> Only users from{' '} |
| 64 | + <Text as="span" fontWeight="medium"> |
| 65 | + {process.env.NEXT_PUBLIC_GITHUB_ALLOWED_ORGANIZATIONS} |
| 66 | + </Text>{' '} |
| 67 | + GitLab organisation(s) will be able to use the application once |
| 68 | + logged in. |
| 69 | + </Text> |
| 70 | + </Box> |
| 71 | + </Stack> |
| 72 | + )} |
| 73 | + </> |
37 | 74 | );
|
38 | 75 | };
|
0 commit comments