update: pagination for assessment when choose aspect on sidebar, and update card using shadcn
This commit is contained in:
parent
c7e9a7e9af
commit
a9d8fed683
|
|
@ -1,8 +1,6 @@
|
||||||
import { createLazyFileRoute } from "@tanstack/react-router";
|
import { createLazyFileRoute } from "@tanstack/react-router";
|
||||||
import {
|
import {
|
||||||
Card,
|
|
||||||
Flex,
|
Flex,
|
||||||
// Pagination,
|
|
||||||
Stack,
|
Stack,
|
||||||
Text,
|
Text,
|
||||||
Loader,
|
Loader,
|
||||||
|
|
@ -10,6 +8,12 @@ import {
|
||||||
CloseButton,
|
CloseButton,
|
||||||
Group,
|
Group,
|
||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
|
import {
|
||||||
|
Card,
|
||||||
|
CardContent,
|
||||||
|
CardDescription,
|
||||||
|
CardHeader,
|
||||||
|
} from "@/shadcn/components/ui/card";
|
||||||
import { Textarea } from "@/shadcn/components/ui/textarea";
|
import { Textarea } from "@/shadcn/components/ui/textarea";
|
||||||
import { Label } from "@/shadcn/components/ui/label";
|
import { Label } from "@/shadcn/components/ui/label";
|
||||||
import { RadioGroup, RadioGroupItem } from "@/shadcn/components/ui/radio-group";
|
import { RadioGroup, RadioGroupItem } from "@/shadcn/components/ui/radio-group";
|
||||||
|
|
@ -77,6 +81,9 @@ export default function AssessmentPage() {
|
||||||
const [unansweredQuestions, setUnansweredQuestions] = useState(0);
|
const [unansweredQuestions, setUnansweredQuestions] = useState(0);
|
||||||
const [validationModalOpen, setValidationModalOpen] = useState(false);
|
const [validationModalOpen, setValidationModalOpen] = useState(false);
|
||||||
const [exceededFileName, setExceededFileName] = useState("");
|
const [exceededFileName, setExceededFileName] = useState("");
|
||||||
|
const [currentPagePerSubAspect, setCurrentPagePerSubAspect] = useState<{ [subAspectId: string]: number }>({});
|
||||||
|
const currentPage = currentPagePerSubAspect[selectedSubAspectId || ""] || 1;
|
||||||
|
const questionsPerPage = 10;
|
||||||
|
|
||||||
// Fetch aspects and sub-aspects
|
// Fetch aspects and sub-aspects
|
||||||
const aspectsQuery = useQuery({
|
const aspectsQuery = useQuery({
|
||||||
|
|
@ -511,11 +518,6 @@ export default function AssessmentPage() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle pagination
|
|
||||||
const handlePageChange = (newPage: number) => {
|
|
||||||
setPage(newPage);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Render conditions
|
// Render conditions
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return <Loader />;
|
return <Loader />;
|
||||||
|
|
@ -529,26 +531,43 @@ export default function AssessmentPage() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const totalQuestions = data?.data?.length || 0;
|
|
||||||
const totalPages = Math.ceil(totalQuestions / limit);
|
|
||||||
|
|
||||||
if (!assessmentId) {
|
if (!assessmentId) {
|
||||||
return (
|
return (
|
||||||
<Card shadow="sm" p="lg" radius="md" withBorder>
|
<Card>
|
||||||
|
<CardContent>
|
||||||
<Text color="red" className="text-center">
|
<Text color="red" className="text-center">
|
||||||
Error: Data Asesmen tidak ditemukan. Harap akses halaman melalui link yang valid.
|
Error: Data Asesmen tidak ditemukan. Harap akses halaman melalui link yang valid.
|
||||||
</Text>
|
</Text>
|
||||||
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const startIndex = (page - 1) * limit;
|
const startIndex = (page - 1) * limit;
|
||||||
const endIndex = startIndex + limit;
|
|
||||||
const paginatedQuestions = data?.data.slice(startIndex, endIndex) || [];
|
|
||||||
|
|
||||||
const filteredQuestions = paginatedQuestions.filter((question) => {
|
// Fungsi untuk mengubah halaman pada sub-aspek
|
||||||
return question.subAspectId === selectedSubAspectId; // Misalnya, jika `question` memiliki `subAspectId`
|
const handlePageChange = (subAspectId: string, newPage: number) => {
|
||||||
});
|
setCurrentPagePerSubAspect((prev) => ({
|
||||||
|
...prev,
|
||||||
|
[subAspectId]: newPage,
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
|
// Filter pertanyaan berdasarkan halaman saat ini
|
||||||
|
const filteredQuestions = data?.data?.filter((question) => {
|
||||||
|
// Filter berdasarkan sub-aspek yang dipilih
|
||||||
|
return question.subAspectId === selectedSubAspectId;
|
||||||
|
})?.slice(
|
||||||
|
(currentPage - 1) * questionsPerPage,
|
||||||
|
currentPage * questionsPerPage
|
||||||
|
) || [];
|
||||||
|
|
||||||
|
// Perbarui jumlah halaman untuk sub-aspek saat ini
|
||||||
|
const totalQuestionsInSubAspect = data?.data?.filter(
|
||||||
|
(question) => question.subAspectId === selectedSubAspectId
|
||||||
|
)?.length || 0;
|
||||||
|
|
||||||
|
const totalPages = Math.ceil(totalQuestionsInSubAspect / questionsPerPage);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
|
@ -828,17 +847,28 @@ export default function AssessmentPage() {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="mt-4 flex justify-center">
|
<div className="mt-4 flex justify-center">
|
||||||
<Pagination page={page} totalPages={totalPages} onPageChange={handlePageChange}>
|
<Pagination
|
||||||
<Text className="text-xs m-0">Halaman {page} dari {totalPages}</Text>
|
page={currentPage}
|
||||||
|
totalPages={totalPages}
|
||||||
|
onPageChange={(newPage) => {
|
||||||
|
if (selectedSubAspectId) {
|
||||||
|
handlePageChange(selectedSubAspectId, newPage);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Text className="text-xs m-0">Halaman {currentPage} dari {totalPages}</Text>
|
||||||
</Pagination>
|
</Pagination>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Skor Aspek dan Sub-Aspek */}
|
{/* Skor Aspek dan Sub-Aspek */}
|
||||||
<div className="mt-4">
|
<div className="mt-4">
|
||||||
<Card shadow="sm" p="md" radius="md" withBorder>
|
<Card>
|
||||||
<Stack>
|
<CardHeader>
|
||||||
{/* Skor Aspek */}
|
<Text className="font-extrabold text-center">Nilai Sementara</Text>
|
||||||
<div>
|
</CardHeader>
|
||||||
|
|
||||||
|
<CardContent>
|
||||||
|
<CardDescription>
|
||||||
{filteredAspects.length > 0 ? (
|
{filteredAspects.length > 0 ? (
|
||||||
filteredAspects.map((aspect) => {
|
filteredAspects.map((aspect) => {
|
||||||
const aspectScore = parseFloat(aspect.averageScore).toFixed(2);
|
const aspectScore = parseFloat(aspect.averageScore).toFixed(2);
|
||||||
|
|
@ -868,15 +898,12 @@ export default function AssessmentPage() {
|
||||||
) : (
|
) : (
|
||||||
<Text className="text-base text-gray-400">Data aspek ini kosong</Text>
|
<Text className="text-base text-gray-400">Data aspek ini kosong</Text>
|
||||||
)}
|
)}
|
||||||
</div>
|
</CardDescription>
|
||||||
|
|
||||||
{/* Garis pembatas */}
|
{/* Garis pembatas */}
|
||||||
<div>
|
<div className="border-t-2 border-gray-300 my-4" />
|
||||||
<hr className="border-t-2 border-gray-300 w-full mx-auto" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Skor Sub-Aspek */}
|
{/* Skor Sub-Aspek */}
|
||||||
<div>
|
|
||||||
{filteredSubAspects.length > 0 ? (
|
{filteredSubAspects.length > 0 ? (
|
||||||
filteredSubAspects.map((subAspect) => {
|
filteredSubAspects.map((subAspect) => {
|
||||||
const subAspectScore = parseFloat(subAspect.averageScore).toFixed(2);
|
const subAspectScore = parseFloat(subAspect.averageScore).toFixed(2);
|
||||||
|
|
@ -906,12 +933,14 @@ export default function AssessmentPage() {
|
||||||
) : (
|
) : (
|
||||||
<Text className="text-sm text-gray-400">Data sub-aspek ini kosong</Text>
|
<Text className="text-sm text-gray-400">Data sub-aspek ini kosong</Text>
|
||||||
)}
|
)}
|
||||||
</div>
|
</CardContent>
|
||||||
</Stack>
|
|
||||||
|
|
||||||
{/* Tombol Selesai */}
|
{/* Tombol Selesai */}
|
||||||
<div className="mt-6">
|
<div className="mt-4 mb-4 ml-4 mr-4">
|
||||||
<button onClick={handleFinishClick} className="bg-blue-500 text-white font-bold rounded-md py-2 w-full text-sm">
|
<button
|
||||||
|
onClick={handleFinishClick}
|
||||||
|
className="bg-blue-500 text-white font-bold rounded-md py-2 w-full text-sm"
|
||||||
|
>
|
||||||
Selesai
|
Selesai
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user