Skip to content

Commit

Permalink
feat(organizations): new /organizations/domaines page (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasduteil authored Jul 3, 2024
1 parent 6bef9ed commit a9e3c9a
Show file tree
Hide file tree
Showing 23 changed files with 604 additions and 98 deletions.
Binary file modified bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions e2e/features/organizations/dinum.feature
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ Fonctionnalité: Page organisation

# Scénario: Fiche de DINUM
Quand sur la même ligne je clique sur "➡️"
Alors je vois "A propos de DINUM"
Alors je vois "A propos de « DINUM »"
* je vois "Creation de l'organisation : 13/07/2018 15:35:15"
* je vois "Dernière mise à jour : 22/06/2023 14:34:34"
* je vois "Dénomination : DINUM"
* je vois "Nom complet : Direction interministerielle du numerique (DINUM)"
* je vois "Tranche d'effectif : 100 à 199 salariés, en 2021 (code : 22) (liste code effectif INSEE)"
* je vois "État administratif : A (liste état administratif INSEE)"
* je vois "siret : 13002526500013 (Voir la fiche annuaire entreprise de cette organisation)"
* je vois "Siret : 13002526500013 (Voir la fiche annuaire entreprise de cette organisation)"

# @only
# Scénario: Domain internes de DINUM
Expand Down
2 changes: 1 addition & 1 deletion packages/~/app/core/src/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { z } from "zod";

dotenv.config({
override: true,
path: [".env", ".env.local", `.env.${env.NODE_ENV}.local`],
path: [".env", ".env.local", `.env.${env["NODE_ENV"]}.local`],
});

const pkg = await import(join(cwd(), "package.json"));
Expand Down
12 changes: 11 additions & 1 deletion packages/~/app/core/src/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export const Entity_Schema = z.object({
//

export const Pagination_Schema = z.object({
page: z.string().pipe(z.coerce.number()).default("1"),
page: z
.string()
.pipe(z.coerce.number().transform((number) => Math.max(1, number)))
.default("1"),
page_size: z.string().pipe(z.coerce.number()).default("10"),
});
export type Pagination = z.infer<typeof Pagination_Schema>;
Expand All @@ -23,3 +26,10 @@ export const PAGINATION_ALL_PAGES: Readonly<Pagination> = {
page: 0,
page_size: 0,
};

//

export const Search_Schema = z.object({
q: z.string().default(""),
});
export type Search = z.infer<typeof Search_Schema>;
2 changes: 1 addition & 1 deletion packages/~/app/layout/src/__snapshots__/main.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ exports[`Main Layout 1`] = `
"
class="flex min-h-screen flex-col"
>
<div class="flex flex-1 flex-col"><div class="flex min-h-full flex-grow flex-col"><header role="banner" class="fr-header"><div class="fr-header__body"><div class="fr-container"><div class="fr-header__body-row"><div class="fr-header__brand fr-enlarge-link"><div class="fr-header__brand-top"><div class="fr-header__logo"><p class="fr-logo">République<br/>Française</p></div></div><div class="fr-header__service"><a href="/" title="Accueil "><p class="fr-header__service-title">Hyyypertool</p></a><p class="fr-header__service-tagline">hyyyyyyyypertool</p></div></div><div class="fr-header__tools"><div class="fr-header__tools-links"><ul class="fr-btns-group"><li><a class="fr-btn fr-btn--sm fr-btn--tertiary-no-outline fr-fi-logout-box-r-line fr-btn--icon-left" href="/auth/logout">undefined undefined</a></li></ul></div></div></div></div></div><div class="fr-header__menu fr-modal"><div class="fr-container"><nav class="fr-nav" id="navigation-494" role="navigation" aria-label="Menu principal"><ul class="fr-nav__list"><li class="fr-nav__item"><a class="fr-nav__link" href="/moderations" target="_self">Moderations</a></li><li class="fr-nav__item"><a class="fr-nav__link" href="/users" target="_self">Utilisateurs</a></li><li class="fr-nav__item"><a class="fr-nav__link" href="/organizations" target="_self">Organisations</a></li></ul></nav></div></div></header><div class="relative flex flex-1 flex-col">✅</div></div></div>
<div class="flex flex-1 flex-col"><div class="flex min-h-full flex-grow flex-col"><header role="banner" class="fr-header"><div class="fr-header__body"><div class="fr-container"><div class="fr-header__body-row"><div class="fr-header__brand fr-enlarge-link"><div class="fr-header__brand-top"><div class="fr-header__logo"><p class="fr-logo">République<br/>Française</p></div></div><div class="fr-header__service"><a href="/" title="Accueil "><p class="fr-header__service-title">Hyyypertool</p></a><p class="fr-header__service-tagline">hyyyyyyyypertool</p></div></div><div class="fr-header__tools"><div class="fr-header__tools-links"><ul class="fr-btns-group"><li><a class="fr-btn fr-btn--sm fr-btn--tertiary-no-outline fr-fi-logout-box-r-line fr-btn--icon-left" href="/auth/logout">undefined undefined</a></li></ul></div></div></div></div></div><div class="fr-header__menu fr-modal"><div class="fr-container"><nav class="fr-nav" id="navigation-494" role="navigation" aria-label="Menu principal"><ul class="fr-nav__list"><li class="fr-nav__item"><a class="fr-nav__link" href="/moderations" target="_self">Moderations</a></li><li class="fr-nav__item"><a class="fr-nav__link" href="/users" target="_self">Utilisateurs</a></li><li class="fr-nav__item"><a class="fr-nav__link" href="/organizations" target="_self">Organisations</a></li><li class="fr-nav__item"><a class="fr-nav__link" href="/organizations/domains" target="_self">Domaines à verifier</a></li></ul></nav></div></div></header><div class="relative flex flex-1 flex-col">✅</div></div></div>
<footer class="container mx-auto flex flex-row justify-between p-2">
<div>© 2222 🇫🇷</div>
<a
Expand Down
9 changes: 9 additions & 0 deletions packages/~/app/layout/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ function Nav() {
Organisations
</a>
</li>
<li class="fr-nav__item">
<a
class="fr-nav__link"
href={urls.organizations.domains.$url().pathname}
target="_self"
>
Domaines à verifier
</a>
</li>
</ul>
</nav>
);
Expand Down
1 change: 1 addition & 0 deletions packages/~/app/middleware/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"dependencies": {
"@~/app.core": "workspace:*",
"@~/app.sentry": "workspace:*",
"@~/moncomptepro.database": "workspace:*",
"hono": "4.4.10",
"hono-sessions": "0.5.8",
Expand Down
9 changes: 3 additions & 6 deletions packages/~/app/middleware/src/context.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//

import type { getSentry } from "@hono/sentry";
import type { AppVariables_Context } from "@~/app.core/config";
import type { SentryVariables_Context } from "@~/app.sentry";
import type { Csp_Context } from "./csp_headers";
import type { MonComptePro_Pg_Context } from "./moncomptepro_pg";
import type { Session_Context } from "./session";
Expand All @@ -13,8 +13,5 @@ export type App_Context = AppVariables_Context &
MonComptePro_Pg_Context &
NonceVariables_Context &
Session_Context &
UserInfoVariables_Context & {
Variables: {
sentry: ReturnType<typeof getSentry>;
};
};
UserInfoVariables_Context &
SentryVariables_Context;
13 changes: 5 additions & 8 deletions packages/~/app/middleware/src/set_userinfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import type { Context, Env } from "hono";
import { createMiddleware } from "hono/factory";
import type { AgentConnect_UserInfo, Session_Context } from "./session";
import type { App_Context } from "./context";
import type { AgentConnect_UserInfo } from "./session";

//
export function set_userinfo(value?: Partial<AgentConnect_UserInfo>) {
Expand All @@ -14,15 +15,11 @@ export function set_userinfo(value?: Partial<AgentConnect_UserInfo>) {

return createMiddleware<UserInfoVariables_Context>(
async function set_userinfo_middleware(c, next) {
const {
req,
set,
var: { sentry },
} = c;
const { req, set } = c;

const {
var: { session },
} = c as Context as Context<Session_Context>;
var: { session, sentry },
} = c as Context as Context<App_Context>;
const userinfo = session.get("userinfo");

if (userinfo) {
Expand Down
1 change: 1 addition & 0 deletions packages/~/app/middleware/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"extends": "@~/config.typescript/base.json",
"references": [
{ "path": "../core/tsconfig.json" },
{ "path": "../sentry/tsconfig.json" },
{ "path": "../../infra/moncomptepro/database/tsconfig.json" }
]
}
12 changes: 12 additions & 0 deletions packages/~/app/sentry/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
Scope,
addRequestDataToEvent,
continueTrace,
httpIntegration,
Expand All @@ -13,8 +14,19 @@ import {
import { nodeProfilingIntegration } from "@sentry/profiling-node";
import config from "@~/app.core/config";
import consola, { LogLevels } from "consola";
import type { Env } from "hono";
import { createMiddleware } from "hono/factory";

//

export interface SentryVariables_Context extends Env {
Variables: {
sentry: Scope;
};
}

//

export function sentry() {
init({
enabled: config.NODE_ENV === "production",
Expand Down
10 changes: 6 additions & 4 deletions packages/~/app/ui/src/hx_table/Foot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { Pagination_Schema, type Pagination } from "@~/app.core/schema";
import { button } from "../button";
import { FrNumberConverter } from "../number";

//

Expand All @@ -19,15 +20,16 @@ export function Foot({
pagination: Pagination;
}) {
const { page, page_size } = pagination;
const last_page = Math.floor(count / page_size) + 1;
const last_page = Math.ceil(count / page_size);
const page_index = page - 1;

return (
<tfoot>
<tr>
<th colspan={2} class="whitespace-nowrap" scope="row">
Showing {page_index * page_size}-{page_index * page_size + page_size}{" "}
of {count}
Affiche de {FrNumberConverter.format(page_index * page_size)}-
{FrNumberConverter.format(page_index * page_size + page_size)} sur{" "}
{FrNumberConverter.format(count)}
</th>
<td colspan={3}>
<button
Expand All @@ -45,7 +47,7 @@ export function Foot({
name={name ?? Pagination_Schema.keyof().Enum.page}
value={page}
/>{" "}
<span> of {last_page}</span>
<span> of {FrNumberConverter.format(last_page)}</span>
<button
class={button({ class: "fr-btn--tertiary-no-outline" })}
disabled={page >= last_page}
Expand Down
3 changes: 3 additions & 0 deletions packages/~/app/ui/src/number/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//

export const FrNumberConverter = new Intl.NumberFormat("fr-FR", {});
24 changes: 19 additions & 5 deletions packages/~/app/ui/src/time/LocalTime.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
//

import { date_to_string } from "@~/app.core/date/date_format";
import type { PropsWithChildren } from "hono/jsx";

//

export function LocalTime({
date: date_like,
}: {
interface Time_Props {
date: Date | string | null | undefined;
}) {
}

//

export function Time({
children,
date: date_like,
}: PropsWithChildren<Time_Props>) {
if (!date_like) return <></>;

const date = new Date(date_like);

return (
<time datetime={date.toISOString()} title={date.toString()}>
{date_to_string(date)}
{children}
</time>
);
}

export function LocalTime({ date: date_like }: Time_Props) {
if (!date_like) return <></>;

const date = new Date(date_like);

return <Time date={date}>{date_to_string(date)}</Time>;
}
20 changes: 18 additions & 2 deletions packages/~/app/urls/src/pattern.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
declare const app: import("hono/hono-base").HonoBase<
import("hono/types").BlankEnv,
import("@~/app.middleware/set_nonce").NonceVariables_Context &
import("@~/app.middleware/set_config").ConfigVariables_Context &
import("@~/app.middleware/set_userinfo").UserInfoVariables_Context,
{
"/organizations/:id/$procedures/verify/:domain": {
$patch: {
Expand Down Expand Up @@ -251,6 +253,20 @@ declare const app: import("hono/hono-base").HonoBase<
status: import("hono/utils/http-status").StatusCode;
};
};
"/organizations/domains": {
$get: {
input: {
query: {
page?: string | string[] | undefined;
page_size?: string | string[] | undefined;
q?: string | string[] | undefined;
};
};
output: {};
outputFormat: string;
status: import("hono/utils/http-status").StatusCode;
};
};
"/organizations/leaders": {
$get: {
input: {
Expand All @@ -267,9 +283,9 @@ declare const app: import("hono/hono-base").HonoBase<
$get: {
input: {
query: {
"search-siret"?: string | string[] | undefined;
page?: string | string[] | undefined;
page_size?: string | string[] | undefined;
"search-siret"?: string | string[] | undefined;
id?: string | string[] | undefined;
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { zValidator } from "@hono/zod-validator";
import type { Htmx_Header } from "@~/app.core/htmx";
import { Entity_Schema, PAGINATION_ALL_PAGES } from "@~/app.core/schema";
import { z_email_domain } from "@~/app.core/schema/z_email_domain";
import type { MonComptePro_Pg_Context } from "@~/app.middleware/moncomptepro_pg";
import type { App_Context } from "@~/app.middleware/context";
import { mark_domain_as_verified } from "@~/moncomptepro.lib";
import { Verification_Type_Schema } from "@~/moncomptepro.lib/verification_type";
import { ORGANISATION_EVENTS } from "@~/organizations.lib/event";
Expand All @@ -19,7 +19,7 @@ import { z } from "zod";

//

export default new Hono<MonComptePro_Pg_Context>().patch(
export default new Hono<App_Context>().patch(
"/:domain",
zValidator("param", Entity_Schema.extend({ domain: z.string() })),
async function PATCH({
Expand Down
Loading

0 comments on commit a9e3c9a

Please sign in to comment.