-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathConventionFormWebsiteSection.tsx
More file actions
125 lines (119 loc) · 4.29 KB
/
ConventionFormWebsiteSection.tsx
File metadata and controls
125 lines (119 loc) · 4.29 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import { CSSObject } from '@emotion/serialize';
import * as React from 'react';
import { BooleanInput, HelpText, usePropertySetters } from '@neinteractiveliterature/litform';
import SelectWithLabel from '../BuiltInFormControls/SelectWithLabel';
import LiquidInput from '../BuiltInFormControls/LiquidInput';
import type { ConventionFormConvention } from './ConventionForm';
import { ConventionAdminConventionQueryData } from './queries.generated';
import FileInputWithPreview from '../CmsAdmin/CmsFilesAdmin/FileInputWithPreview';
import { useTranslation } from 'react-i18next';
// Since our selects come right above a CodeMirror, we need to override the z-index on the
// dropdown menu so that the text in the CodeMirror doesn't cover it
const selectStyles = {
menu: (provided: CSSObject) => ({ ...provided, zIndex: 5 }),
};
export type ConventionFormWebsiteSectionProps = {
convention: ConventionFormConvention;
setConvention: React.Dispatch<React.SetStateAction<ConventionFormConvention>>;
disabled: boolean;
rootSite: ConventionAdminConventionQueryData['rootSite'];
cmsLayouts: ConventionAdminConventionQueryData['convention']['cmsLayouts'];
pages: ConventionAdminConventionQueryData['convention']['cmsPages'];
openGraphImage: File | null | undefined;
setOpenGraphImage: React.Dispatch<File | null | undefined>;
favicon: File | null | undefined;
setFavicon: React.Dispatch<File | null | undefined>;
};
function ConventionFormWebsiteSection({
convention,
rootSite,
setConvention,
cmsLayouts,
pages,
disabled,
openGraphImage,
setOpenGraphImage,
favicon,
setFavicon,
}: ConventionFormWebsiteSectionProps): React.JSX.Element {
const [setDefaultLayout, setRootPage, setClickwrapAgreement, setHidden] = usePropertySetters(
setConvention,
'defaultLayout',
'rootPage',
'clickwrap_agreement',
'hidden',
);
const { t } = useTranslation();
return (
<>
<SelectWithLabel
name="default_layout_id"
label="Default layout for pages"
value={convention.defaultLayout}
isClearable
getOptionValue={(option) => option?.id.toString() ?? ''}
getOptionLabel={(option) => option?.name ?? ''}
options={cmsLayouts}
onChange={(newValue) => newValue && setDefaultLayout(newValue)}
styles={selectStyles}
isDisabled={disabled}
/>
<SelectWithLabel
name="root_page_id"
label="Root page"
value={convention.rootPage ?? null}
isClearable
getOptionValue={(option) => option?.id.toString() ?? ''}
getOptionLabel={(option) => option?.name ?? ''}
options={pages}
onChange={(newValue) => newValue && setRootPage(newValue)}
styles={selectStyles}
isDisabled={disabled}
/>
<BooleanInput
caption={
<>
Hide convention from public list on{' '}
<a href={rootSite.url} target="_blank" rel="noreferrer">
{rootSite.url}
</a>
?
</>
}
value={convention.hidden}
onChange={setHidden}
/>
<fieldset className="mb-4">
<legend className="col-form-label">
Clickwrap agreement (if present, all users will be prompted to accept this agreement before using the site)
</legend>
<LiquidInput
value={convention.clickwrap_agreement ?? ''}
onChange={setClickwrapAgreement}
disabled={disabled}
/>
</fieldset>
<fieldset className="mb-4">
<legend className="col-form-label">{t('admin.convention.openGraphImageLabel')}</legend>
<HelpText>{t('admin.convention.openGraphImageHelpText')}</HelpText>
<FileInputWithPreview
existingFileUrl={convention.open_graph_image?.url}
file={openGraphImage}
onChange={setOpenGraphImage}
disabled={disabled}
/>
</fieldset>
<fieldset className="mb-4">
<legend className="col-form-label">{t('admin.convention.faviconLabel')}</legend>
<HelpText>{t('admin.convention.faviconHelpText')}</HelpText>
<FileInputWithPreview
existingFileUrl={convention.favicon?.url}
file={favicon}
onChange={setFavicon}
disabled={disabled}
/>
</fieldset>
</>
);
}
export default ConventionFormWebsiteSection;