Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Wak In #354

Merged
merged 2 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions callbacks/admin/addquestion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface QuestionType {
ID: number;
CreatedAt: string;
UpdatedAt: string;
event: string;
type: string;
question: string;
recruitment_cycle_id: number;
Expand Down
1 change: 1 addition & 0 deletions callbacks/admin/rc/proforma/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface QuestionProforma {
qid: number;
CreatedAt: string;
UpdatedAt: string;
event: string;
type: string;
question: string;
recruitment_cycle_id: number;
Expand Down
1 change: 1 addition & 0 deletions callbacks/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const ADMIN_RC_URL = `${BASE_URL}/api/admin/rc`;
export const ADMIN_STUDENT_URL = `${BASE_URL}/api/admin/student`;
export const ADMIN_COMPANY_URL = `${BASE_URL}/api/admin/company`;
export const ADMIN_APPLICATION_URL = `${BASE_URL}/api/admin/application`;
export const ADMIN_URL = `${BASE_URL}/api/admin`;

export const CDN_URL = `${BASE_URL}/cdn`;

Expand Down
6 changes: 5 additions & 1 deletion callbacks/student/rc/applyQuestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { errorNotification, successNotification } from "@callbacks/notifcation";
export interface studentApplicationQuestions {
ID: number;
proforma_id: number;
event: string;
type: string;
question: string;
options: string;
Expand All @@ -37,7 +38,10 @@ const responseBody = <T>(response: AxiosResponse<T>) => response.data;
const applicationRequest = {
getApplicationQuestion: (token: string, rcid: string, pid: string) =>
instance
.get(`/application/rc/${rcid}/opening/${pid}`, setConfig(token))
.get<studentApplicationQuestions[]>(
`/application/rc/${rcid}/opening/${pid}`,
setConfig(token)
)
.then(responseBody)
.catch((err: ErrorType) => {
errorNotification("Error", err.response?.data?.error || err.message);
Expand Down
13 changes: 13 additions & 0 deletions components/Modals/AddApplyQuestion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function AddApplyQuestion({
);
if (response) {
reset({
event: "",
question: "",
mandatory: false,
options: "",
Expand All @@ -81,6 +82,18 @@ function AddApplyQuestion({
<Stack spacing={3}>
<FormControl onSubmit={handleSubmit(onSubmit)}>
<h2 style={{ margin: "20px 0px 50px 0px" }}>Additional Questions</h2>
<FormControl sx={{ m: 1 }}>
<InputLabel id="Event">Application / Walk In Interview</InputLabel>
<Select
labelId="Event"
label="Event"
variant="standard"
{...register("event")}
>
<MenuItem value="Application">Application</MenuItem>
<MenuItem value="Walk In">Walk In</MenuItem>
</Select>
</FormControl>
<FormControl sx={{ m: 1 }}>
<InputLabel id="Type-of-Ques">Type of Question</InputLabel>
<Select
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ const columns: GridColDef[] = [
headerName: "ID",
width: 150,
},
{
field: "event",
headerName: "Event",
width: 150,
},
{
field: "type",
headerName: "Question Type",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ function Apply() {
const fetch = async () => {
const response = await applicationRequest
.getApplicationQuestion(token, rcid.toString(), openingid.toString())
.catch(() => ({ type: "null" } as studentApplicationQuestions));
setQuestions(response);
.catch(() => [{ type: "null" }] as studentApplicationQuestions[]);
setQuestions(
response.filter((question) => question.event === "Application")
);
};
fetch();
}, [rcid, token, router, openingid]);
Expand Down
206 changes: 206 additions & 0 deletions pages/student/rc/[rcid]/opening/[openingid]/walkin.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
import { useRouter } from "next/router";
import React, { useEffect, useState } from "react";
import {
Box,
Button,
FormControl,
FormControlLabel,
Radio,
RadioGroup,
Stack,
TextField,
Typography,
} from "@mui/material";
import { useForm } from "react-hook-form";

import applicationRequest, {
answerApplication,
studentApplicationQuestions,
} from "@callbacks/student/rc/applyQuestions";
import Meta from "@components/Meta";
import useStore from "@store/store";

const boxStyle = {
width: { xs: "330px", md: "500px" },
bgcolor: "background.paper",
border: "white solid 2px",
borderRadius: "10px",
boxShadow: 24,
p: 4,
marginTop: 5,
marginBottom: 10,
alignItems: "center",
};
function Apply() {
const {
register,
handleSubmit,
formState: { errors },
} = useForm();

const router = useRouter();
const { rcid, openingid, rsid } = router.query;

const { token } = useStore();
const [questions, setQuestions] = useState<studentApplicationQuestions[]>();
useEffect(() => {
if (!rcid || !openingid) return;
const fetch = async () => {
const response = await applicationRequest
.getApplicationQuestion(token, rcid.toString(), openingid.toString())
.catch(() => [{ type: "null" }] as studentApplicationQuestions[]);
setQuestions(response.filter((question) => question.event === "Walk In"));
};
fetch();
}, [rcid, token, router, openingid]);

const onSubmit = async (data: any) => {
if (questions) {
let res: answerApplication[] = [];
questions.forEach((question) => {
let obj: answerApplication = {
application_question_id: question.ID,
answer: data[question.ID],
};
res.push(obj);
});
if (rcid && openingid && rsid) {
await applicationRequest.postApplicationAnswer(
token,
rcid.toString(),
openingid.toString(),
{ resume_id: parseInt(rsid.toString(), 10), answers: res }
);
}
}
router.push(`/student/rc/${rcid}/opening`);
};

const renderSwitch = (
index: number,
question: studentApplicationQuestions
) => {
if (question) {
let name = question.ID.toString();
switch (question?.type) {
case "MCQ":
return (
<FormControl>
<RadioGroup
aria-labelledby="demo-radio-buttons-group-label"
defaultValue={question.answer}
row
>
{question.options
.toString()
.split(",")
.map((option) => (
<FormControlLabel
key={option}
value={option}
control={<Radio />}
label={option}
{...register(name)}
/>
))}
</RadioGroup>
{errors[name] && (
<Typography variant="caption" color="error">
*Required
</Typography>
)}
</FormControl>
);
case "Short Answer":
return (
<TextField
multiline
minRows={3}
defaultValue={question.answer}
variant="standard"
error={errors[name]}
helperText={errors[name] && "*Required"}
{...register(name)}
/>
);
case "Boolean":
return (
<FormControl>
<RadioGroup
aria-labelledby="demo-radio-buttons-group-label"
defaultValue={question.answer}
row
>
<FormControlLabel
value="true"
control={<Radio />}
label="True"
{...register(name)}
/>
<FormControlLabel
value="false"
control={<Radio />}
label="False"
{...register(name)}
/>
</RadioGroup>
{errors[name] && (
<Typography variant="caption" color="error">
*Required
</Typography>
)}
</FormControl>
);
default:
return <div />;
}
}
return <div />;
};

return (
<div>
<Meta title="RC - Openings - QnA" />
<Stack alignItems="center" spacing={4}>
<Box sx={boxStyle}>
<Stack spacing={4}>
<Stack spacing={2} alignItems="flex-start">
<h2>Walk In Questions</h2>
{questions &&
questions.length > 0 &&
questions.map((question, index) => (
<FormControl key={question.ID} sx={{ m: 1, width: "100%" }}>
<h3 style={{ fontWeight: 300 }}>
<b>Ques: </b> {questions[index]?.question}
</h3>
{questions && renderSwitch(index, question)}
</FormControl>
))}
{questions && questions.length === 0 && (
<h4>No Questions Found!</h4>
)}
</Stack>
<Stack spacing={2} alignItems="flex-start" direction="row">
<Button
variant="contained"
sx={{ width: "100%" }}
onClick={handleSubmit(onSubmit)}
>
Submit
</Button>
<Button
variant="contained"
sx={{ width: "100%" }}
onClick={() => window.location.reload()}
>
Reset
</Button>
</Stack>
</Stack>
</Box>
</Stack>
</div>
);
}
Apply.layout = "studentPhaseDashboard";
export default Apply;
Loading