LayoutConfigurationDetail.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. const [sections, setSections] = useState(configuration.sections);
  43. return (
  44. <div className="space-y-6">
  45. <div className="flex items-center gap-4">
  46. <Button
  47. variant="ghost"
  48. size="sm"
  49. onClick={() => router.push("/layout-configurations")}
  50. >
  51. <ArrowLeft className="h-4 w-4 mr-2" />
  52. Back to Configurations
  53. </Button>
  54. </div>
  55. <Card>
  56. <CardHeader>
  57. <div className="flex justify-between items-start">
  58. <div>
  59. <CardTitle>Configuration Details</CardTitle>
  60. <CardDescription>
  61. Overview of the layout configuration and its sections
  62. </CardDescription>
  63. </div>
  64. <div className="flex gap-2">
  65. <Badge variant="secondary">
  66. {sections.length} sections
  67. </Badge>
  68. <Badge variant="outline">
  69. {sections.reduce((total, section) => total + section.fields.length, 0)} fields
  70. </Badge>
  71. </div>
  72. </div>
  73. </CardHeader>
  74. <CardContent>
  75. <div className="grid gap-4">
  76. <div>
  77. <span className="font-medium">Name:</span> {configuration.name}
  78. </div>
  79. <div>
  80. <span className="font-medium">Created:</span> {new Date(configuration.createdAt).toLocaleDateString()}
  81. </div>
  82. <div>
  83. <span className="font-medium">Last Updated:</span> {new Date(configuration.updatedAt).toLocaleDateString()}
  84. </div>
  85. </div>
  86. </CardContent>
  87. </Card>
  88. <div className="space-y-4">
  89. <div className="flex justify-between items-center">
  90. <h2 className="text-2xl font-semibold">Sections</h2>
  91. <Button size="sm" onClick={() => setIsDialogOpen(true)}>
  92. <Plus className="h-4 w-4 mr-2" />
  93. Add Section
  94. </Button>
  95. </div>
  96. {sections.length === 0 ? (
  97. <Card>
  98. <CardContent className="pt-6">
  99. <p className="text-center text-muted-foreground">
  100. No sections found for this configuration
  101. </p>
  102. </CardContent>
  103. </Card>
  104. ) : (
  105. <div className="grid gap-4">
  106. {sections.map((section) => (
  107. <LayoutSectionCard
  108. key={section.id}
  109. section={section}
  110. onSectionDeleted={() => {
  111. // Refresh the sections list
  112. setSections(prev => prev.filter(s => s.id !== section.id));
  113. }}
  114. />
  115. ))}
  116. </div>
  117. )}
  118. </div>
  119. <AddSectionDialog
  120. configurationId={configuration.id}
  121. open={isDialogOpen}
  122. onOpenChange={setIsDialogOpen}
  123. />
  124. </div>
  125. );
  126. }