Skip to content

Commit

Permalink
creating POST request
Browse files Browse the repository at this point in the history
  • Loading branch information
Prakhar-commits committed Nov 17, 2023
1 parent b10ac58 commit ee3ea76
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/components/Steps/Timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ export default function Timeline({
*/}
<input
className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded block w-full p-2.5 mt-10"
placeholder="Report Schedule"
placeholder="Repeat Schedule"
required
{...register("reportSchedule")}
{...register("repeatSchedule")}
/>
<input
className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded block w-full p-2.5 mt-10"
Expand Down
2 changes: 2 additions & 0 deletions src/pages/SessionCreator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export default function SessionCreator() {
});

const createSession = async () => {
console.log(data);

await postFormData(data);
setIsSessionAdded(true);

Expand Down
2 changes: 1 addition & 1 deletion src/types/FormTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type TimelineForm = {
synced: string;
sessionType: string;
reportLink: string;
reportSchedule: string;
repeatSchedule: string;
startDate: string;
endDate: string;
startTime: string;
Expand Down
63 changes: 57 additions & 6 deletions src/utils/FormInputHandling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,65 @@ async function getData(currentPage: number, limit: number) {

// post data to the server
async function postFormData(formData: RowType) {
const currentDate = new Date().toLocaleDateString();
const { student, test, timeline, dateCreated } = formData;
let start_time = timeline.startDate + "T" + timeline.startTime + ":00";
let end_time = timeline.endDate + "T" + timeline.endTime + ":00";
const requestBody = {
name: test.name,
platform: test.platform,
platform_link: test.platformLink,
portal_link: test.portalLink,
start_time,
end_time,
is_active: "",
purpose: {
type: "attendance",
params: "quiz",
},
repeat_schedule: { type: "weekly", params: [1, 2, 3, 4, 5, 6, 7] }, // this is hardcoded needs to be changed
session_id: "",
platform_id: "",
form_schema_id: "1",
type: "sign-in",
auth_type: "ID",
activate_signup: true,
id_generation: false,
redirection: false,
pop_up_form: true,
number_of_fields_in_pop_form: "3",
meta_data: {
group: student.group,
batch: student.batch,
grade: student.grade,
course: student.course,
stream: student.stream,
test_format: test.format,
test_purpose: test.purpose,
enabled: timeline.isEnabled,
infinite_session: true,
cms_test_id: test.cmdId,
test_takers_count: test.testTakers,
has_synced_to_bq: true,
optional_limits: test.optionalLimit,
marking_scheme: test.markingScheme,
test_type: test.type,
shortened_link: "",
report_link: timeline.reportLink,

const res = await instance.post("/quiz", {
dateCreated: currentDate,
...formData,
});
date_created: new Date().toISOString().split("T")[0],
},
};

return res;
try {
const response = await instance.post(
"https://staging-db.avantifellows.org/api/session",
requestBody
);
return response.data;
} catch (error) {
console.error("Error posting form data", error);
throw error;
}
}

export { getData, postFormData };

0 comments on commit ee3ea76

Please sign in to comment.