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