Skip to content

Commit

Permalink
feat: only allow signing in if compulsory trainings are completed
Browse files Browse the repository at this point in the history
  • Loading branch information
Gobot1234 committed Apr 20, 2024
1 parent f2fe368 commit 78afb6e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface ToolSelectionListProps {
title: string;
toolTipContent: string;
selectable?: boolean;
userHasCompulsoryTraining?: boolean;
onTrainingSelect?: (selectedTrainings: Training[]) => void;
}

Expand All @@ -21,6 +22,7 @@ const TrainingSelectionList: React.FC<ToolSelectionListProps> = ({
title,
toolTipContent,
selectable,
userHasCompulsoryTraining,
onTrainingSelect,
}) => {
const [selectedTrainings, setSelectedTrainings] = useState<string[]>([]);
Expand Down Expand Up @@ -69,6 +71,12 @@ const TrainingSelectionList: React.FC<ToolSelectionListProps> = ({
<AlertTitle>Warning</AlertTitle>
<AlertDescription>No training available to select.</AlertDescription>
</Alert>
) : userHasCompulsoryTraining === true ? (
<Alert variant="default">
<ExclamationTriangleIcon className="h-4 w-4" />
<AlertTitle>Warning</AlertTitle>
<AlertDescription>Compulsory trainings have not been completed.</AlertDescription>
</Alert>
) : (
trainings.map((training) => (
<React.Fragment key={training.id}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { errorDisplay } from "@/components/errors/ErrorDisplay";
import { FlowStepComponent } from "@/components/signin/actions/SignInManager/types.ts";
import { SelectedTrainingPipDisplay } from "@/components/signin/actions/ToolSelectionInput/SelectedTrainingPipDisplay.tsx";
import ToolSelectionList from "@/components/signin/actions/ToolSelectionInput/TrainingSelectionList.tsx";
Expand All @@ -13,7 +14,6 @@ import { Loader } from "@ui/components/ui/loader.tsx";
import { ChevronsDownUp, ChevronsUpDown } from "lucide-react";
import { useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { errorDisplay } from "@/components/errors/ErrorDisplay";

/*
three categories of tools that can be selected:
Expand Down Expand Up @@ -133,6 +133,8 @@ const ToolSelectionInput: FlowStepComponent = ({ onSecondary, onPrimary }) => {
}
};

const userHasCompulsoryTraining = trainingMap.DISABLED.some((training) => training.compulsory);

const toolSelectionDisplay = (
<>
<Collapsible open={isOpen} onOpenChange={setIsOpen} className="w-full space-y-2">
Expand All @@ -149,6 +151,7 @@ const ToolSelectionInput: FlowStepComponent = ({ onSecondary, onPrimary }) => {
title="Selectable Training"
trainings={trainingMap.SELECTABLE}
selectable={true}
userHasRequiredTraining={userHasCompulsoryTraining}
onTrainingSelect={handleOnTrainingSelect}
toolTipContent="Tools that the user has training for, and reps are trained on the tool"
/>
Expand Down

0 comments on commit 78afb6e

Please sign in to comment.