-
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: active incidents for LEO dashboard (#1805)
- Loading branch information
Showing
10 changed files
with
199 additions
and
73 deletions.
There are no files selected for viewing
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
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
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
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
95 changes: 95 additions & 0 deletions
95
apps/client/src/components/dispatch/active-incidents/columns/actions-column.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,95 @@ | ||
import { Button } from "@snailycad/ui"; | ||
import { useActiveDispatchers } from "hooks/realtime/use-active-dispatchers"; | ||
import { useModal } from "state/modalState"; | ||
import { usePermission } from "hooks/usePermission"; | ||
import { useRouter } from "next/router"; | ||
import { defaultPermissions } from "@snailycad/permissions"; | ||
import type { ActiveOfficer } from "state/leo-state"; | ||
import type { ActiveDeputy } from "state/ems-fd-state"; | ||
import { LeoIncident, ShouldDoType } from "@snailycad/types"; | ||
import { ModalIds } from "types/modal-ids"; | ||
import { useTranslations } from "next-intl"; | ||
|
||
interface Props { | ||
incident: LeoIncident; | ||
unit: ActiveOfficer | ActiveDeputy | null; | ||
isUnitAssigned: boolean; | ||
setTempIncident(incident: LeoIncident): void; | ||
handleAssignUnassignToIncident( | ||
incident: LeoIncident, | ||
unitId: string, | ||
type: "assign" | "unassign", | ||
): void; | ||
} | ||
|
||
export function ActiveIncidentsActionsColumn({ | ||
setTempIncident, | ||
handleAssignUnassignToIncident, | ||
isUnitAssigned, | ||
unit, | ||
incident, | ||
}: Props) { | ||
const modalState = useModal(); | ||
const { hasActiveDispatchers } = useActiveDispatchers(); | ||
const { hasPermissions } = usePermission(); | ||
const router = useRouter(); | ||
|
||
const t = useTranslations("Leo"); | ||
const common = useTranslations("Common"); | ||
|
||
const hasDispatchPermissions = hasPermissions(defaultPermissions.defaultDispatchPermissions); | ||
const isDispatch = router.pathname === "/dispatch" && hasDispatchPermissions; | ||
|
||
const isUnitActive = unit?.status && unit.status.shouldDo !== ShouldDoType.SET_OFF_DUTY; | ||
|
||
function onEditClick(incident: LeoIncident) { | ||
modalState.openModal(ModalIds.ManageIncident); | ||
setTempIncident(incident); | ||
} | ||
|
||
function onEndClick(incident: LeoIncident) { | ||
modalState.openModal(ModalIds.AlertDeleteIncident); | ||
setTempIncident(incident); | ||
} | ||
|
||
return ( | ||
<> | ||
<Button | ||
isDisabled={isDispatch ? !hasActiveDispatchers : !isUnitActive} | ||
size="xs" | ||
variant="success" | ||
onPress={() => onEditClick(incident)} | ||
> | ||
{isDispatch ? common("manage") : common("view")} | ||
</Button> | ||
|
||
{isDispatch ? ( | ||
<Button | ||
onPress={() => onEndClick(incident)} | ||
isDisabled={!hasActiveDispatchers} | ||
size="xs" | ||
variant="danger" | ||
className="ml-2" | ||
> | ||
{t("end")} | ||
</Button> | ||
) : ( | ||
<Button | ||
className="ml-2" | ||
isDisabled={!isUnitActive} | ||
size="xs" | ||
onPress={() => | ||
unit && | ||
handleAssignUnassignToIncident( | ||
incident, | ||
unit.id, | ||
isUnitAssigned ? "unassign" : "assign", | ||
) | ||
} | ||
> | ||
{isUnitAssigned ? t("unassignFromIncident") : t("assignToIncident")} | ||
</Button> | ||
)} | ||
</> | ||
); | ||
} |
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
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
Oops, something went wrong.