Improvements on start button
This commit is contained in:
@@ -47,7 +47,7 @@ export default function AssignmentCreator({isCreating, assignment, user, groups,
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [startDate, setStartDate] = useState<Date | null>(assignment ? moment(assignment.startDate).toDate() : new Date());
|
const [startDate, setStartDate] = useState<Date | null>(assignment ? moment(assignment.startDate).toDate() : moment().add(1, 'hour').toDate());
|
||||||
|
|
||||||
const [endDate, setEndDate] = useState<Date | null>(
|
const [endDate, setEndDate] = useState<Date | null>(
|
||||||
assignment ? moment(assignment.endDate).toDate() : moment().hours(23).minutes(59).add(8, "day").toDate(),
|
assignment ? moment(assignment.endDate).toDate() : moment().hours(23).minutes(59).add(8, "day").toDate(),
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import {
|
|||||||
BsPen,
|
BsPen,
|
||||||
} from "react-icons/bs";
|
} from "react-icons/bs";
|
||||||
import { toast } from "react-toastify";
|
import { toast } from "react-toastify";
|
||||||
import { activeAssignmentFilter } from "@/utils/assignments";
|
import { futureAssignmentFilter } from "@/utils/assignments";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
@@ -296,11 +296,9 @@ export default function AssignmentView({ isOpen, assignment, onClose }: Props) {
|
|||||||
|
|
||||||
const shouldRenderStart = () => {
|
const shouldRenderStart = () => {
|
||||||
if (assignment) {
|
if (assignment) {
|
||||||
if (activeAssignmentFilter(assignment)) {
|
if (futureAssignmentFilter(assignment)) {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return assignment.results.length === 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
archivedAssignmentFilter,
|
archivedAssignmentFilter,
|
||||||
futureAssignmentFilter,
|
futureAssignmentFilter,
|
||||||
pastAssignmentFilter,
|
pastAssignmentFilter,
|
||||||
unstartedAssignmentFilter,
|
startHasExpiredAssignmentFilter,
|
||||||
} from "@/utils/assignments";
|
} from "@/utils/assignments";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { groupBy } from "lodash";
|
import { groupBy } from "lodash";
|
||||||
@@ -40,10 +40,10 @@ export default function AssignmentsPage({
|
|||||||
const [selectedAssignment, setSelectedAssignment] = useState<Assignment>();
|
const [selectedAssignment, setSelectedAssignment] = useState<Assignment>();
|
||||||
const [isCreatingAssignment, setIsCreatingAssignment] = useState(false);
|
const [isCreatingAssignment, setIsCreatingAssignment] = useState(false);
|
||||||
|
|
||||||
const unstartedAssignments = assignments.filter(unstartedAssignmentFilter);
|
|
||||||
|
|
||||||
const displayAssignmentView = !!selectedAssignment && !isCreatingAssignment;
|
const displayAssignmentView = !!selectedAssignment && !isCreatingAssignment;
|
||||||
|
|
||||||
|
const assignmentsPastExpiredStart = assignments.filter(startHasExpiredAssignmentFilter);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{displayAssignmentView && (
|
{displayAssignmentView && (
|
||||||
@@ -144,21 +144,6 @@ export default function AssignmentsPage({
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<section className="flex flex-col gap-4">
|
|
||||||
<h2 className="text-2xl font-semibold">
|
|
||||||
Active Assignments Pending Start ({unstartedAssignments.length})
|
|
||||||
</h2>
|
|
||||||
<div className="flex flex-wrap gap-2">
|
|
||||||
{unstartedAssignments.map((a) => (
|
|
||||||
<AssignmentCard
|
|
||||||
{...a}
|
|
||||||
users={users}
|
|
||||||
onClick={() => setSelectedAssignment(a)}
|
|
||||||
key={a.id}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
<section className="flex flex-col gap-4">
|
<section className="flex flex-col gap-4">
|
||||||
<h2 className="text-2xl font-semibold">
|
<h2 className="text-2xl font-semibold">
|
||||||
Planned Assignments (
|
Planned Assignments (
|
||||||
@@ -203,6 +188,25 @@ export default function AssignmentsPage({
|
|||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
</section>
|
||||||
|
<section className="flex flex-col gap-4">
|
||||||
|
<h2 className="text-2xl font-semibold">
|
||||||
|
Assignments start expired ({assignmentsPastExpiredStart.length})
|
||||||
|
</h2>
|
||||||
|
<div className="flex flex-wrap gap-2">
|
||||||
|
{assignments.filter(startHasExpiredAssignmentFilter).map((a) => (
|
||||||
|
<AssignmentCard
|
||||||
|
{...a}
|
||||||
|
users={users}
|
||||||
|
onClick={() => setSelectedAssignment(a)}
|
||||||
|
key={a.id}
|
||||||
|
allowDownload
|
||||||
|
reload={reloadAssignments}
|
||||||
|
allowArchive
|
||||||
|
allowExcelDownload
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<section className="flex flex-col gap-4">
|
<section className="flex flex-col gap-4">
|
||||||
<h2 className="text-2xl font-semibold">
|
<h2 className="text-2xl font-semibold">
|
||||||
|
|||||||
@@ -1,15 +1,29 @@
|
|||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import {Assignment} from "@/interfaces/results";
|
import {Assignment} from "@/interfaces/results";
|
||||||
|
|
||||||
export const futureAssignmentFilter = (a: Assignment) => {
|
// export const futureAssignmentFilter = (a: Assignment) => {
|
||||||
if(a.archived) return false;
|
// if(a.archived) return false;
|
||||||
if(a.start) return false;
|
// if(a.start) return false;
|
||||||
|
|
||||||
|
// const currentDate = moment();
|
||||||
|
// const startDate = moment(a.startDate);
|
||||||
|
// if(currentDate.isAfter(startDate)) return false;
|
||||||
|
// if(a.autoStart && a.autoStartDate) {
|
||||||
|
// return moment(a.autoStartDate).isAfter(currentDate);
|
||||||
|
// }
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
|
||||||
|
export const futureAssignmentFilter = (a: Assignment) => {
|
||||||
const currentDate = moment();
|
const currentDate = moment();
|
||||||
const startDate = moment(a.startDate);
|
if(moment(a.endDate).isBefore(currentDate)) return false;
|
||||||
if(startDate.isAfter(currentDate)) return true;
|
if(a.archived) return false;
|
||||||
if(a.autoStart && a.autoStartDate) {
|
|
||||||
return moment(a.autoStartDate).isAfter(currentDate);
|
if(a.autoStart && a.autoStartDate && moment(a.autoStartDate).isBefore(currentDate)) return false;
|
||||||
|
|
||||||
|
if(!a.start) {
|
||||||
|
if(moment(a.startDate).isBefore(currentDate)) return false;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -36,16 +50,28 @@ export const activeAssignmentFilter = (a: Assignment) => {
|
|||||||
return moment(a.autoStartDate).isBefore(currentDate);
|
return moment(a.autoStartDate).isBefore(currentDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if(currentDate.isAfter(moment(a.startDate))) return true;
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const unstartedAssignmentFilter = (a: Assignment) => {
|
// export const unstartedAssignmentFilter = (a: Assignment) => {
|
||||||
|
// const currentDate = moment();
|
||||||
|
// if(moment(a.endDate).isBefore(currentDate)) return false;
|
||||||
|
// if(a.archived) return false;
|
||||||
|
|
||||||
|
// if(a.autoStart && a.autoStartDate && moment(a.autoStartDate).isBefore(currentDate)) return false;
|
||||||
|
|
||||||
|
// if(!a.start) {
|
||||||
|
// if(moment(a.startDate).isBefore(currentDate)) return false;
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
|
||||||
|
export const startHasExpiredAssignmentFilter = (a: Assignment) => {
|
||||||
const currentDate = moment();
|
const currentDate = moment();
|
||||||
if(moment(a.endDate).isBefore(currentDate)) return false;
|
|
||||||
if(a.archived) return false;
|
if(a.archived) return false;
|
||||||
|
if(a.start) return false;
|
||||||
if(a.autoStart && a.autoStartDate && moment(a.autoStartDate).isBefore(currentDate)) return false;
|
if(currentDate.isAfter(moment(a.startDate)) && currentDate.isBefore(moment(a.endDate))) return true;
|
||||||
|
|
||||||
if(!a.start) return true;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user