|
| 1 | +import { Caption1, Card, CardHeader, makeStyles, Spinner, Subtitle1, Text, tokens } from '@fluentui/react-components' |
| 2 | +import { useEffect, useState } from 'react' |
| 3 | +import { getCSVTicketFields } from '../../services/api' |
| 4 | + |
| 5 | +const useStyles = makeStyles({ |
| 6 | + container: { |
| 7 | + padding: tokens.spacingVerticalL, |
| 8 | + display: 'flex', |
| 9 | + flexDirection: 'column', |
| 10 | + gap: tokens.spacingVerticalL, |
| 11 | + }, |
| 12 | + tableWrapper: { |
| 13 | + overflowX: 'auto', |
| 14 | + backgroundColor: tokens.colorNeutralBackground1, |
| 15 | + borderRadius: tokens.borderRadiusMedium, |
| 16 | + boxShadow: tokens.shadow4, |
| 17 | + }, |
| 18 | + table: { |
| 19 | + width: '100%', |
| 20 | + borderCollapse: 'collapse', |
| 21 | + fontSize: tokens.fontSizeBase200, |
| 22 | + }, |
| 23 | + th: { |
| 24 | + padding: `${tokens.spacingVerticalS} ${tokens.spacingHorizontalM}`, |
| 25 | + textAlign: 'left', |
| 26 | + backgroundColor: tokens.colorNeutralBackground3, |
| 27 | + borderBottom: `2px solid ${tokens.colorNeutralStroke1}`, |
| 28 | + whiteSpace: 'nowrap', |
| 29 | + }, |
| 30 | + td: { |
| 31 | + padding: `${tokens.spacingVerticalS} ${tokens.spacingHorizontalM}`, |
| 32 | + borderBottom: `1px solid ${tokens.colorNeutralStroke2}`, |
| 33 | + maxWidth: '320px', |
| 34 | + overflow: 'hidden', |
| 35 | + textOverflow: 'ellipsis', |
| 36 | + whiteSpace: 'nowrap', |
| 37 | + }, |
| 38 | + tr: { |
| 39 | + ':nth-child(even)': { |
| 40 | + backgroundColor: tokens.colorNeutralBackground2, |
| 41 | + }, |
| 42 | + }, |
| 43 | +}) |
| 44 | + |
| 45 | +export default function FieldsDocs() { |
| 46 | + const styles = useStyles() |
| 47 | + const [fields, setFields] = useState([]) |
| 48 | + const [loading, setLoading] = useState(true) |
| 49 | + const [error, setError] = useState(null) |
| 50 | + |
| 51 | + useEffect(() => { |
| 52 | + async function load() { |
| 53 | + try { |
| 54 | + const data = await getCSVTicketFields() |
| 55 | + setFields(data.fields || []) |
| 56 | + } catch (err) { |
| 57 | + setError(err?.message || 'Failed to load fields') |
| 58 | + } finally { |
| 59 | + setLoading(false) |
| 60 | + } |
| 61 | + } |
| 62 | + load() |
| 63 | + }, []) |
| 64 | + |
| 65 | + return ( |
| 66 | + <div className={styles.container}> |
| 67 | + <div> |
| 68 | + <Subtitle1>CSV Ticket Fields</Subtitle1> |
| 69 | + <Caption1>Fetched from API: `/csv-tickets/fields`</Caption1> |
| 70 | + </div> |
| 71 | + |
| 72 | + {loading && ( |
| 73 | + <Spinner label="Loading fields..." /> |
| 74 | + )} |
| 75 | + |
| 76 | + {error && ( |
| 77 | + <Text>{error}</Text> |
| 78 | + )} |
| 79 | + |
| 80 | + {!loading && !error && ( |
| 81 | + <Card> |
| 82 | + <CardHeader header={<Text weight="semibold">Available Fields ({fields.length})</Text>} /> |
| 83 | + <div className={styles.tableWrapper}> |
| 84 | + <table className={styles.table}> |
| 85 | + <thead> |
| 86 | + <tr> |
| 87 | + <th className={styles.th}>Name</th> |
| 88 | + <th className={styles.th}>Label</th> |
| 89 | + <th className={styles.th}>Type</th> |
| 90 | + </tr> |
| 91 | + </thead> |
| 92 | + <tbody> |
| 93 | + {fields.map((field) => ( |
| 94 | + <tr key={field.name} className={styles.tr}> |
| 95 | + <td className={styles.td}>{field.name}</td> |
| 96 | + <td className={styles.td}>{field.label || '—'}</td> |
| 97 | + <td className={styles.td}>{field.type || 'string'}</td> |
| 98 | + </tr> |
| 99 | + ))} |
| 100 | + </tbody> |
| 101 | + </table> |
| 102 | + </div> |
| 103 | + </Card> |
| 104 | + )} |
| 105 | + </div> |
| 106 | + ) |
| 107 | +} |
0 commit comments