+
setOpen(true)} onChange={handleChange} />
- {suggestions.length > 0 ? (
-
+ {isOpen && suggestions.length > 0 ? (
+
{suggestions.map((suggestion) => (
- onSuggestionClick?.(suggestion)}
+ onClick={() => handleSuggestionClick(suggestion)}
>
{Component ? (
diff --git a/yarn.lock b/yarn.lock
index f951bae50..92f95a517 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1067,6 +1067,7 @@ __metadata:
react: ^17.0.2
react-bootstrap-icons: ^1.6.1
react-colorful: ^5.5.0
+ react-cool-onclickoutside: ^1.7.0
react-dom: ^17.0.2
react-hot-toast: ^2.1.1
react-markdown: ^7.1.0
@@ -8674,6 +8675,15 @@ __metadata:
languageName: node
linkType: hard
+"react-cool-onclickoutside@npm:^1.7.0":
+ version: 1.7.0
+ resolution: "react-cool-onclickoutside@npm:1.7.0"
+ peerDependencies:
+ react: ">= 16.8.0"
+ checksum: 52041d867ff275ee9e925b2fc0616febd17964a372b2319007e4c8ae375a9c583da79ab0f27238a36d7fb7e486ec2293f94b2a2362e9c48db44303884c97b2d4
+ languageName: node
+ linkType: hard
+
"react-dom@npm:^17.0.2":
version: 17.0.2
resolution: "react-dom@npm:17.0.2"
From 602598f7fc13cdcefbcfd860c3cc9c22244902e1 Mon Sep 17 00:00:00 2001
From: Dev-CasperTheGhost
<53900565+Dev-CasperTheGhost@users.noreply.github.com>
Date: Wed, 10 Nov 2021 13:39:27 +0100
Subject: [PATCH 3/5] :tada: implement suggestions input
---
.../controllers/record/RecordsController.ts | 2 +-
packages/client/locales/en/common.json | 3 +-
.../leo/modals/CreateTicketModal.tsx | 60 ++++++++++++++-----
.../NameSearchModal/NameSearchModal.tsx | 7 ++-
packages/schemas/src/records.ts | 1 +
5 files changed, 54 insertions(+), 19 deletions(-)
diff --git a/packages/api/src/controllers/record/RecordsController.ts b/packages/api/src/controllers/record/RecordsController.ts
index 7a83b31c8..0f996e803 100644
--- a/packages/api/src/controllers/record/RecordsController.ts
+++ b/packages/api/src/controllers/record/RecordsController.ts
@@ -53,7 +53,7 @@ export class RecordsController {
},
});
- if (!citizen) {
+ if (!citizen || `${citizen.name} ${citizen.surname}` !== body.get("citizenName")) {
throw new NotFound("citizenNotFound");
}
diff --git a/packages/client/locales/en/common.json b/packages/client/locales/en/common.json
index 70243a058..20f6bfafa 100644
--- a/packages/client/locales/en/common.json
+++ b/packages/client/locales/en/common.json
@@ -50,6 +50,7 @@
"dateLargerThanNow": "Please provide a date smaller than the current date.",
"divisionNotInDepartment": "This division does not exist in this department.",
"passwordsDoNotMatch": "Passwords do not match",
- "currentPasswordIncorrect": "Current password is incorrect"
+ "currentPasswordIncorrect": "Current password is incorrect",
+ "citizenNotFound": "That citizen was not found"
}
}
diff --git a/packages/client/src/components/leo/modals/CreateTicketModal.tsx b/packages/client/src/components/leo/modals/CreateTicketModal.tsx
index f402f6464..83ce3dcf3 100644
--- a/packages/client/src/components/leo/modals/CreateTicketModal.tsx
+++ b/packages/client/src/components/leo/modals/CreateTicketModal.tsx
@@ -14,8 +14,10 @@ import useFetch from "lib/useFetch";
import { ModalIds } from "types/ModalIds";
import { useTranslations } from "use-intl";
import { Textarea } from "components/form/Textarea";
-import { useCitizen } from "context/CitizenContext";
-import { RecordType } from "types/prisma";
+import { Citizen, RecordType } from "types/prisma";
+import { InputSuggestions } from "components/form/InputSuggestions";
+import { PersonFill } from "react-bootstrap-icons";
+import { useImageUrl } from "hooks/useImageUrl";
export const CreateTicketModal = ({ type }: { type: RecordType }) => {
const { isOpen, closeModal, getPayload } = useModal();
@@ -39,7 +41,7 @@ export const CreateTicketModal = ({ type }: { type: RecordType }) => {
const { state, execute } = useFetch();
const { penalCode } = useValues();
- const { citizens } = useCitizen();
+ const { makeImageUrl } = useImageUrl();
async function onSubmit(values: typeof INITIAL_VALUES) {
const { json } = await execute("/records", {
@@ -56,10 +58,12 @@ export const CreateTicketModal = ({ type }: { type: RecordType }) => {
}
}
+ const payload = getPayload<{ citizenId: string; citizenName: string }>(data[type].id);
const validate = handleValidate(CREATE_TICKET_SCHEMA);
const INITIAL_VALUES = {
type,
- citizenId: getPayload<{ citizenId: string }>(data[type].id)?.citizenId ?? "",
+ citizenId: payload?.citizenId ?? "",
+ citizenName: payload?.citizenName ?? "",
violations: [] as SelectValue[],
postal: "",
notes: "",
@@ -73,18 +77,44 @@ export const CreateTicketModal = ({ type }: { type: RecordType }) => {
className="w-[600px]"
>
- {({ handleChange, errors, values, isValid }) => (
+ {({ handleChange, setFieldValue, errors, values, isValid }) => (