Skip to content

Commit

Permalink
fix: unable to create citizen with license data
Browse files Browse the repository at this point in the history
  • Loading branch information
casperiv0 committed Jun 21, 2023
1 parent fa0e9c6 commit 6fcd112
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 39 deletions.
6 changes: 4 additions & 2 deletions apps/api/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,13 @@ export class Server {
version: z.string().optional(),
});

s.parse(body);
const data = await s.safeParseAsync(body);

if (!data.success) return;

await request(URL, {
method: "POST",
body: JSON.stringify(body),
body: JSON.stringify(data.data),
headers: {
"Content-Type": "application/json",
},
Expand Down
6 changes: 1 addition & 5 deletions apps/client/src/components/citizen/ManageCitizenForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,7 @@ export function ManageCitizenForm({

{formFeatures?.["license-fields"] && features.ALLOW_CITIZEN_UPDATE_LICENSE ? (
<MultiFormStep id="license-information" title={t("licenseInformation")}>
{() => (
<FormRow>
<ManageLicensesFormFields flexType="column" isLeo={false} allowRemoval />
</FormRow>
)}
{() => <ManageLicensesFormFields flexType="column" isLeo={false} allowRemoval />}
</MultiFormStep>
) : null}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useFormikContext } from "formik";
import { useFeatureEnabled } from "hooks/useFeatureEnabled";
import { useTranslations } from "next-intl";
import { filterLicenseType, filterLicenseTypes } from "lib/utils";
import { classNames } from "lib/classNames";
import type { LicenseInitialValues } from "./manage-licenses-modal";
import { FormRow, DatePickerField, SwitchField, SelectField } from "@snailycad/ui";
import { ValueSelectField } from "components/form/inputs/value-select-field";
Expand Down Expand Up @@ -50,17 +49,13 @@ interface Props {
flexType: "row" | "column";
}

export function ManageLicensesFormFields({ isLeo, allowRemoval, flexType }: Props) {
export function ManageLicensesFormFields({ isLeo, allowRemoval }: Props) {
const { values, setFieldValue, errors } =
useFormikContext<ReturnType<typeof createDefaultLicensesValues>>();

const { license, driverslicenseCategory } = useValues();
const t = useTranslations();
const { WEAPON_REGISTRATION, LICENSE_EXAMS } = useFeatureEnabled();
const formRowClassName = classNames(
"w-full",
flexType === "row" ? "grid grid-cols-2 gap-2" : "flex flex-col",
);

return (
<>
Expand Down Expand Up @@ -93,7 +88,7 @@ export function ManageLicensesFormFields({ isLeo, allowRemoval, flexType }: Prop
</FormRow>
) : null}

<div className={formRowClassName}>
<FormRow>
<ValueSelectField
isDisabled={values.suspended.driverLicense}
isClearable={allowRemoval}
Expand All @@ -120,7 +115,7 @@ export function ManageLicensesFormFields({ isLeo, allowRemoval, flexType }: Prop
description: value.description,
}))}
/>
</div>
</FormRow>

{!isLeo && values.suspended.driverLicense ? (
<p className="-mt-2 text-base mb-3 text-neutral-700 dark:text-gray-400">
Expand Down Expand Up @@ -162,7 +157,7 @@ export function ManageLicensesFormFields({ isLeo, allowRemoval, flexType }: Prop
</FormRow>
) : null}

<div className={formRowClassName}>
<FormRow>
<ValueSelectField
isDisabled={values.suspended.pilotLicense}
isClearable={allowRemoval}
Expand All @@ -189,7 +184,7 @@ export function ManageLicensesFormFields({ isLeo, allowRemoval, flexType }: Prop
description: value.description,
}))}
/>
</div>
</FormRow>

{!isLeo && values.suspended.pilotLicense ? (
<p className="-mt-2 text-base mb-3 text-neutral-700 dark:text-gray-400">
Expand Down Expand Up @@ -228,7 +223,7 @@ export function ManageLicensesFormFields({ isLeo, allowRemoval, flexType }: Prop
</FormRow>
) : null}

<div className={formRowClassName}>
<FormRow>
<ValueSelectField
isClearable={allowRemoval}
fieldName="waterLicense"
Expand All @@ -255,7 +250,7 @@ export function ManageLicensesFormFields({ isLeo, allowRemoval, flexType }: Prop
description: value.description,
}))}
/>
</div>
</FormRow>

