|
| 1 | +import {AddIcon} from '@sanity/icons' |
| 2 | +import {Box, Flex, Stack, Text} from '@sanity/ui' |
| 3 | +import {useCallback} from 'react' |
| 4 | +import {useTranslation} from 'react-i18next' |
| 5 | +import styled from 'styled-components' |
| 6 | + |
| 7 | +import {Button} from '../../../../../ui-components' |
| 8 | +import {tasksLocaleNamespace} from '../../../../i18n' |
| 9 | +import {type SidebarTabsIds, useTasksNavigation} from '../../context' |
| 10 | +import {type TaskStatus} from '../../types' |
| 11 | + |
| 12 | +const HEADING_BY_STATUS: Record< |
| 13 | + TaskStatus, |
| 14 | + Record< |
| 15 | + SidebarTabsIds, |
| 16 | + { |
| 17 | + heading: string |
| 18 | + text: string |
| 19 | + } |
| 20 | + > |
| 21 | +> = { |
| 22 | + open: { |
| 23 | + assigned: { |
| 24 | + heading: 'empty-state.status.list.open.assigned.heading', |
| 25 | + text: 'empty-state.status.list.open.assigned.text', |
| 26 | + }, |
| 27 | + document: {heading: 'empty-state.status.list.open.document.heading', text: ''}, |
| 28 | + subscribed: { |
| 29 | + heading: 'empty-state.status.list.open.subscribed.heading', |
| 30 | + text: 'empty-state.status.list.open.subscribed.text', |
| 31 | + }, |
| 32 | + }, |
| 33 | + closed: { |
| 34 | + assigned: { |
| 35 | + heading: 'empty-state.status.list.closed.assigned.heading', |
| 36 | + text: 'empty-state.status.list.closed.assigned.text', |
| 37 | + }, |
| 38 | + document: {heading: 'empty-state.status.list.closed.document.heading', text: ''}, |
| 39 | + subscribed: { |
| 40 | + heading: 'empty-state.status.list.closed.subscribed.heading', |
| 41 | + text: 'empty-state.status.list.closed.subscribed.text', |
| 42 | + }, |
| 43 | + }, |
| 44 | +} |
| 45 | + |
| 46 | +export function EmptyStatusListState({status}: {status: TaskStatus}) { |
| 47 | + const { |
| 48 | + state: {activeTabId}, |
| 49 | + } = useTasksNavigation() |
| 50 | + const {t} = useTranslation(tasksLocaleNamespace) |
| 51 | + const {heading, text} = HEADING_BY_STATUS[status][activeTabId] |
| 52 | + return ( |
| 53 | + <Stack space={3}> |
| 54 | + <Text size={1} weight="semibold"> |
| 55 | + {t(heading)} |
| 56 | + </Text> |
| 57 | + <Text size={1}>{t(text)}</Text> |
| 58 | + </Stack> |
| 59 | + ) |
| 60 | +} |
| 61 | + |
| 62 | +const EMPTY_TASK_LIST: Record< |
| 63 | + SidebarTabsIds, |
| 64 | + { |
| 65 | + heading: string |
| 66 | + text: string |
| 67 | + } |
| 68 | +> = { |
| 69 | + assigned: { |
| 70 | + heading: 'empty-state.list.assigned.heading', |
| 71 | + text: 'empty-state.list.assigned.text', |
| 72 | + }, |
| 73 | + subscribed: { |
| 74 | + heading: 'empty-state.list.subscribed.heading', |
| 75 | + text: 'empty-state.list.subscribed.text', |
| 76 | + }, |
| 77 | + document: { |
| 78 | + heading: 'empty-state.list.document.heading', |
| 79 | + text: 'empty-state.list.document.text', |
| 80 | + }, |
| 81 | +} |
| 82 | + |
| 83 | +const Root = styled.div` |
| 84 | + max-width: 268px; |
| 85 | + margin: 0 auto; |
| 86 | + height: 100%; |
| 87 | + margin-top: 40%; |
| 88 | +` |
| 89 | +export function EmptyTasksListState() { |
| 90 | + const { |
| 91 | + state: {activeTabId}, |
| 92 | + setViewMode, |
| 93 | + } = useTasksNavigation() |
| 94 | + const {heading, text} = EMPTY_TASK_LIST[activeTabId] |
| 95 | + const {t} = useTranslation(tasksLocaleNamespace) |
| 96 | + |
| 97 | + const handleTaskCreate = useCallback(() => { |
| 98 | + setViewMode({type: 'create'}) |
| 99 | + }, [setViewMode]) |
| 100 | + return ( |
| 101 | + <Root> |
| 102 | + <Flex direction={'column'} gap={3} align={'center'} flex={1} justify={'center'}> |
| 103 | + <Text size={1} weight="semibold"> |
| 104 | + {t(heading)} |
| 105 | + </Text> |
| 106 | + <Box paddingBottom={6} paddingTop={1}> |
| 107 | + <Text size={1} align="center"> |
| 108 | + {t(text)} |
| 109 | + </Text> |
| 110 | + </Box> |
| 111 | + <Button icon={AddIcon} text={t('empty-state.list.create-new')} onClick={handleTaskCreate} /> |
| 112 | + </Flex> |
| 113 | + </Root> |
| 114 | + ) |
| 115 | +} |
0 commit comments