-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Expand file tree
/
Copy pathSettingsAccountsEditImapSmtpCaldavConnection.tsx
More file actions
102 lines (89 loc) · 2.98 KB
/
Copy pathSettingsAccountsEditImapSmtpCaldavConnection.tsx
File metadata and controls
102 lines (89 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { styled } from '@linaria/react';
import { useLingui } from '@lingui/react/macro';
import { FormProvider } from 'react-hook-form';
import { useParams } from 'react-router-dom';
import { SaveAndCancelButtons } from '@/settings/components/SaveAndCancelButtons/SaveAndCancelButtons';
import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer';
import { SettingsPageLayout } from '@/settings/components/layout/SettingsPageLayout';
import { SettingsPath } from 'twenty-shared/types';
import { Loader } from 'twenty-ui/feedback';
import { getSettingsPath } from 'twenty-shared/utils';
import { useNavigateSettings } from '~/hooks/useNavigateSettings';
import { ACCOUNT_TYPES } from 'twenty-shared/constants';
import { NotFound } from '~/pages/not-found/NotFound';
import { useImapSmtpCaldavConnectionForm } from '@/settings/accounts/hooks/useImapSmtpCaldavConnectionForm';
import { SettingsAccountsConnectionForm } from './SettingsAccountsConnectionForm';
const StyledLoadingContainer = styled.div`
align-items: center;
display: flex;
height: 200px;
justify-content: center;
`;
export const SettingsAccountsEditImapSmtpCaldavConnection = () => {
const { t } = useLingui();
const navigate = useNavigateSettings();
const { connectedAccountId } = useParams<{ connectedAccountId: string }>();
const {
formMethods,
handleSave,
handleSubmit,
canSave,
isSubmitting,
loading,
connectedAccount,
} = useImapSmtpCaldavConnectionForm({
isEditing: true,
connectedAccountId,
});
const { control } = formMethods;
if (loading && !connectedAccount) {
return (
<StyledLoadingContainer>
<Loader />
</StyledLoadingContainer>
);
}
if (!connectedAccount && !loading) {
return <NotFound />;
}
const existingProtocols = ACCOUNT_TYPES.filter(
(protocol) => connectedAccount?.connectionParameters?.[protocol]?.host,
);
const renderForm = () => (
// oxlint-disable-next-line react/jsx-props-no-spreading
<FormProvider {...formMethods}>
<SettingsPageLayout
title={t`Edit Account`}
links={[
{
children: t`User`,
href: getSettingsPath(SettingsPath.ProfilePage),
},
{
children: t`Accounts`,
href: getSettingsPath(SettingsPath.Accounts),
},
{ children: t`Edit Account` },
]}
actionButton={
<SaveAndCancelButtons
isSaveDisabled={!canSave}
isCancelDisabled={isSubmitting}
isLoading={loading}
onCancel={() => navigate(SettingsPath.Accounts)}
onSave={handleSubmit((data) => handleSave(data))}
/>
}
>
<SettingsPageContainer>
<SettingsAccountsConnectionForm
control={control}
isEditing
existingProtocols={existingProtocols}
/>
</SettingsPageContainer>
</SettingsPageLayout>
</FormProvider>
);
return renderForm();
};