Skip to content

Commit 1fc55b8

Browse files
berentebIsti01
authored andcommitted
feat: debt module for frontend
1 parent 392276f commit 1fc55b8

File tree

10 files changed

+139
-13
lines changed

10 files changed

+139
-13
lines changed

frontend/src/App.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import RaceByTeamPage from './pages/race/raceByTeam.page.tsx'
4545
import CreateTeamPage from './pages/teams/createTeam.page.tsx'
4646
import EditMyTeamPage from './pages/teams/editMyTeam.page.tsx'
4747
import MyTeamPage from './pages/teams/myTeam.page.tsx'
48+
import DebtPage from './pages/debt/debt.page.tsx'
4849

4950
export function App() {
5051
return (
@@ -62,6 +63,9 @@ export function App() {
6263
<Route path=":id" element={<CommunityPage />} />
6364
<Route index element={<CommunityListPage />} />
6465
</Route>
66+
<Route path={Paths.DEBT}>
67+
<Route index element={<DebtPage />} />
68+
</Route>
6569
<Route path={Paths.ORGANIZATION}>
6670
<Route path=":id" element={<OrganizationPage />} />
6771
<Route index element={<OrganizationListPage />} />

frontend/src/api/contexts/config/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,10 @@ export interface Token {
260260
defaultTestIcon: string
261261
}
262262

263-
export interface Debt {}
263+
export interface Debt {
264+
topMessage: string
265+
title: string
266+
}
264267

265268
export interface UserHandling {}
266269

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import axios from 'axios'
2+
import { useQuery } from '@tanstack/react-query'
3+
import { ApiPaths } from '../../../util/paths'
4+
import { DebtDto } from '../../../util/views/debt.view.ts'
5+
import { QueryKeys } from '../queryKeys'
6+
7+
export const useDebtQuery = () => {
8+
return useQuery<DebtDto, Error>({
9+
queryKey: [QueryKeys.DEBTS],
10+
queryFn: async () => {
11+
const response = await axios.get<DebtDto>(ApiPaths.DEBTS)
12+
return response.data
13+
},
14+
refetchOnMount: 'always'
15+
})
16+
}

frontend/src/api/hooks/queryKeys.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ export enum QueryKeys {
2828
COMMUNITY = 'COMMUNITY',
2929
ORGANIZATION = 'ORGANIZATION',
3030
ACCESS_KEY = 'ACCESS_KEY',
31-
HOME_NEWS = 'HOME_NEWS'
31+
HOME_NEWS = 'HOME_NEWS',
32+
DEBTS = 'DEBTS'
3233
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Box, HStack, Text, useColorModeValue } from '@chakra-ui/react'
2+
import * as FaIcons from 'react-icons/fa'
3+
import { FaCircleCheck, FaCircleXmark } from 'react-icons/fa6'
4+
import { useOpaqueBackground } from '../../../util/core-functions.util.ts'
5+
import { DebtView } from '../../../util/views/debt.view.ts'
6+
7+
interface DebtListItemProps {
8+
item: DebtView
9+
}
10+
11+
export const DebtListItem = ({ item }: DebtListItemProps) => {
12+
const bg = useOpaqueBackground(1)
13+
14+
const red = useColorModeValue('red.500', 'red.300')
15+
const green = useColorModeValue('green.500', 'green.300')
16+
17+
return (
18+
<Box borderRadius="lg" padding={4} backgroundColor={bg} marginTop={5}>
19+
<HStack spacing={4} justify="space-between">
20+
<Text isTruncated display="flex" alignItems="center" gap={1}>
21+
<DebtIcon name="FaUser" />
22+
{item.product}
23+
</Text>
24+
<Text>{item.price}&nbsp;JMF</Text>
25+
{item.payed ? (
26+
<Text color={green} display="flex" alignItems="center" gap={1} fontWeight="bold">
27+
<FaCircleCheck /> Fizetve
28+
</Text>
29+
) : (
30+
<Text color={red} display="flex" alignItems="center" gap={1} fontWeight="bold">
31+
<FaCircleXmark /> Fizetetlen
32+
</Text>
33+
)}
34+
</HStack>
35+
</Box>
36+
)
37+
}
38+
39+
function DebtIcon({ name }: { name: string }) {
40+
const Icon = FaIcons[name as keyof typeof FaIcons] ?? null
41+
return <Icon />
42+
}

frontend/src/pages/debt/debt.page.tsx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { Divider, Heading, Text } from '@chakra-ui/react'
2+
import { Helmet } from 'react-helmet-async'
3+
import { useConfigContext } from '../../api/contexts/config/ConfigContext.tsx'
4+
import { useDebtQuery } from '../../api/hooks/debt/useDebtQuery.ts'
5+
import { useProfileQuery } from '../../api/hooks/profile/useProfileQuery.ts'
6+
import { ComponentUnavailable } from '../../common-components/ComponentUnavailable.tsx'
7+
import { CmschPage } from '../../common-components/layout/CmschPage.tsx'
8+
import Markdown from '../../common-components/Markdown.tsx'
9+
import { PageStatus } from '../../common-components/PageStatus.tsx'
10+
import { ProfileQR } from '../profile/components/ProfileQR.tsx'
11+
import { DebtListItem } from './components/debt-list-item.tsx'
12+
13+
const DebtPage = () => {
14+
const debtComponent = useConfigContext()?.components.debt
15+
const profileComponent = useConfigContext()?.components.profile
16+
const profileQuery = useProfileQuery()
17+
const { data, isError, isLoading } = useDebtQuery()
18+
19+
if (!debtComponent) return <ComponentUnavailable />
20+
21+
const title = debtComponent.title || 'Tartozások'
22+
23+
if (isError || isLoading || !data) return <PageStatus isLoading={isLoading} isError={isError} title={title} />
24+
25+
return (
26+
<CmschPage>
27+
<Helmet title={title} />
28+
<Heading as="h1" variant="main-title">
29+
{title}
30+
</Heading>
31+
{profileQuery.data && (
32+
<>
33+
<Divider my={8} borderWidth={2} />
34+
<ProfileQR profile={profileQuery.data} component={profileComponent} />
35+
<Divider my={8} borderWidth={2} />
36+
</>
37+
)}
38+
{debtComponent.topMessage && <Markdown text={debtComponent.topMessage} />}
39+
{data.debts.map((item) => (
40+
<DebtListItem key={item.product + item.price} item={item} />
41+
))}
42+
{data.debts.length === 0 && (
43+
<Text align="center" mt={10} fontWeight="bold">
44+
Nincs tranzakciód eddig, szaladj és vegyél valami zurát!
45+
</Text>
46+
)}
47+
</CmschPage>
48+
)
49+
}
50+
51+
export default DebtPage

frontend/src/pages/profile/components/ProfileQR.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import { ProfileView } from '../../../util/views/profile.view'
21
import {
32
Box,
43
Button,
54
Center,
6-
Divider,
75
Modal,
86
ModalBody,
97
ModalCloseButton,
@@ -13,16 +11,16 @@ import {
1311
Text,
1412
useDisclosure
1513
} from '@chakra-ui/react'
16-
import QRCode from 'react-qr-code'
1714
import { FaQrcode } from 'react-icons/fa'
15+
import QRCode from 'react-qr-code'
1816
import { Profile } from '../../../api/contexts/config/types'
1917
import { WalletButton } from '../../../common-components/WalletButton'
18+
import { ProfileView } from '../../../util/views/profile.view'
2019

2120
export const ProfileQR = ({ profile, component }: { profile: ProfileView; component: Profile }) => {
2221
const { isOpen, onOpen, onClose } = useDisclosure()
2322
return (
2423
<>
25-
<Divider my={10} borderWidth={2} w={'100%'} />
2624
<Center flexDirection="column">
2725
<Text fontSize="3xl" fontWeight={500}>
2826
{component.qrTitle}

frontend/src/pages/profile/profile.page.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,13 @@ const ProfilePage = ({}: Props) => {
144144
</>
145145
)}
146146

147-
{component.showQr && profile.cmschId && <ProfileQR profile={profile} component={component} />}
148-
{(component.showTasks || component.showRiddles || component.showTokens) && <Divider my={10} borderWidth={2} />}
147+
{component.showQr && profile.cmschId && (
148+
<>
149+
<Divider my={8} borderWidth={2} />
150+
<ProfileQR profile={profile} component={component} />
151+
</>
152+
)}
153+
{(component.showTasks || component.showRiddles || component.showTokens) && <Divider my={8} borderWidth={2} />}
149154
<Flex justify="center" alignItems="center" flexWrap="wrap">
150155
{component.showTasks && (
151156
<Center p={3}>

frontend/src/util/paths.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ export enum Paths {
2626
MY_TEAM = 'my-team',
2727
TEAM_ADMIN = 'team-admin',
2828
ACCESS_KEY = 'access-key',
29-
MAP = 'map'
29+
MAP = 'map',
30+
DEBT = 'debt'
3031
}
3132

3233
export enum AbsolutePaths {
@@ -56,7 +57,8 @@ export enum AbsolutePaths {
5657
QR_FIGHT = '/qr-fight',
5758
LEADER_BOARD = '/leaderboard',
5859
ACCESS_KEY = '/access-key',
59-
MAP = '/map'
60+
MAP = '/map',
61+
DEBT = '/debt'
6062
}
6163

6264
export enum ApiPaths {
@@ -90,5 +92,6 @@ export enum ApiPaths {
9092
DELETE_PUSH_NOTIFICATION_TOKEN = '/api/pushnotification/delete-token',
9193
MY_TEAM = '/api/team/my',
9294
TEAM = '/api/team',
93-
ALL_TEAMS = '/api/teams'
95+
ALL_TEAMS = '/api/teams',
96+
DEBTS = '/api/debts',
9497
}

frontend/src/util/views/debt.view.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ export interface DebtView {
55
representativeName: string
66
payed: boolean
77
shipped: boolean
8-
log: string
9-
materialIcon: string
8+
icon: string
9+
}
10+
11+
export interface DebtDto {
12+
debts: DebtView[]
1013
}

0 commit comments

Comments
 (0)