diff --git a/src/components/AttachEvidenceDialog/index.tsx b/src/components/AttachEvidenceDialog/index.tsx index ea3333893..56e085549 100644 --- a/src/components/AttachEvidenceDialog/index.tsx +++ b/src/components/AttachEvidenceDialog/index.tsx @@ -1,8 +1,11 @@ +import { yupResolver } from "@hookform/resolvers/yup"; import { useCallback, useEffect, useState } from "react"; import { Controller, useForm } from "react-hook-form"; import * as yup from "yup"; -import { yupResolver } from "@hookform/resolvers/yup"; +import { useQueryClient } from "@tanstack/react-query"; +import { Link } from "react-router-dom"; +import { createIncidentQueryKey } from "../../api/query-hooks"; import { createEvidence } from "../../api/services/evidence"; import { createHypothesis, @@ -13,24 +16,21 @@ import { } from "../../api/services/hypothesis"; import { createIncident, - searchIncident, IncidentSeverity, - IncidentStatus + IncidentStatus, + searchIncident } from "../../api/services/incident"; import { useUser } from "../../context"; -import { TextInput } from "../TextInput"; -import { Modal } from "../Modal"; +import { Events, sendAnalyticEvent } from "../../services/analytics"; +import { IItem } from "../../types/IItem"; import { DropdownWithActions } from "../Dropdown/DropdownWithActions"; -import { IncidentStatusTag } from "../IncidentStatusTag"; +import SelectDropdown from "../Dropdown/SelectDropdown"; +import { severityItems, typeItems } from "../Incidents/data"; import { IncidentSeverityTag } from "../IncidentSeverityTag"; -import { IItem } from "../../types/IItem"; +import { IncidentStatusTag } from "../IncidentStatusTag"; +import { Modal } from "../Modal"; +import { TextInput } from "../TextInput"; import { toastSuccess } from "../Toast/toast"; -import { Link } from "react-router-dom"; -import { severityItems, typeItems } from "../Incidents/data"; -import { ReactSelectDropdown } from "../ReactSelectDropdown"; -import { useQueryClient } from "@tanstack/react-query"; -import { createIncidentQueryKey } from "../../api/query-hooks"; -import { Events, sendAnalyticEvent } from "../../services/analytics"; interface Props { title?: string; @@ -141,6 +141,22 @@ const validationSchema = yup }) .required(); +export const severityOptions = Object.entries(severityItems).map( + ([_, { value, description, icon }]) => ({ + value, + label: description, + icon + }) +); + +export const typeOptions = Object.entries(typeItems).map( + ([_, { value, description, icon }]) => ({ + value, + label: description, + icon + }) +); + export function AttachEvidenceDialog({ title = "Link to Incident", config_id, @@ -394,13 +410,15 @@ export function AttachEvidenceDialog({ Type - { + if (!e) return; + setValue("type", e); + }} />

{errors.type?.message} @@ -414,13 +432,15 @@ export function AttachEvidenceDialog({ Severity - { + if (!e) return; + setValue("severity", e); + }} />

{errors.severity?.message} diff --git a/src/components/Dropdown/SelectDropdown.tsx b/src/components/Dropdown/SelectDropdown.tsx new file mode 100644 index 000000000..93aeee08f --- /dev/null +++ b/src/components/Dropdown/SelectDropdown.tsx @@ -0,0 +1,62 @@ +import clsx from "clsx"; +import { ComponentProps } from "react"; +import Select, { components } from "react-select"; + +type SelectDropdownProps = { + options: { + label: string; + value: TValue; + icon?: React.ReactNode; + }[]; + value?: TValue; + onChange: (value: TValue) => void; +} & Omit, "onChange" | "value" | "options">; + +export default function SelectDropdown({ + options, + value, + onChange = () => {}, + ...props +}: SelectDropdownProps) { + return ( +