|
1 | | -import { Page, LinkButton, Image, Card, Flex } from '@webkom/lego-bricks'; |
2 | | -import { Package } from 'lucide-react'; |
| 1 | +import { Page, LinkButton, Image, Card } from '@webkom/lego-bricks'; |
| 2 | +import { Package, Contact, Tag } from 'lucide-react'; |
3 | 3 | import { useState } from 'react'; |
4 | 4 | import { Helmet } from 'react-helmet-async'; |
5 | 5 | import { Dateish } from 'app/models'; |
6 | | -import { |
7 | | - ContentMain, |
8 | | - ContentSection, |
9 | | - ContentSidebar, |
10 | | -} from '~/components/Content'; |
11 | 6 | import DisplayContent from '~/components/DisplayContent'; |
| 7 | +import { readmeIfy } from '~/components/ReadmeLogo'; |
12 | 8 | import TextWithIcon from '~/components/TextWithIcon'; |
13 | 9 | import { useFetchedLendableObject } from '~/pages/lending/@lendableObjectId/useFetchedLendableObject'; |
| 10 | +import { useAppSelector } from '~/redux/hooks'; |
| 11 | +import { selectGroupsByIds } from '~/redux/slices/groups'; |
| 12 | +import { LENDABLE_CATEGORY } from '~/utils/constants'; |
| 13 | +import truncateString from '~/utils/truncateString'; |
14 | 14 | import { useParams } from '~/utils/useParams'; |
15 | 15 | import LendingCalendar from './LendingCalendar'; |
16 | 16 | import LendingRequestEditor from './LendingRequestEditor'; |
17 | 17 | import styles from './Page.module.css'; |
18 | 18 |
|
| 19 | +export const formatGroups = (groups: { name: string }[]) => { |
| 20 | + return groups.length > 0 ? groups.map((g) => g.name).join(', ') : 'Ukjent'; |
| 21 | +}; |
| 22 | + |
19 | 23 | export const LendableObjectList = () => { |
20 | 24 | const { lendableObjectId } = useParams<{ lendableObjectId: string }>(); |
21 | 25 | const { lendableObject, fetching } = useFetchedLendableObject( |
22 | 26 | lendableObjectId!, |
23 | 27 | ); |
| 28 | + |
| 29 | + const responsibleGroups = useAppSelector((state) => |
| 30 | + selectGroupsByIds(state, lendableObject?.responsibleGroups), |
| 31 | + ); |
| 32 | + |
| 33 | + const formattedGroups = formatGroups(responsibleGroups) || ''; |
| 34 | + |
24 | 35 | const [range, setRange] = useState<[Dateish, Dateish] | undefined>(); |
25 | 36 |
|
26 | 37 | const title = lendableObject ? `Utlån: ${lendableObject.title}` : undefined; |
@@ -51,24 +62,42 @@ export const LendableObjectList = () => { |
51 | 62 | </Card> |
52 | 63 | )} |
53 | 64 | <DisplayContent content={lendableObject.description} /> |
54 | | - <TextWithIcon |
55 | | - iconNode={<Package />} |
56 | | - size={20} |
57 | | - content={lendableObject.location} |
58 | | - /> |
59 | 65 | </div> |
60 | 66 | {lendableObject.image && ( |
61 | | - <Card className={styles.card}> |
62 | | - <Image |
63 | | - className={styles.image} |
64 | | - alt="image of lendeable object" |
65 | | - src={lendableObject.image} |
66 | | - /> |
67 | | - </Card> |
| 67 | + <div className={styles.infoRight}> |
| 68 | + <Card className={styles.imageCard}> |
| 69 | + <Image |
| 70 | + className={styles.image} |
| 71 | + alt="image of lendeable object" |
| 72 | + src={lendableObject.image} |
| 73 | + /> |
| 74 | + </Card> |
| 75 | + <Card className={styles.practicalInfo}> |
| 76 | + <h4>Praktisk Info:</h4> |
| 77 | + <TextWithIcon |
| 78 | + iconNode={<Contact />} |
| 79 | + size={20} |
| 80 | + gap={'var(--spacing-xs)'} |
| 81 | + content={readmeIfy(truncateString(formattedGroups, 15))} |
| 82 | + /> |
| 83 | + <TextWithIcon |
| 84 | + iconNode={<Package />} |
| 85 | + size={20} |
| 86 | + gap={'var(--spacing-xs)'} |
| 87 | + content={lendableObject.location} |
| 88 | + /> |
| 89 | + <TextWithIcon |
| 90 | + iconNode={<Tag />} |
| 91 | + size={20} |
| 92 | + gap={'var(--spacing-xs)'} |
| 93 | + content={LENDABLE_CATEGORY[lendableObject.category]} |
| 94 | + /> |
| 95 | + </Card> |
| 96 | + </div> |
68 | 97 | )} |
69 | 98 | </div> |
70 | | - <div className={styles.border} /> |
71 | | - <div> |
| 99 | + <div className={styles.border}></div> |
| 100 | + <div className={styles.lendingCalendar}> |
72 | 101 | <LendingCalendar |
73 | 102 | selectedRange={range} |
74 | 103 | lendableObjectId={lendableObjectId} |
|
0 commit comments