Skip to content

Commit 3fe931b

Browse files
Events time (#461)
Co-authored-by: Prince Kumar <x.prince.x@outlook.com>
1 parent 2241894 commit 3fe931b

2 files changed

Lines changed: 30 additions & 18 deletions

File tree

src/components/Admin/JobEvents.tsx

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ const options = typeOptions.map((option) => ({
3636
label: option,
3737
}));
3838

39+
const formatDateTimeLocalValue = (date: string | Date) => {
40+
const value = new Date(date);
41+
const timezoneOffset = value.getTimezoneOffset() * 60000;
42+
43+
return new Date(value.getTime() - timezoneOffset).toISOString().slice(0, 16);
44+
};
45+
46+
const convertDateTimeLocalToISOString = (date: string) => {
47+
return new Date(date).toISOString();
48+
};
49+
3950
export const EditEvent = ({
4051
open,
4152
setOpen,
@@ -91,10 +102,8 @@ export const EditEvent = ({
91102
roundNumber: eventData.roundNumber,
92103
type: eventData.type,
93104
metadata: eventData.metadata,
94-
startDateTime: new Date(eventData.startDateTime)
95-
.toISOString()
96-
.slice(0, 16),
97-
endDateTime: new Date(eventData.endDateTime).toISOString().slice(0, 16),
105+
startDateTime: formatDateTimeLocalValue(eventData.startDateTime),
106+
endDateTime: formatDateTimeLocalValue(eventData.endDateTime),
98107
visibleToRecruiter: eventData.visibleToRecruiter,
99108
additionalData: eventData.additionalData || {},
100109
});
@@ -158,18 +167,14 @@ export const EditEvent = ({
158167
setFormValues({ ...formValues, additionalData: newAdditionalData });
159168
};
160169

161-
const convertToISOFormat = (date: string) => {
162-
return new Date(date).toISOString();
163-
};
164-
165170
const handleSubmit = async (e: React.FormEvent) => {
166171
e.preventDefault();
167172
setUpdating(true);
168173
try {
169174
const updatedValues = {
170175
...formValues,
171-
startDateTime: convertToISOFormat(formValues.startDateTime),
172-
endDateTime: convertToISOFormat(formValues.endDateTime),
176+
startDateTime: convertDateTimeLocalToISOString(formValues.startDateTime),
177+
endDateTime: convertDateTimeLocalToISOString(formValues.endDateTime),
173178
// Only include additionalData if round number is 0
174179
additionalData: Number(formValues.roundNumber) === 0 ? formValues.additionalData : {},
175180
};
@@ -483,6 +488,8 @@ export const AddEvent = ({
483488
try {
484489
const eventData = {
485490
...formValues,
491+
startDateTime: convertDateTimeLocalToISOString(formValues.startDateTime),
492+
endDateTime: convertDateTimeLocalToISOString(formValues.endDateTime),
486493
// Only include additionalData if round number is 0
487494
additionalData: Number(formValues.roundNumber) === 0 ? formValues.additionalData : {},
488495
};
@@ -794,13 +801,13 @@ const MakeJobOfferModal = ({
794801
]);
795802

796803
const makeOffer = async (salaryId: string) => {
797-
await postOnCampusOffer([
798-
{
799-
salaryId: salaryId,
800-
studentId: studentIds[0],
804+
await postOnCampusOffer(
805+
studentIds.map((studentId) => ({
806+
salaryId,
807+
studentId,
801808
status: "ACCEPTED",
802-
},
803-
]);
809+
})),
810+
);
804811
toast.success("Made a successful offer!");
805812
window.location.reload();
806813
};
@@ -809,7 +816,7 @@ const MakeJobOfferModal = ({
809816
const fetchSalaries = async () => {
810817
const salaries = await getStudentSalaryOffers(
811818
lastEvent.job.id,
812-
studentIds[0],
819+
studentIds[0],
813820
);
814821
const newSalaries = salaries.map((salary) => ({
815822
select: (

src/components/jobs/AddEventDialog.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ import { useState } from "react";
1515
import submit from "../action";
1616
import { createJobEvent } from "@/helpers/api";
1717
import toast from "react-hot-toast";
18+
19+
const convertDateTimeLocalToISOString = (date: string) => {
20+
return new Date(date).toISOString();
21+
};
22+
1823
interface Props {
1924
jobId: String;
2025
}
@@ -90,7 +95,7 @@ export function AddEventDialog({ jobId }: Props) {
9095
jobId,
9196
type,
9297
round,
93-
date,
98+
convertDateTimeLocalToISOString(date),
9499
);
95100
if (success) {
96101
submit("AllEvents");

0 commit comments

Comments
 (0)