LayoutConfigurationDetail.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. "use client";
  2. import { useState } from "react";
  3. import { useRouter } from "next/navigation";
  4. import { LayoutSectionCard } from "./LayoutSectionCard";
  5. import { AddSectionDialog } from "./AddSectionDialog";
  6. import { Button } from "@/components/ui/button";
  7. import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
  8. import { Badge } from "@/components/ui/badge";
  9. import { ArrowLeft, Plus } from "lucide-react";
  10. interface LayoutConfiguration {
  11. id: number;
  12. name: string;
  13. sections: LayoutSection[];
  14. createdAt: Date;
  15. updatedAt: Date;
  16. }
  17. interface LayoutSection {
  18. id: number;
  19. name: string;
  20. type: string;
  21. sheetName: string;
  22. startingRow?: number | null;
  23. endingRow?: number | null;
  24. tableName: string;
  25. fields: LayoutSectionField[];
  26. }
  27. interface LayoutSectionField {
  28. id: number;
  29. name: string;
  30. dataType: string;
  31. dataTypeFormat: string | null;
  32. cellPosition: string;
  33. importTableColumnName: string;
  34. importColumnOrderNumber: number;
  35. }
  36. interface LayoutConfigurationDetailProps {
  37. configuration: LayoutConfiguration;
  38. }
  39. export function LayoutConfigurationDetail({ configuration }: LayoutConfigurationDetailProps) {
  40. const router = useRouter();
  41. const [isDialogOpen, setIsDialogOpen] = useState(false);
  42. return (
  43. <div className="space-y-6">
  44. <div className="flex items-center gap-4">
  45. <Button
  46. variant="ghost"
  47. size="sm"
  48. onClick={() => router.push("/layout-configurations")}
  49. >
  50. <ArrowLeft className="h-4 w-4 mr-2" />
  51. Back to Configurations
  52. </Button>
  53. </div>
  54. <Card>
  55. <CardHeader>
  56. <div className="flex justify-between items-start">
  57. <div>
  58. <CardTitle>Configuration Details</CardTitle>
  59. <CardDescription>
  60. Overview of the layout configuration and its sections
  61. </CardDescription>
  62. </div>
  63. <div className="flex gap-2">
  64. <Badge variant="secondary">
  65. {configuration.sections.length} sections
  66. </Badge>
  67. <Badge variant="outline">
  68. {configuration.sections.reduce((total, section) => total + section.fields.length, 0)} fields
  69. </Badge>
  70. </div>
  71. </div>
  72. </CardHeader>
  73. <CardContent>
  74. <div className="grid gap-4">
  75. <div>
  76. <span className="font-medium">Name:</span> {configuration.name}
  77. </div>
  78. <div>
  79. <span className="font-medium">Created:</span> {new Date(configuration.createdAt).toLocaleDateString()}
  80. </div>
  81. <div>
  82. <span className="font-medium">Last Updated:</span> {new Date(configuration.updatedAt).toLocaleDateString()}
  83. </div>
  84. </div>
  85. </CardContent>
  86. </Card>
  87. <div className="space-y-4">
  88. <div className="flex justify-between items-center">
  89. <h2 className="text-2xl font-semibold">Sections</h2>
  90. <Button size="sm" onClick={() => setIsDialogOpen(true)}>
  91. <Plus className="h-4 w-4 mr-2" />
  92. Add Section
  93. </Button>
  94. </div>
  95. {configuration.sections.length === 0 ? (
  96. <Card>
  97. <CardContent className="pt-6">
  98. <p className="text-center text-muted-foreground">
  99. No sections found for this configuration
  100. </p>
  101. </CardContent>
  102. </Card>
  103. ) : (
  104. <div className="grid gap-4">
  105. {configuration.sections.map((section) => (
  106. <LayoutSectionCard key={section.id} section={section} />
  107. ))}
  108. </div>
  109. )}
  110. </div>
  111. <AddSectionDialog
  112. configurationId={configuration.id}
  113. open={isDialogOpen}
  114. onOpenChange={setIsDialogOpen}
  115. />
  116. </div>
  117. );
  118. }