Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

figma tables #847

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 17 additions & 53 deletions src/components/Organization/Dashboard/ProcessCard.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { Box, Flex, Text } from '@chakra-ui/react'
import { Td, Tr } from '@chakra-ui/react'
import { ElectionStatusBadge, ElectionTitle, QuestionsTypeBadge } from '@vocdoni/chakra-components'
import { useElection } from '@vocdoni/react-providers'
import { ensure0x, InvalidElection } from '@vocdoni/sdk'
import { InvalidElection } from '@vocdoni/sdk'
import { useTranslation } from 'react-i18next'
import { generatePath, Link as RouterLink } from 'react-router-dom'
import { useDateFns } from '~i18n/use-date-fns'
import { Routes } from '~src/router/routes'

const ProcessCard = () => {
const { election } = useElection()
Expand All @@ -15,58 +13,24 @@ const ProcessCard = () => {
if (!election || election instanceof InvalidElection) return null

return (
<Box
as={RouterLink}
to={generatePath(Routes.dashboard.process, { id: ensure0x(election.id) })}
w='full'
display='flex'
gap={5}
textDecoration='none'
py='10px'
borderRadius='xl'
px={4}
_hover={{
bgColor: 'process.card_hover.light',

_dark: {
bgColor: 'process.card_hover.dark',
},
}}
>
<ElectionTitle
flexGrow={1}
flexShrink={0}
flexBasis={48}
mb={0}
mt={1}
fontSize='md'
textAlign='left'
fontWeight='500'
isTruncated
/>
<Box flexGrow={1} flexShrink={0} flexBasis={60} fontWeight='500'>
<Text as='span'>{format(election.startDate, t('organization.date_format'))}</Text> -{' '}
<Text as='span'>{format(election.endDate, t('organization.date_format'))}</Text>
</Box>
<Box
flexGrow={1}
flexShrink={0}
flexBasis={36}
sx={{
label: {
fontWeight: 500,
},
}}
>
<Tr>
<Td>
<ElectionTitle mb={0} fontSize='md' textAlign='left' fontWeight='500' isTruncated />
</Td>
<Td>
{format(election.startDate, t('organization.date_format'))} -{' '}
{format(election.endDate, t('organization.date_format'))}
</Td>
<Td>
<QuestionsTypeBadge />
</Box>
<Flex flexGrow={1} flexShrink={0} flexBasis={24}>
</Td>
<Td>
<ElectionStatusBadge />
</Flex>
<Flex flexGrow={1} flexShrink={0} flexBasis={24} fontWeight='500'>
</Td>
<Td>
{election.voteCount}/{election.census.size}
</Flex>
</Box>
</Td>
</Tr>
)
}

Expand Down
62 changes: 23 additions & 39 deletions src/components/Organization/Dashboard/ProcessesList.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { Alert, AlertDescription, Flex, Progress, Text, VStack } from '@chakra-ui/react'
import { Table, TableContainer, Tbody, Th, Thead, Tr } from '@chakra-ui/react'
import { ElectionProvider } from '@vocdoni/react-providers'
import { InvalidElection, PublishedElection } from '@vocdoni/sdk'
import { useTranslation } from 'react-i18next'
import { HSeparator } from '~components/Auth/SignIn'
import NoElections from '../NoElections'
import ProcessCard from './ProcessCard'

type Election = PublishedElection | InvalidElection
Expand All @@ -18,42 +16,28 @@ const ProcessesList = ({ loading, processes, error }: ProcessesListProps) => {
const { t } = useTranslation()

return (
<VStack w='full' overflowX='auto' borderRadius='lg' py={{ base: 2.5, lg: 5 }} px={{ base: 5, lg: 10 }}>
{loading && <Progress isIndeterminate w='full' colorScheme='primary' size='xs' />}
{error && (
<Alert>
<AlertDescription>{error.message.toString()}</AlertDescription>
</Alert>
)}
<Flex w='full' gap={5} fontSize='sm' pl={4}>
<Text flexGrow={1} flexShrink={0} flexBasis={48} textTransform='uppercase'>
{t('process_list.title', { defaultValue: 'Title' })}
</Text>
<Text flexGrow={1} flexShrink={0} flexBasis={60} textTransform='uppercase'>
{t('process_list.start_end_date', { defaultValue: 'Start-end date' })}
</Text>
<Text flexGrow={1} flexShrink={0} flexBasis={36} textTransform='uppercase'>
{t('process_list.type', { defaultValue: 'Type' })}
</Text>
<Text flexGrow={1} flexShrink={0} flexBasis={24} textTransform='uppercase'>
{t('process_list.status', { defaultValue: 'Status' })}
</Text>
<Text flexGrow={1} flexShrink={0} flexBasis={24} textTransform='uppercase'>
{t('process_list.voters', { defaultValue: 'Voters' })}
</Text>
</Flex>
<HSeparator />
<VStack w='full'>
{processes &&
processes.length &&
processes?.map((election) => (
<ElectionProvider election={election} id={election.id} key={election.id}>
<ProcessCard />
</ElectionProvider>
))}
{!loading && (!processes || !processes.length) && <NoElections />}
</VStack>
</VStack>
<TableContainer>
<Table>
<Thead>
<Tr>
<Th>{t('process_list.title', { defaultValue: 'Title' })}</Th>
<Th>{t('process_list.start_end_date', { defaultValue: 'Start-end date' })}</Th>
<Th>{t('process_list.type', { defaultValue: 'Type' })}</Th>
<Th>{t('process_list.status', { defaultValue: 'Status' })}</Th>
<Th>{t('process_list.voters', { defaultValue: 'Voters' })}</Th>
</Tr>
</Thead>
<Tbody>
{processes &&
processes.length &&
processes?.map((election) => (
<ElectionProvider election={election} id={election.id} key={election.id}>
<ProcessCard />
</ElectionProvider>
))}
</Tbody>
</Table>
</TableContainer>
)
}

Expand Down
7 changes: 1 addition & 6 deletions src/elements/dashboard/processes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ElectionListWithPagination } from '@vocdoni/sdk'
import { useEffect } from 'react'
import { useTranslation } from 'react-i18next'
import { useLoaderData, useOutletContext } from 'react-router-dom'
import { DashboardContents } from '~components/Layout/Dashboard'
import Votings from '~components/Organization/Dashboard/Votings'
import { DashboardLayoutContext } from '~elements/LayoutDashboard'

