Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions apps/admin/src/animals/situation/db.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type SituationKeys =
| "comments"
| "diagnosis"
| "fosterFamilyId"
| "freeCity"
| "freeComment"
| "isSterilizationMandatory"
| "isSterilized"
| "isVaccinationMandatory"
Expand Down Expand Up @@ -144,6 +146,11 @@ export class AnimalSituationDbDelegate {
data.adoptionOption = null
}

if (data.status !== Status.FREE) {
data.freeCity = null
data.freeComment = null
}

if (!ACTIVE_ANIMAL_STATUS.includes(data.status)) {
data.fosterFamilyId = null
}
Expand Down
41 changes: 41 additions & 0 deletions apps/admin/src/animals/situation/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export const ActionFormData = FormDataDelegate.create(
comments: zu.string().trim(),
diagnosis: zu.nativeEnum(Diagnosis).default(Diagnosis.UNKNOWN),
fosterFamilyId: zu.string().uuid().optional(),
freeCity: zu.string().trim().optional(),
freeComment: zu.string().trim().optional(),
isSterilized: zu.enum(["YES", "NO", "NOT_MANDATORY"], {
required_error: "Veuillez choisir une option",
}),
Expand Down Expand Up @@ -103,6 +105,8 @@ type DefaultAnimal = null | SerializeFrom<
| "adoptionOption"
| "comments"
| "diagnosis"
| "freeCity"
| "freeComment"
| "gender"
| "isSterilizationMandatory"
| "isSterilized"
Expand Down Expand Up @@ -198,6 +202,43 @@ export function AnimalSituationForm({
</>
) : null}

{statusState === Status.FREE &&
defaultAnimal?.species === Species.CAT ? (
<>
<Separator />

<Form.Field>
<Form.Label htmlFor={ActionFormData.keys.freeCity}>
Ville
</Form.Label>

<Input
id={ActionFormData.keys.freeCity}
name={ActionFormData.keys.freeCity}
defaultValue={defaultAnimal?.freeCity ?? undefined}
leftAdornment={
<Input.Adornment>
<Icon href="icon-location-dot-solid" />
</Input.Adornment>
}
/>
</Form.Field>

<Form.Field>
<Form.Label htmlFor={ActionFormData.keys.freeComment}>
Informations complémentaires
</Form.Label>

<Textarea
id={ActionFormData.keys.freeComment}
name={ActionFormData.keys.freeComment}
defaultValue={defaultAnimal?.freeComment ?? undefined}
rows={5}
/>
</Form.Field>
</>
) : null}

<Form.Field>
<Form.Label>
Statut <RequiredStar />
Expand Down
2 changes: 2 additions & 0 deletions apps/admin/src/routes/_layout.animals.$id._index/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
breed: { select: { name: true } },
color: { select: { name: true } },
description: true,
freeCity: true,
freeComment: true,
gender: true,
id: true,
isOkCats: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,23 @@ export function SituationCard() {
)
</>
) : null}
{animal.status === Status.FREE && animal.freeCity != null ? (
<>
{" "}
à{" "}
<strong className="text-body-emphasis">
{animal.freeCity}
</strong>
</>
) : null}
</SimpleItem>

{animal.status === Status.FREE && animal.freeComment != null ? (
<SimpleItem icon={<Icon href="icon-comment-solid" />}>
{animal.freeComment}
</SimpleItem>
) : null}

{animal.fosterFamily != null ? (
<DropdownSheet>
<SimpleItem
Expand Down
4 changes: 4 additions & 0 deletions apps/admin/src/routes/_layout.animals.$id.edit.situation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
comments: true,
diagnosis: true,
fosterFamily: { select: { id: true, displayName: true } },
freeCity: true,
freeComment: true,
gender: true,
isSterilizationMandatory: true,
isSterilized: true,
Expand Down Expand Up @@ -135,6 +137,8 @@ export async function action({ request, params }: ActionFunctionArgs) {
comments: formData.data.comments || null,
diagnosis: formData.data.diagnosis,
fosterFamilyId: formData.data.fosterFamilyId ?? null,
freeCity: formData.data.freeCity || null,
freeComment: formData.data.freeComment || null,
isSterilizationMandatory:
formData.data.isSterilized !==
ActionFormData.schema.shape.isSterilized.Enum.NOT_MANDATORY,
Expand Down
2 changes: 2 additions & 0 deletions apps/admin/src/routes/_layout.animals.new.situation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ export async function action({ request }: ActionFunctionArgs) {
comments: formData.data.comments || null,
diagnosis: formData.data.diagnosis,
fosterFamilyId: formData.data.fosterFamilyId ?? null,
freeCity: formData.data.freeCity || null,
freeComment: formData.data.freeComment || null,
isSterilizationMandatory:
formData.data.isSterilized !==
ActionFormData.schema.shape.isSterilized.Enum.NOT_MANDATORY,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- AlterTable
ALTER TABLE "Animal" ADD COLUMN "freeCity" VARCHAR(255),
ADD COLUMN "freeComment" TEXT;

-- AlterTable
ALTER TABLE "AnimalDraft" ADD COLUMN "freeCity" VARCHAR(255),
ADD COLUMN "freeComment" TEXT;
4 changes: 4 additions & 0 deletions libs/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ model Animal {
diagnosis Diagnosis @default(UNKNOWN)
fosterFamily FosterFamily? @relation(fields: [fosterFamilyId], references: [id], onDelete: Restrict)
fosterFamilyId String?
freeCity String? @db.VarChar(255)
freeComment String?
gender Gender
iCadNumber String?
isOkCats Boolean?
Expand Down Expand Up @@ -213,6 +215,8 @@ model AnimalDraft {
diagnosis Diagnosis? @default(UNKNOWN)
fosterFamily FosterFamily? @relation(fields: [fosterFamilyId], references: [id])
fosterFamilyId String?
freeCity String? @db.VarChar(255)
freeComment String?
gender Gender?
iCadNumber String?
isOkCats Boolean?
Expand Down
Loading