-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38e8ad3
commit 7bccf65
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
...nt/src/app/pages/applications/assessment-actions/components/dynamic-assessment-button.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Application, Assessment, Questionnaire } from "@app/api/models"; | ||
import { useFetchAssessmentsByAppId } from "@app/queries/assessments"; | ||
import { Button } from "@patternfly/react-core"; | ||
import { Td } from "@patternfly/react-table"; | ||
import React, { FunctionComponent } from "react"; | ||
|
||
interface DynamicAssessmentButtonProps { | ||
questionnaire: Questionnaire; | ||
application: Application; | ||
handleAssessmentAction: ( | ||
questionnaire: Questionnaire, | ||
assessment: Assessment, | ||
action: any | ||
) => void; | ||
} | ||
|
||
const DynamicAssessmentButton: FunctionComponent< | ||
DynamicAssessmentButtonProps | ||
> = ({ questionnaire, application, handleAssessmentAction }) => { | ||
const { assessments } = useFetchAssessmentsByAppId(application?.id); | ||
const matchingAssessment = assessments?.find( | ||
(assessment) => assessment.questionnaire.id === questionnaire.id | ||
); | ||
|
||
// const actionName = status === "active" ? "Take" : "View"; // Dynamic action name based on status | ||
|
||
return ( | ||
<Td> | ||
<Button | ||
type="button" | ||
variant="primary" | ||
onClick={() => { | ||
if (matchingAssessment) { | ||
handleAssessmentAction(questionnaire, matchingAssessment, "take"); | ||
} | ||
}} | ||
// disabled={!matchingAssessment} | ||
> | ||
{/* {actionName} */} | ||
</Button> | ||
</Td> | ||
); | ||
}; | ||
|
||
export default DynamicAssessmentButton; |