-
Notifications
You must be signed in to change notification settings - Fork 170
Expand file tree
/
Copy pathScheduledContentTabs.tsx
More file actions
108 lines (104 loc) · 4.37 KB
/
Copy pathScheduledContentTabs.tsx
File metadata and controls
108 lines (104 loc) · 4.37 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
import { useState } from 'react';
import { Box, Flex, FormControl, Tabs, Text } from '@contentful/f36-components';
import { ScheduledContentTable } from './ScheduledContentTable';
import { RecentlyPublishedTable } from './RecentlyPublishedTable';
import { NeedsUpdateTable } from './NeedsUpdateTable';
import { styles } from './Dashboard.styles';
import { useSDK } from '@contentful/react-apps-toolkit';
import { HomeAppSDK, PageAppSDK, ConfigAppSDK } from '@contentful/app-sdk';
import { ReactNode } from 'react';
import { EntryProps, ScheduledActionProps, ContentTypeProps } from 'contentful-management';
import ContentTypeMultiSelect, { ContentType } from './ContentTypeMultiSelect';
import type { AppInstallationParameters } from '../locations/ConfigScreen';
interface TabPanelContentProps {
description: string;
children: ReactNode;
}
const TabPanelContent = ({ description, children }: TabPanelContentProps) => {
return (
<Flex flexDirection="column" marginLeft="spacingM" marginRight="spacingM" marginTop="spacingL">
<Text fontSize="fontSizeM" fontColor="gray600" marginBottom="spacingM">
{description}
</Text>
{children}
</Flex>
);
};
export const ScheduledContentTabs = ({
scheduledActions,
entries,
contentTypes,
}: {
scheduledActions: ScheduledActionProps[];
entries: EntryProps[];
contentTypes: Map<string, ContentTypeProps>;
}) => {
const sdk = useSDK<HomeAppSDK | PageAppSDK>();
const { parameters } = sdk;
const installation = (parameters?.installation ?? {}) as AppInstallationParameters;
const recentlyPublishedDays = installation.recentlyPublishedDays;
const needsUpdateMonths = installation.needsUpdateMonths;
const [currentTab, setCurrentTab] = useState('scheduled');
const [selectedNeedsUpdateContentTypes, setSelectedNeedsUpdateContentTypes] = useState<
ContentType[]
>([]);
return (
<Box marginTop="spacingXl">
<Box padding="spacingL" style={styles.releasesTableContainer}>
<Tabs currentTab={currentTab} onTabChange={setCurrentTab}>
<Tabs.List variant="horizontal-divider">
<Tabs.Tab panelId="scheduled">Scheduled content</Tabs.Tab>
<Tabs.Tab panelId="recentlyPublished">Recently published</Tabs.Tab>
<Tabs.Tab panelId="needsUpdate">Needs update</Tabs.Tab>
</Tabs.List>
<Tabs.Panel id="scheduled">
<TabPanelContent description="Content scheduled will appear here.">
<ScheduledContentTable
scheduledActions={scheduledActions}
entries={entries}
contentTypes={contentTypes}
/>
</TabPanelContent>
</Tabs.Panel>
<Tabs.Panel id="recentlyPublished">
<TabPanelContent
description={`Content published in the last ${recentlyPublishedDays} ${
recentlyPublishedDays === 1 ? 'day' : 'days'
} will appear here.`}>
<RecentlyPublishedTable entries={entries} contentTypes={contentTypes} />
</TabPanelContent>
</Tabs.Panel>
<Tabs.Panel id="needsUpdate">
<TabPanelContent
description={`Content older than ${needsUpdateMonths} ${
needsUpdateMonths === 1 ? 'month' : 'months'
} will appear here.`}>
<FormControl marginBottom="spacingM">
<FormControl.Label>Filter by content type</FormControl.Label>
<ContentTypeMultiSelect
selectedContentTypes={selectedNeedsUpdateContentTypes}
setSelectedContentTypes={setSelectedNeedsUpdateContentTypes}
sdk={sdk as unknown as ConfigAppSDK}
initialSelectedIds={installation.needsUpdateContentTypes}
disablePills={false}
/>
<FormControl.HelpText>
Leave empty to use the configured default.
</FormControl.HelpText>
</FormControl>
<NeedsUpdateTable
entries={entries}
contentTypes={contentTypes}
selectedContentTypeIds={
selectedNeedsUpdateContentTypes.length > 0
? selectedNeedsUpdateContentTypes.map((ct) => ct.id)
: undefined
}
/>
</TabPanelContent>
</Tabs.Panel>
</Tabs>
</Box>
</Box>
);
};