Expand All @@ -17,11 +16,7 @@ const OrganizationVotings = () => {
setBack(null)
}, [setTitle, setBack])

return (
<DashboardContents>
<Votings data={data as ElectionListWithPagination} />
</DashboardContents>
)
return <Votings data={data as ElectionListWithPagination} />
}

export default OrganizationVotings
33 changes: 33 additions & 0 deletions src/theme/components/table.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { tableAnatomy } from '@chakra-ui/anatomy'
import { createMultiStyleConfigHelpers } from '@chakra-ui/react'

const { definePartsStyle, defineMultiStyleConfig } = createMultiStyleConfigHelpers(tableAnatomy.keys)

const baseStyle = definePartsStyle((props) => ({
table: {
borderRadius: 'lg',
bgColor: 'white',
overflow: 'hidden',
},
thead: {
bg: 'gray.100',
bgColor: 'lightBlue',
},
th: {
textTransform: 'normal',
fontWeight: 600,
textAlign: 'left',
},
td: {},
}))

const md = definePartsStyle({
th: {
paddingTop: '160px',
},
})

export const Table = defineMultiStyleConfig({
baseStyle,
sizes: { md },
})
2 changes: 2 additions & 0 deletions src/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { Text } from './components/text'
import { Textarea } from './components/textarea'
import { editor } from './editor'
import { spacing } from './space'
import { Table } from './components/table'

export const theme = extendTheme(vtheme, {
config: {
Expand Down Expand Up @@ -94,6 +95,7 @@ export const theme = extendTheme(vtheme, {
Pagination,
Radio,
Stepper,
Table,
Tabs,
Text,
Textarea,
Expand Down
Loading