|
| 1 | +import { AttributeList, Button, Card, P, useDialog } from "@maykin-ui/admin-ui"; |
| 2 | +import { useCallback } from "react"; |
| 3 | + |
| 4 | +import { useDataFetcher } from "../../hooks/useDataFetcher"; |
| 5 | +import { getAppInfo } from "../../lib/api/app-info"; |
| 6 | + |
1 | 7 | export type LogoProps = {
|
2 |
| - width?: number; |
| 8 | + width?: number | string; |
| 9 | + withDialog?: boolean; |
3 | 10 | };
|
4 | 11 |
|
5 |
| -export function Logo({ width = 128 }: LogoProps) { |
| 12 | +/** |
| 13 | + * Implementation of the LogoImage with optional interactivity |
| 14 | + */ |
| 15 | +export function Logo({ width = 128, withDialog = false }: LogoProps) { |
| 16 | + const dialog = useDialog(); |
| 17 | + |
| 18 | + const onClick = useCallback(() => { |
| 19 | + dialog("Over", <DialogBody />, undefined, { size: "s" }); |
| 20 | + }, [dialog]); |
| 21 | + |
| 22 | + return withDialog ? ( |
| 23 | + <Button variant="transparent" onClick={onClick} pad={false}> |
| 24 | + <LogoImage width={width} /> |
| 25 | + </Button> |
| 26 | + ) : ( |
| 27 | + <LogoImage width={width} /> |
| 28 | + ); |
| 29 | +} |
| 30 | + |
| 31 | +function DialogBody() { |
| 32 | + const { data: appInfo } = useDataFetcher( |
| 33 | + (signal) => getAppInfo(signal), |
| 34 | + { |
| 35 | + errorMessage: |
| 36 | + "Er is een fout opgetreden bij het ophalen van de versieinfo!", |
| 37 | + }, |
| 38 | + [], |
| 39 | + ); |
| 40 | + |
| 41 | + return ( |
| 42 | + <Card> |
| 43 | + <LogoImage width={"100%"} /> |
| 44 | + <AttributeList |
| 45 | + object={{ |
| 46 | + Versie: <P size="xs">{appInfo?.release}</P>, |
| 47 | + "Git SHA": <P size="xs">{appInfo?.gitSha}</P>, |
| 48 | + }} |
| 49 | + /> |
| 50 | + </Card> |
| 51 | + ); |
| 52 | +} |
| 53 | + |
| 54 | +/** |
| 55 | + * Purely the image of the logo, without any interactivity. |
| 56 | + */ |
| 57 | +function LogoImage({ width }: { width: number | string }) { |
6 | 58 | return <img src="/logo.svg" alt="Open Archiefbeheer Logo" width={width} />;
|
7 | 59 | }
|
0 commit comments