Pull Request branch dev-clone to main #1
|
|
@ -25,14 +25,14 @@ const assessmentRequestRoute = new Hono<HonoEnv>()
|
|||
requestValidator(
|
||||
"query",
|
||||
z.object({
|
||||
page: z.coerce.number().int().min(0).default(0), // Menambahkan pagination page
|
||||
limit: z.coerce.number().int().min(1).max(1000).default(10), // Menambahkan pagination limit
|
||||
q: z.string().optional(), // Kata kunci pencarian (search)
|
||||
page: z.coerce.number().int().min(0).default(0),
|
||||
limit: z.coerce.number().int().min(1).max(1000).default(10),
|
||||
q: z.string().optional(),
|
||||
})
|
||||
),
|
||||
async (c) => {
|
||||
const currentUser = c.get("currentUser");
|
||||
const userId = currentUser?.id; // Mengambil userId dari currentUser yang disimpan di context
|
||||
const userId = currentUser?.id; // Get user ID of the currently logged in currentUser
|
||||
|
||||
if (!userId) {
|
||||
throw forbidden({
|
||||
|
|
@ -41,7 +41,7 @@ const assessmentRequestRoute = new Hono<HonoEnv>()
|
|||
}
|
||||
const { page, limit, q } = c.req.valid("query");
|
||||
|
||||
// Query untuk menghitung total data
|
||||
// Query to count total data
|
||||
const totalCountQuery = db
|
||||
.select({
|
||||
count: sql<number>`count(distinct ${assessments.id})`,
|
||||
|
|
@ -59,19 +59,15 @@ const assessmentRequestRoute = new Hono<HonoEnv>()
|
|||
const totalCountResult = await totalCountQuery;
|
||||
const totalItems = totalCountResult[0]?.count || 0;
|
||||
|
||||
// Query untuk mendapatkan data assessment dengan pagination
|
||||
// Query to get assessment data with pagination
|
||||
const queryResult = await db
|
||||
.select({
|
||||
userId: users.id,
|
||||
createdAt: assessments.createdAt,
|
||||
name: users.name,
|
||||
code: rolesSchema.code,
|
||||
id: assessments.id,
|
||||
assessmentId: assessments.id,
|
||||
tanggal: assessments.createdAt,
|
||||
status: assessments.status,
|
||||
respondentId: respondents.id,
|
||||
email: users.email,
|
||||
username: users.username,
|
||||
})
|
||||
.from(users)
|
||||
.leftJoin(rolesToUsers, eq(users.id, rolesToUsers.userId))
|
||||
|
|
@ -91,7 +87,6 @@ const assessmentRequestRoute = new Hono<HonoEnv>()
|
|||
|
||||
if (!queryResult[0]) throw notFound();
|
||||
|
||||
// Mengembalikan data dengan metadata pagination
|
||||
return c.json({
|
||||
data: queryResult,
|
||||
_metadata: {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ export default function StartAssessmentModal({
|
|||
</Button>
|
||||
<Button
|
||||
onClick={() => {
|
||||
onConfirm(assessmentId); // Menggunakan assessmentId saat konfirmasi
|
||||
onConfirm(assessmentId); // Use assessmentId when confirming
|
||||
}}
|
||||
>
|
||||
Mulai Asesmen
|
||||
|
|
|
|||
|
|
@ -1,12 +1,6 @@
|
|||
import stringToColorHex from "@/utils/stringToColorHex";
|
||||
import {
|
||||
Avatar,
|
||||
// Button,
|
||||
Center,
|
||||
Flex,
|
||||
Modal,
|
||||
ScrollArea,
|
||||
Stack,
|
||||
Text
|
||||
} from "@mantine/core";
|
||||
import { Button } from "@/shadcn/components/ui/button";
|
||||
|
|
@ -40,14 +34,16 @@ export default function UserFormModal() {
|
|||
|
||||
const modalTitle = <b>Konfirmasi</b>
|
||||
|
||||
|
||||
const form = useForm({
|
||||
initialValues: {
|
||||
id: "",
|
||||
respondentsId: "",
|
||||
name: "",
|
||||
},
|
||||
});
|
||||
|
||||
// used to get the respondentId of the currently logged in user
|
||||
// and then set respondentsId in the form to create an assessment request
|
||||
useEffect(() => {
|
||||
const data = userQuery.data;
|
||||
|
||||
|
|
@ -57,7 +53,6 @@ export default function UserFormModal() {
|
|||
}
|
||||
|
||||
form.setValues({
|
||||
id: data.data[0].id ?? "",
|
||||
respondentsId: data.data[0].respondentId ?? "",
|
||||
name: data.data[0].name ?? "",
|
||||
});
|
||||
|
|
@ -65,6 +60,7 @@ export default function UserFormModal() {
|
|||
form.setErrors({});
|
||||
}, [userQuery.data]);
|
||||
|
||||
// Mutation function to create a new assessment request and refresh query after success
|
||||
const mutation = useMutation({
|
||||
mutationKey: ["usersMutation"],
|
||||
mutationFn: async (options: { action: "create"; data: { respondentsId: string } }) => {
|
||||
|
|
@ -140,19 +136,11 @@ export default function UserFormModal() {
|
|||
disableAll: mutation.isPending,
|
||||
readonlyAll: formType === "create",
|
||||
inputs: [
|
||||
{
|
||||
type: "text",
|
||||
label: "User ID",
|
||||
readOnly: true,
|
||||
variant: "filled",
|
||||
...form.getInputProps("id"),
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
type: "text",
|
||||
label: "Respondent ID",
|
||||
...form.getInputProps("respondentsId"),
|
||||
hidden: true,
|
||||
hidden: true,
|
||||
},
|
||||
{
|
||||
type: "text",
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ export default function UsersPage() {
|
|||
const [selectedAssessmentId, setSelectedAssessmentId] = useState<string | null>(null);
|
||||
|
||||
/**
|
||||
* Fungsi untuk membuka modal konfirmasi mulai asesmen
|
||||
* @param {string} assessmentId ID asesmen yang akan di mulai
|
||||
* Function to open confirmation modal to start assessment
|
||||
* @param {string} assessmentId ID of the assessment to be started
|
||||
*/
|
||||
const handleOpenModal = (assessmentId: string) => {
|
||||
if (!assessmentId) {
|
||||
|
|
@ -37,8 +37,8 @@ export default function UsersPage() {
|
|||
};
|
||||
|
||||
/**
|
||||
* Fungsi untuk membuka halaman asesmen di tab baru
|
||||
* @param {string} assessmentId ID asesmen yang akan di buka
|
||||
* Function to open assessment page in new tab
|
||||
* @param {string} assessmentId ID of the assessment to be opened
|
||||
*/
|
||||
const handleStartAssessment = (assessmentId: string) => {
|
||||
// Redirect ke URL baru di tab baru
|
||||
|
|
@ -48,12 +48,12 @@ export default function UsersPage() {
|
|||
};
|
||||
|
||||
/**
|
||||
* Fungsi untuk membuka halaman hasil asesmen berdasarkan ID yang valid
|
||||
* Digunakan ketika tombol "Lihat Hasil" diklik
|
||||
* @param {string} assessmentId ID asesmen yang akan di buka
|
||||
* Function to open assessment result page based on valid ID
|
||||
* Used when "View Result" button is clicked
|
||||
* @param {string} assessmentId ID of the assessment to be opened
|
||||
*/
|
||||
const handleViewResult = (assessmentId: string) => {
|
||||
// Make sure assessmentId is valid and not null
|
||||
// to make sure assessmentId is valid and not null
|
||||
if (!assessmentId) {
|
||||
console.error("Assessment ID is missing");
|
||||
return;
|
||||
|
|
@ -77,7 +77,7 @@ export default function UsersPage() {
|
|||
columnHelper.display({
|
||||
header: "Tanggal",
|
||||
cell: (props) =>
|
||||
props.row.original.createdAt
|
||||
props.row.original.tanggal
|
||||
? new Intl.DateTimeFormat("ID", {
|
||||
year: "numeric",
|
||||
month: "long",
|
||||
|
|
@ -85,7 +85,7 @@ export default function UsersPage() {
|
|||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
hour12: true,
|
||||
}).format(new Date(props.row.original.createdAt))
|
||||
}).format(new Date(props.row.original.tanggal))
|
||||
: 'N/A',
|
||||
}),
|
||||
columnHelper.display({
|
||||
|
|
@ -94,7 +94,6 @@ export default function UsersPage() {
|
|||
const status = props.row.original.status;
|
||||
switch (status) {
|
||||
case "menunggu konfirmasi":
|
||||
// return <Badge color="yellow">Menunggu Konfirmasi</Badge>;
|
||||
return <Badge variant={"waiting"}>Menunggu Konfirmasi</Badge>;
|
||||
case "diterima":
|
||||
return <Badge variant={"accepted"}>Diterima</Badge>;
|
||||
|
|
@ -111,7 +110,7 @@ export default function UsersPage() {
|
|||
header: "Actions",
|
||||
cell: (props) => {
|
||||
const status = props.row.original.status;
|
||||
const assessmentId = props.row.original.id; // Retrieve the assessmentId from the data row
|
||||
const assessmentId = props.row.original.assessmentId; // Retrieve the assessmentId from the data row
|
||||
|
||||
return (
|
||||
<Flex gap="xs">
|
||||
|
|
@ -141,7 +140,7 @@ export default function UsersPage() {
|
|||
]}
|
||||
/>
|
||||
|
||||
{/* Modal Konfirmasi Start Asessment */}
|
||||
{/* Confirmation Modal to Start Assessment */}
|
||||
{selectedAssessmentId && (
|
||||
<StartAssessmentModal
|
||||
assessmentId={selectedAssessmentId}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|||
<Comp
|
||||
className={cn(buttonVariants({ variant, size, className }))}
|
||||
ref={ref}
|
||||
disabled={isLoading || props.disabled} // Disable tombol jika loading
|
||||
disabled={isLoading || props.disabled} // Disable button if loading
|
||||
{...props}
|
||||
>
|
||||
{isLoading ? (
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user