1 import { useState } from 'react';
3 import { c } from 'ttag';
5 import { Button, Href } from '@proton/atoms';
6 import Copy from '@proton/components/components/button/Copy';
7 import PrimaryButton from '@proton/components/components/button/PrimaryButton';
8 import Icon from '@proton/components/components/icon/Icon';
9 import SettingsLayout from '@proton/components/containers/account/SettingsLayout';
10 import SettingsLayoutLeft from '@proton/components/containers/account/SettingsLayoutLeft';
11 import SettingsLayoutRight from '@proton/components/containers/account/SettingsLayoutRight';
12 import SettingsParagraph from '@proton/components/containers/account/SettingsParagraph';
13 import SettingsSectionWide from '@proton/components/containers/account/SettingsSectionWide';
14 import useApi from '@proton/components/hooks/useApi';
15 import useNotifications from '@proton/components/hooks/useNotifications';
16 import useUserVPN from '@proton/components/hooks/useUserVPN';
17 import { useLoading } from '@proton/hooks';
18 import { resetVPNSettings } from '@proton/shared/lib/api/vpn';
19 import { VPN_APP_NAME } from '@proton/shared/lib/constants';
25 const OpenVPNCredentialsSection = (props: Props) => {
26 const [updating, withUpdating] = useLoading();
27 const { result = {}, fetch: fetchUserVPN } = useUserVPN();
28 const { VPN = {} } = result as any;
29 const { Name = '', Password = '' } = VPN;
30 const [show, setShow] = useState(false);
32 const { createNotification } = useNotifications();
33 const { app } = props;
35 const handleResetCredentials = async () => {
36 await api(resetVPNSettings());
39 createNotification({ text: c('Notification').t`OpenVPN / IKEv2 credentials regenerated` });
43 <Href key="learn-more" href="https://protonvpn.com/support/vpn-login/">{c('Link').t`Learn more`}</Href>
52 .t`You can use the following credentials to connect to a ${VPN_APP_NAME} server using a third-party, open source VPN app, like Tunnelblick for macOS or OpenVPN for GNU/Linux.`}
55 {c('Info').t`Learn how to sign in to ${VPN_APP_NAME} with third-party VPN applications.`}
58 {c('Info').t`We advise you to use official ${VPN_APP_NAME} applications when possible.`}
62 .jt`These credentials cannot be used to sign in to our official ${VPN_APP_NAME} apps. ${learnMore}`}
69 .t`Use the following credentials when connecting to ${VPN_APP_NAME} servers without application. Example use cases include: Tunnelblick on macOS, OpenVPN on GNU/Linux.`}
73 .jt`These credentials cannot be used to sign in to our official ${VPN_APP_NAME} apps. ${learnMore}`}
80 <span className="label pt-0">{c('Label').t`OpenVPN / IKEv2 username`}</span>
82 <SettingsLayoutRight className="flex items-center">
83 <div className="text-ellipsis max-w-full mr-0 md:mr-4">
84 <code title={Name}>{Name}</code>
86 <div className="flex shrink-0 mt-2 md:mt-0">
91 text: c('Success').t`Username copied to clipboard`,
96 </SettingsLayoutRight>
100 <span className="label pt-0">{c('Label').t`OpenVPN / IKEv2 password`}</span>
101 </SettingsLayoutLeft>
102 <SettingsLayoutRight className="flex items-center">
103 <div className="text-ellipsis max-w-full mr-0 md:mr-4">
104 <code>{show ? Password : '••••••••••••••••'}</code>
106 <div className="flex shrink-0 mt-2 md:mt-0">
112 text: c('Success').t`Password copied to clipboard`,
118 onClick={() => setShow(!show)}
119 title={show ? c('Action').t`Hide` : c('Action').t`Show`}
122 name={show ? 'eye-slash' : 'eye'}
123 alt={show ? c('Action').t`Hide` : c('Action').t`Show`}
127 </SettingsLayoutRight>
130 disabled={!Name || !Password}
132 onClick={() => withUpdating(handleResetCredentials())}
133 >{c('Action').t`Reset credentials`}</PrimaryButton>
134 </SettingsSectionWide>
138 export default OpenVPNCredentialsSection;