{!isLeo && values.suspended.waterLicense ? (
<p className="-mt-2 text-base mb-3 text-neutral-700 dark:text-gray-400">
Expand Down Expand Up @@ -295,7 +290,7 @@ export function ManageLicensesFormFields({ isLeo, allowRemoval, flexType }: Prop
</FormRow>
) : null}

<div className={formRowClassName}>
<FormRow>
<ValueSelectField
isClearable={allowRemoval}
fieldName="weaponLicense"
Expand All @@ -322,7 +317,7 @@ export function ManageLicensesFormFields({ isLeo, allowRemoval, flexType }: Prop
description: value.description,
}))}
/>
</div>
</FormRow>

{!isLeo && values.suspended.firearmsLicense ? (
<p className="-mt-2 text-base mb-3 text-neutral-700 dark:text-gray-400">
Expand Down
17 changes: 1 addition & 16 deletions apps/client/src/pages/citizen/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { getTranslations } from "lib/getTranslation";
import { requestAll } from "lib/utils";
import { Title } from "components/shared/Title";
import { ManageCitizenForm } from "components/citizen/ManageCitizenForm";
import type { SelectValue } from "components/form/Select";
import type { PostCitizenImageByIdData, PostCitizensData } from "@snailycad/types/api";
import { BreadcrumbItem, Breadcrumbs } from "@snailycad/ui";

Expand All @@ -30,21 +29,7 @@ export default function CreateCitizen() {
path: "/citizen",
method: "POST",
helpers,
data: {
...data,
driversLicenseCategory: Array.isArray(data.driversLicenseCategory)
? (data.driversLicenseCategory as SelectValue[]).map((v) => v.value)
: data.driversLicenseCategory,
pilotLicenseCategory: Array.isArray(data.pilotLicenseCategory)
? (data.pilotLicenseCategory as SelectValue[]).map((v) => v.value)
: data.pilotLicenseCategory,
waterLicenseCategory: Array.isArray(data.waterLicenseCategory)
? (data.waterLicenseCategory as SelectValue[]).map((v) => v.value)
: data.waterLicenseCategory,
firearmLicenseCategory: Array.isArray(data.firearmLicenseCategory)
? (data.firearmLicenseCategory as SelectValue[]).map((v) => v.value)
: data.firearmLicenseCategory,
},
data,
});

const errors = ["dateLargerThanNow", "nameAlreadyTaken", "invalidImageType"];
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/fields/select-field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export function SelectField<T extends SelectValue>(props: SelectFieldProps<T>) {
variant: "default",
size: "sm",
className: cn(
"px-2 cursor-default !rounded-r-none w-full min-h-[40px] h-auto flex items-center justify-between border !bg-white dark:!bg-secondary hover:dark:!bg-secondary hover:dark:!brightness-100 group-hover:dark:!border-gray-500 group-hover:!border-gray-500",
"px-2 cursor-default !rounded-r-none w-full min-h-[39px] h-auto flex items-center justify-between border !bg-white dark:!bg-secondary hover:dark:!bg-secondary hover:dark:!brightness-100 group-hover:dark:!border-gray-500 group-hover:!border-gray-500",
props.errorMessage &&
"!border-red-500 focus:!border-red-700 dark:focus:!border-red-700",
state.isOpen && "dark:!border-gray-500 !border-gray-500",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function SelectedItems<T extends SelectValue>(props: Props<T>) {

return (
<span
className="text-sm flex items-center justify-between p-0.5 px-1.5 rounded-sm bg-gray-300 dark:bg-tertiary"
className="text-sm flex items-center justify-between px-1.5 rounded-sm bg-gray-300 dark:bg-tertiary"
key={item.key}
>
<HoverCard open={option?.description ? undefined : false}>
Expand Down

0 comments on commit 6fcd112

Please sign in to comment.