Skip to content

Commit

Permalink
feat: updated switch field
Browse files Browse the repository at this point in the history
  • Loading branch information
casperiv0 committed Apr 15, 2023
1 parent afa0d9c commit e120e4b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import { FormField } from "components/form/FormField";
import { Select } from "components/form/Select";
import { filterLicenseType, filterLicenseTypes } from "lib/utils";
import { classNames } from "lib/classNames";
import { Toggle } from "components/form/Toggle";
import type { LicenseInitialValues } from "./manage-licenses-modal";
import { FormRow } from "components/form/FormRow";
import { DatePickerField } from "@snailycad/ui";
import { DatePickerField, SwitchField } from "@snailycad/ui";
import { ValueSelectField } from "components/form/inputs/value-select-field";

export function createDefaultLicensesValues(citizen: Citizen | null): LicenseInitialValues {
Expand Down Expand Up @@ -89,14 +88,12 @@ export function ManageLicensesFormFields({ isLeo, allowRemoval, flexType }: Prop
<section className="w-full">
{isLeo ? (
<FormRow>
<FormField label={t("Leo.suspendDriversLicense")}>
<Toggle
onCheckedChange={handleChange}
name="suspended.driverLicense"
value={values.suspended.driverLicense}
onChange={handleChange}
/>
</FormField>
<SwitchField
isSelected={values.suspended.driverLicense}
onChange={(isSelected) => setFieldValue("suspended.driverLicense", isSelected)}
>
{t("Leo.suspendDriversLicense")}
</SwitchField>

{values.suspended.driverLicense ? (
<DatePickerField
Expand Down Expand Up @@ -163,14 +160,12 @@ export function ManageLicensesFormFields({ isLeo, allowRemoval, flexType }: Prop
<section className="w-full">
{isLeo ? (
<FormRow>
<FormField label={t("Leo.suspendPilotLicense")} checkbox>
<Toggle
onCheckedChange={handleChange}
name="suspended.pilotLicense"
value={values.suspended.pilotLicense}
onChange={handleChange}
/>
</FormField>
<SwitchField
isSelected={values.suspended.pilotLicense}
onChange={(isSelected) => setFieldValue("suspended.pilotLicense", isSelected)}
>
{t("Leo.suspendPilotLicense")}
</SwitchField>

{values.suspended.pilotLicense ? (
<DatePickerField
Expand Down Expand Up @@ -234,14 +229,12 @@ export function ManageLicensesFormFields({ isLeo, allowRemoval, flexType }: Prop
<section className="w-full">
{isLeo ? (
<FormRow>
<FormField label={t("Leo.suspendWaterLicense")} checkbox>
<Toggle
onCheckedChange={handleChange}
name="suspended.waterLicense"
value={values.suspended.waterLicense}
onChange={handleChange}
/>
</FormField>
<SwitchField
isSelected={values.suspended.waterLicense}
onChange={(isSelected) => setFieldValue("suspended.waterLicense", isSelected)}
>
{t("Leo.suspendWaterLicense")}
</SwitchField>

{values.suspended.waterLicense ? (
<DatePickerField
Expand Down Expand Up @@ -306,14 +299,12 @@ export function ManageLicensesFormFields({ isLeo, allowRemoval, flexType }: Prop
<section className="w-full">
{isLeo ? (
<FormRow>
<FormField label={t("Leo.suspendFirearmsLicense")} checkbox>
<Toggle
onCheckedChange={handleChange}
name="suspended.firearmsLicense"
value={values.suspended.firearmsLicense}
onChange={handleChange}
/>
</FormField>
<SwitchField
isSelected={values.suspended.firearmsLicense}
onChange={(isSelected) => setFieldValue("suspended.firearmsLicense", isSelected)}
>
{t("Leo.suspendFirearmsLicense")}
</SwitchField>

{values.suspended.firearmsLicense ? (
<DatePickerField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Loader,
SelectField,
TextField,
SwitchField,
} from "@snailycad/ui";
import { FormField } from "components/form/FormField";
import { Modal } from "components/modal/Modal";
Expand All @@ -27,7 +28,6 @@ import { handleValidate } from "lib/handleValidate";
import { useCitizen } from "context/CitizenContext";
import { useRouter } from "next/router";
import { useAuth } from "context/AuthContext";
import { Toggle } from "components/form/Toggle";
import { useFeatureEnabled } from "hooks/useFeatureEnabled";
import { useBusinessState } from "state/business-state";
import { filterLicenseType, filterLicenseTypes } from "lib/utils";
Expand Down Expand Up @@ -301,22 +301,20 @@ export function RegisterVehicleModal({ vehicle, onClose, onCreate, onUpdate }: P

{vehicle ? (
<FormRow>
<FormField errorMessage={errors.reportedStolen} label={tVehicle("reportAsStolen")}>
<Toggle
onCheckedChange={handleChange}
name="reportedStolen"
value={values.reportedStolen}
/>
</FormField>
<SwitchField
isSelected={values.reportedStolen}
onChange={(isSelected) => setFieldValue("reportedStolen", isSelected)}
>
{tVehicle("reportAsStolen")}
</SwitchField>

<FormField errorMessage={errors.reApplyForDmv} label={tVehicle("reApplyForDmv")}>
<Toggle
disabled={vehicle.dmvStatus !== WhitelistStatus.DECLINED}
onCheckedChange={handleChange}
name="reApplyForDmv"
value={values.reApplyForDmv ?? false}
/>
</FormField>
<SwitchField
isSelected={values.reApplyForDmv}
onChange={(isSelected) => setFieldValue("reApplyForDmv", isSelected)}
isDisabled={vehicle.dmvStatus !== WhitelistStatus.DECLINED}
>
{tVehicle("reApplyForDmv")}
</SwitchField>
</FormRow>
) : null}

Expand Down

0 comments on commit e120e4b

Please sign in to comment.