diff --git a/packages/backend/src/routes/userRoutes.ts b/packages/backend/src/routes/userRoutes.ts
index 52d64a85..a1e7cd41 100644
--- a/packages/backend/src/routes/userRoutes.ts
+++ b/packages/backend/src/routes/userRoutes.ts
@@ -23,7 +23,7 @@ export const createUserTSchema = {
response: { 200: userAndTokenTSchema },
};
export const loginTSchema = {
- body: Type.Pick(userInput, ["email", "password", "udap"]),
+ body: Type.Pick(userInput, ["email", "password"]),
response: { 200: userAndTokenTSchema },
};
export const verifyTokenTSchema = {
diff --git a/packages/frontend/panda.config.ts b/packages/frontend/panda.config.ts
index f33534a1..ef14d51c 100644
--- a/packages/frontend/panda.config.ts
+++ b/packages/frontend/panda.config.ts
@@ -31,7 +31,12 @@ export default defineConfig({
"100%": { transform: "rotate(360deg)" },
},
},
- tokens: {},
+ tokens: {
+ colors: {
+ "yellow-waiting": { value: "#FEECC2" },
+ "red-offline": { value: "#FFE9E6" },
+ },
+ },
semanticTokens: {},
},
},
diff --git a/packages/frontend/src/components/Banner.tsx b/packages/frontend/src/components/Banner.tsx
index be31e49a..717141d3 100644
--- a/packages/frontend/src/components/Banner.tsx
+++ b/packages/frontend/src/components/Banner.tsx
@@ -1,5 +1,19 @@
import { type CenterProps, Center } from "#styled-system/jsx";
+import { cva } from "#styled-system/css";
+import { SyncFormStatus } from "./SyncForm";
-export const Banner = (props: CenterProps) => {
- return
;
+export const Banner = ({ status, ...props }: CenterProps & { status: SyncFormStatus }) => {
+ return ;
};
+
+const banner = cva({
+ base: { bgColor: "background-open-blue-france" },
+ variants: {
+ status: {
+ offline: { bgColor: "red-offline" },
+ pending: { bgColor: "yellow-waiting" },
+ saved: {},
+ saving: {},
+ },
+ },
+});
diff --git a/packages/frontend/src/components/SyncForm.tsx b/packages/frontend/src/components/SyncForm.tsx
index 31e96809..27c79105 100644
--- a/packages/frontend/src/components/SyncForm.tsx
+++ b/packages/frontend/src/components/SyncForm.tsx
@@ -8,7 +8,7 @@ import Button from "@codegouvfr/react-dsfr/Button";
import { styled } from "#styled-system/jsx";
import { fr } from "@codegouvfr/react-dsfr";
import { css } from "#styled-system/css";
-
+import { useNetworkState } from "react-use";
export function SyncFormBanner({
form,
baseObject,
@@ -25,9 +25,12 @@ export function SyncFormBanner({
const router = useRouter();
const goBack = () => router.history.back();
+ const { online } = useNetworkState();
+
+ const status = !online ? "offline" : Object.keys(diff).length ? "pending" : "saved";
return (
-
+
{/* @ts-ignore dsfr buttons props must have children */}
);
}
+const messages: Record = {
+ offline: "Hors ligne",
+ pending: "En attente",
+ saved: "Connecté(e)",
+ saving: "Sauvegarde",
+};
+
+export type SyncFormStatus = "offline" | "pending" | "saved" | "saving";
+
async function syncObject(id: string, diff: Record) {
if (!Object.keys(diff).length) return;
diff --git a/packages/frontend/src/contexts/AuthContext.tsx b/packages/frontend/src/contexts/AuthContext.tsx
index cc75009a..53ff47ea 100644
--- a/packages/frontend/src/contexts/AuthContext.tsx
+++ b/packages/frontend/src/contexts/AuthContext.tsx
@@ -23,8 +23,8 @@ export const AuthProvider = ({ children }: PropsWithChildren) => {
await electric.connect(data.token!);
await electric.db.clause.sync();
- await electric.db.user.sync();
- await electric.db.report.sync({ include: { user: true } });
+ await electric.db.user.sync({ where: { email: data?.user?.email } });
+ await electric.db.report.sync();
await electric.db.chip.sync();
return true;
diff --git a/packages/frontend/src/routes/export.$reportId.tsx b/packages/frontend/src/routes/export.$reportId.tsx
index 2138fe7d..1c843a89 100644
--- a/packages/frontend/src/routes/export.$reportId.tsx
+++ b/packages/frontend/src/routes/export.$reportId.tsx
@@ -26,6 +26,7 @@ const WithReport = ({ report }: { report: Report }) => {
return (
setValue(e)} />
+
diff --git a/packages/frontend/src/routes/index.tsx b/packages/frontend/src/routes/index.tsx
index 32fe203b..2d0195d2 100644
--- a/packages/frontend/src/routes/index.tsx
+++ b/packages/frontend/src/routes/index.tsx
@@ -10,6 +10,7 @@ import { Tabs } from "../components/Tabs";
import { useUser } from "../contexts/AuthContext";
import { db } from "../db";
import { AllReports, MyReports } from "../features/ReportList";
+import { useLiveQuery } from "electric-sql/react";
const Index = () => {
const user = useUser()!;
@@ -19,6 +20,8 @@ const Index = () => {
{ id: "udap", label: "UDAP" },
];
+ console.log("a", useLiveQuery(db.user.liveMany()));
+ console.log("b", useLiveQuery(db.report.liveMany({ include: { user: true } })));
const createReportMutation = useMutation({
mutationFn: () =>
db.report.create({