Skip to content

Commit

Permalink
fix: use types from electric-client package
Browse files Browse the repository at this point in the history
  • Loading branch information
ledouxm committed Apr 30, 2024
1 parent be49882 commit f32c730
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion packages/frontend/src/components/chips/ContactChips.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useFormContext, useWatch } from "react-hook-form";
import type { Report } from "../../generated/client";
import type { Report } from "@cr-vif/electric-client/frontend";
import { ChipGroup, type ChipGroupOption } from "../Chip";

export const ContactChips = () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/components/chips/DecisionChips.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useFormContext, useWatch } from "react-hook-form";
import type { Report } from "../../generated/client";
import type { Report } from "@cr-vif/electric-client/frontend";
import { ChipGroup, type ChipGroupOption } from "../Chip";

export const DecisionChips = () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/frontend/src/components/chips/FurtherInfoChips.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useFormContext, useWatch } from "react-hook-form";
import type { Report } from "../../generated/client";
import type { Report } from "@cr-vif/electric-client/frontend";
import { ChipGroup, type ChipGroupOption } from "../Chip";

export const FurtherInfoChips = () => {
const form = useFormContext<Report>();

const selected = useWatch({ control: form.control, name: "further_information" })?.split(",") ?? [];
const selected = useWatch({ control: form.control, name: "furtherInformation" })?.split(",") ?? [];

const furtherInfoOptions: ChipGroupOption[] = [
{ label: "Aller plus loin 1", key: "furtherInfo1" },
Expand All @@ -24,7 +24,7 @@ export const FurtherInfoChips = () => {
isMulti
options={furtherInfoOptions}
value={selected}
onChange={(values) => form.setValue("further_information", values.join(","))}
onChange={(values) => form.setValue("furtherInformation", values.join(","))}
label="Pour aller plus loin"
/>
);
Expand Down
6 changes: 3 additions & 3 deletions packages/frontend/src/components/chips/SpaceTypeChips.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useFormContext, useWatch } from "react-hook-form";
import type { Report } from "../../generated/client";
import type { Report } from "@cr-vif/electric-client/frontend";
import { ChipGroup, type ChipGroupOption } from "../Chip";

export const SpaceTypeChips = () => {
const form = useFormContext<Report>();

const selected = useWatch({ control: form.control, name: "project_space_type" })?.split(",") ?? [];
const selected = useWatch({ control: form.control, name: "projectSpaceType" })?.split(",") ?? [];

const spaceTypes: ChipGroupOption[] = [
{ label: "PSMV", key: "psmv" },
Expand All @@ -24,7 +24,7 @@ export const SpaceTypeChips = () => {
isMulti
options={spaceTypes}
value={selected}
onChange={(values) => form.setValue("project_space_type", values.join(","))}
onChange={(values) => form.setValue("projectSpaceType", values.join(","))}
label="Type d'espace"
/>
);
Expand Down
20 changes: 10 additions & 10 deletions packages/frontend/src/features/InfoForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import { useFormContext, useWatch } from "react-hook-form";
import { InputGroupWithTitle } from "../components/InputGroup";
import { SpaceTypeChips } from "../components/chips/SpaceTypeChips";
import { useUser } from "../contexts/AuthContext";
import type { Report } from "../generated/client";
import type { Report } from "@cr-vif/electric-client/frontend";

export const InfoForm = () => {
const form = useFormContext<Report>();
const user = useUser()!;

const meetDate = useWatch({ control: form.control, name: "meet_date" });
const meetDate = useWatch({ control: form.control, name: "meetDate" });

const meetDateRef = useRef({
day: meetDate ? format(new Date(meetDate), "yyyy-MM-dd") : "",
Expand All @@ -29,11 +29,11 @@ export const InfoForm = () => {
const date = parse(`${day}T${time}`, "yyyy-MM-dd'T'HH:mm", new Date());

if (!day || !time || Number.isNaN(date.getTime())) {
form.setValue("meet_date", undefined as any);
form.setValue("meetDate", undefined as any);
return;
}

form.setValue("meet_date", date);
form.setValue("meetDate", date);
};

const setTime = (e: any) => {
Expand All @@ -55,8 +55,8 @@ export const InfoForm = () => {
</Button>
<InputGroupWithTitle title="Le rendez-vous">
<Input label="Titre" nativeInputProps={form.register("title")} />
<Input label="Description" textArea nativeTextAreaProps={form.register("project_description")} />
<Select label="Rédigé par" nativeSelectProps={form.register("redacted_by")}>
<Input label="Description" textArea nativeTextAreaProps={form.register("projectDescription")} />
<Select label="Rédigé par" nativeSelectProps={form.register("redactedBy")}>
<option value={user.name}>{user.name}</option>
</Select>
<Stack direction="row">
Expand All @@ -68,10 +68,10 @@ export const InfoForm = () => {
<Divider mb="32px" />

<InputGroupWithTitle title="Le projet">
<Input label="Nom du demandeur*" nativeInputProps={form.register("applicant_name")} />
<Input label="Adresse du projet*" nativeInputProps={form.register("applicant_address")} />
<Input label="Référence cadastrale du projet" nativeInputProps={form.register("project_cadastral_ref")} />
<Input label="Service instructeur*" nativeInputProps={form.register("service_instructeur")} />
<Input label="Nom du demandeur*" nativeInputProps={form.register("applicantName")} />
<Input label="Adresse du projet*" nativeInputProps={form.register("applicantAddress")} />
<Input label="Référence cadastrale du projet" nativeInputProps={form.register("projectCadastralRef")} />
<Input label="Service instructeur*" nativeInputProps={form.register("serviceInstructeur")} />
<SpaceTypeChips />
</InputGroupWithTitle>

Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/features/NotesForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Flex } from "#styled-system/jsx";
import { useFormContext } from "react-hook-form";
import { InputGroupWithTitle } from "../components/InputGroup";
import Input from "@codegouvfr/react-dsfr/Input";
import type { Report } from "../generated/client";
import type { Report } from "@cr-vif/electric-client/frontend";
import { DecisionChips } from "../components/chips/DecisionChips";
import { ContactChips } from "../components/chips/ContactChips";
import { css } from "#styled-system/css";
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/features/ReportList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Badge from "@codegouvfr/react-dsfr/Badge";
import { css } from "#styled-system/css";
import { Link } from "@tanstack/react-router";

type ReportWithUser = Report & { user?: { email: string; name: string } };
export type ReportWithUser = Report & { user?: { email: string; name: string } };

export const MyReports = () => {
const user = useUser()!;
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/features/chips/ChipList.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useLiveQuery } from "electric-sql/react";
import { db } from "../../db";
import { Flex, Stack, styled } from "#styled-system/jsx";
import type { Chip } from "../../generated/client";
import type { Chip } from "@cr-vif/electric-client/frontend";

export const ChipList = () => {
const chips = useLiveQuery(db.chip.liveMany());
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/routes/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Box, Center } from "#styled-system/jsx";
import { Tabs } from "../components/Tabs";
import { InfoForm } from "../features/InfoForm";
import { FormProvider, useForm } from "react-hook-form";
import type { Report } from "../generated/client";
import type { Report } from "@cr-vif/electric-client/frontend";
import { useUser } from "../contexts/AuthContext";
import Button from "@codegouvfr/react-dsfr/Button";
import { useMutation } from "@tanstack/react-query";
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/routes/edit.$reportId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Tabs } from "../components/Tabs";
import { db } from "../db";
import { InfoForm } from "../features/InfoForm";
import { NotesForm } from "../features/NotesForm";
import type { Report } from "../generated/client";
import type { Report } from "@cr-vif/electric-client/frontend";

const EditReport = () => {
const { reportId } = Route.useParams();
Expand Down
14 changes: 7 additions & 7 deletions packages/frontend/src/routes/export.$reportId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { createFileRoute } from "@tanstack/react-router";
import { useLiveQuery } from "electric-sql/react";
import { db } from "../db";
import { Flex, styled } from "#styled-system/jsx";
import type { Report } from "../generated/client";
import { Document, Page, Text, View, StyleSheet, type Styles } from "@react-pdf/renderer";
import { PDFViewer } from "@react-pdf/renderer";
import type { Report } from "@cr-vif/electric-client/frontend";
import { TextEditor, textEditorClassName } from "../features/text-editor/TextEditor";
import { useState } from "react";
import Html from "react-pdf-html";
import useDebounce from "react-use/lib/useDebounce";

import type { ReportWithUser } from "../features/ReportList";
const ExportPdf = () => {
const { reportId } = Route.useParams();
const { results: report } = useLiveQuery(db.report.liveUnique({ where: { id: reportId } }));
Expand Down Expand Up @@ -69,13 +69,13 @@ const WithReport = ({ report }: { report: Report }) => {
);
};

const getReportHtmlString = (report: Report) => {
const getReportHtmlString = (report: ReportWithUser) => {
return `<p>
<span>Objet : ${report.title}</span><br/>
<span>Votre interlocuteur : ${report.created_by_username}</span><br/>
<span>Demandeur : ${report.applicant_name}</span><br/>
<span>Adresse du projet : ${report.applicant_address}</span><br/>
<span>Ref cadastrale : ${report.project_cadastral_ref}</span>
<span>Votre interlocuteur : ${report.user?.name ?? report.createdByEmail.split("@")[0]}</span><br/>
<span>Demandeur : ${report.applicantName}</span><br/>
<span>Adresse du projet : ${report.applicantAddress}</span><br/>
<span>Ref cadastrale : ${report.projectCadastralRef}</span>
</p>`;
};

Expand Down

0 comments on commit f32c730

Please sign in to comment.