@@ -0,0 +1,24 @@
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="color-scheme" content="light dark" />
|
||||
<title>CoHaiSe CRM</title>
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.webp" />
|
||||
<script>
|
||||
(() => {
|
||||
const stored = localStorage.getItem("cohaise-theme");
|
||||
const prefersDark = window.matchMedia(
|
||||
"(prefers-color-scheme: dark)",
|
||||
).matches;
|
||||
const theme = stored ?? (prefersDark ? "dark" : "light");
|
||||
if (theme === "dark") document.documentElement.classList.add("dark");
|
||||
})();
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "@cohaise/crm-web",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc --noEmit && vite build",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@cohaise/ui": "*",
|
||||
"react": "^19.3.0",
|
||||
"react-dom": "^19.3.0",
|
||||
"three": "^0.187.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/vite": "^4.3.3",
|
||||
"@types/react": "^19.3.0",
|
||||
"@types/react-dom": "^19.3.0",
|
||||
"@types/three": "^0.187.0",
|
||||
"@vitejs/plugin-react": "^6.1.1",
|
||||
"tailwindcss": "^4.3.3",
|
||||
"typescript": "^7.0.2",
|
||||
"vite": "^8.3.1"
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 826 B |
|
After Width: | Height: | Size: 792 B |
|
After Width: | Height: | Size: 466 B |
|
After Width: | Height: | Size: 680 B |
|
After Width: | Height: | Size: 626 B |
|
After Width: | Height: | Size: 932 B |
|
After Width: | Height: | Size: 656 B |
|
After Width: | Height: | Size: 680 B |
|
After Width: | Height: | Size: 482 B |
|
After Width: | Height: | Size: 702 B |
|
After Width: | Height: | Size: 544 B |
|
After Width: | Height: | Size: 576 B |
|
After Width: | Height: | Size: 490 B |
|
After Width: | Height: | Size: 730 B |
|
After Width: | Height: | Size: 466 B |
|
After Width: | Height: | Size: 608 B |
|
After Width: | Height: | Size: 566 B |
|
After Width: | Height: | Size: 704 B |
|
After Width: | Height: | Size: 520 B |
|
After Width: | Height: | Size: 732 B |
|
After Width: | Height: | Size: 608 B |
|
After Width: | Height: | Size: 752 B |
|
After Width: | Height: | Size: 814 B |
|
After Width: | Height: | Size: 746 B |
|
After Width: | Height: | Size: 878 B |
|
After Width: | Height: | Size: 808 B |
|
After Width: | Height: | Size: 764 B |
|
After Width: | Height: | Size: 588 B |
|
After Width: | Height: | Size: 604 B |
|
After Width: | Height: | Size: 728 B |
|
After Width: | Height: | Size: 832 B |
|
After Width: | Height: | Size: 576 B |
|
After Width: | Height: | Size: 520 B |
|
After Width: | Height: | Size: 676 B |
|
After Width: | Height: | Size: 74 KiB |
@@ -0,0 +1,59 @@
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { Spinner } from "@cohaise/ui";
|
||||
import { ApiError, api, type User } from "./lib/api.js";
|
||||
import { Login } from "./pages/Login.js";
|
||||
import { ChangePassword } from "./pages/ChangePassword.js";
|
||||
import { Crm } from "./pages/Crm.js";
|
||||
|
||||
type Session =
|
||||
| { state: "loading" }
|
||||
| { state: "guest" }
|
||||
| { state: "ready"; user: User };
|
||||
|
||||
export const App = () => {
|
||||
const [session, setSession] = useState<Session>({ state: "loading" });
|
||||
|
||||
const refresh = useCallback(async () => {
|
||||
try {
|
||||
const { user } = await api.me();
|
||||
setSession({ state: "ready", user });
|
||||
} catch (error) {
|
||||
// 401 = simplement deconnecte, ce n'est pas une panne.
|
||||
if (error instanceof ApiError && error.status === 401) setSession({ state: "guest" });
|
||||
else setSession({ state: "guest" });
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
void refresh();
|
||||
}, [refresh]);
|
||||
|
||||
const logout = useCallback(async () => {
|
||||
await api.logout().catch(() => undefined);
|
||||
setSession({ state: "guest" });
|
||||
}, []);
|
||||
|
||||
if (session.state === "loading") {
|
||||
return (
|
||||
<div className="flex min-h-dvh items-center justify-center bg-background">
|
||||
<Spinner size="md" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (session.state === "guest") {
|
||||
return <Login onAuthenticated={(user) => setSession({ state: "ready", user })} />;
|
||||
}
|
||||
|
||||
if (session.user.must_change_password) {
|
||||
return (
|
||||
<ChangePassword
|
||||
user={session.user}
|
||||
onCompleted={refresh}
|
||||
onLogout={() => void logout()}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return <Crm user={session.user} onLogout={() => void logout()} />;
|
||||
};
|
||||
@@ -0,0 +1,870 @@
|
||||
// @ts-nocheck
|
||||
// Rendu WebGL2 « terminal » (grille de glyphes, scanlines, glitch). Porté tel
|
||||
// quel, volontairement non typé (code shader dense).
|
||||
import { useEffect, useRef } from 'react';
|
||||
|
||||
const INTRO_SECONDS = 2;
|
||||
const MAX_CLICKS = 4;
|
||||
const CLICK_SECONDS = { glitch: 0.7, degauss: 1.6 };
|
||||
const GLYPHS = { blocks: 0, dots: 1, characters: 2 };
|
||||
const CLICKS = { none: 0, glitch: 1, degauss: 2 };
|
||||
|
||||
const FONT = [
|
||||
['.###.', '#..##', '#.#.#', '##..#', '.###.'],
|
||||
['..#..', '.##..', '..#..', '..#..', '.###.'],
|
||||
['####.', '....#', '.###.', '#....', '#####'],
|
||||
['####.', '....#', '.###.', '....#', '####.'],
|
||||
['#..#.', '#..#.', '#####', '...#.', '...#.'],
|
||||
['#####', '#....', '####.', '....#', '####.'],
|
||||
['.###.', '#....', '####.', '#...#', '.###.'],
|
||||
['#####', '....#', '...#.', '..#..', '..#..'],
|
||||
['.###.', '#...#', '.###.', '#...#', '.###.'],
|
||||
['.###.', '#...#', '.####', '....#', '.###.'],
|
||||
['.###.', '#...#', '#####', '#...#', '#...#'],
|
||||
['####.', '#...#', '####.', '#...#', '####.'],
|
||||
['.####', '#....', '#....', '#....', '.####'],
|
||||
['####.', '#...#', '#...#', '#...#', '####.'],
|
||||
['#####', '#....', '####.', '#....', '#####'],
|
||||
['#####', '#....', '####.', '#....', '#....'],
|
||||
['.....', '..#..', '.###.', '..#..', '.....'],
|
||||
['.....', '.....', '.###.', '.....', '.....'],
|
||||
['.#...', '..#..', '...#.', '..#..', '.#...'],
|
||||
['....#', '...#.', '..#..', '.#...', '#....'],
|
||||
['.....', '#.#.#', '.###.', '#.#.#', '.....'],
|
||||
['.....', '#####', '.....', '#####', '.....'],
|
||||
['.....', '.....', '.....', '.....', '#####']
|
||||
];
|
||||
|
||||
const FONT_BITS = FONT.map(rows =>
|
||||
rows.reduce((bits, row, r) => {
|
||||
let value = bits;
|
||||
for (let c = 0; c < 5; c++) if (row[c] === '#') value += 2 ** (r * 5 + c);
|
||||
return value;
|
||||
}, 0)
|
||||
);
|
||||
|
||||
const VERTEX = `#version 300 es
|
||||
void main() {
|
||||
vec2 p = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2));
|
||||
gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);
|
||||
}`;
|
||||
|
||||
const PATTERN = `
|
||||
float time;
|
||||
|
||||
float noise(vec2 p) {
|
||||
return sin(p.x * 10.0) * sin(p.y * (3.0 + sin(time * 0.090909))) + 0.2;
|
||||
}
|
||||
|
||||
mat2 rotate(float angle) {
|
||||
float c = cos(angle);
|
||||
float s = sin(angle);
|
||||
return mat2(c, -s, s, c);
|
||||
}
|
||||
|
||||
float fbm(vec2 p) {
|
||||
p *= 1.1;
|
||||
float f = 0.0;
|
||||
float amp = 0.5 * uNoiseAmp;
|
||||
mat2 modify0 = rotate(time * 0.02);
|
||||
f += amp * noise(p);
|
||||
p = modify0 * p * 2.0;
|
||||
amp *= 0.454545;
|
||||
mat2 modify1 = rotate(time * 0.02);
|
||||
f += amp * noise(p);
|
||||
p = modify1 * p * 2.0;
|
||||
amp *= 0.454545;
|
||||
f += amp * noise(p);
|
||||
return f;
|
||||
}
|
||||
|
||||
float pattern(vec2 p) {
|
||||
vec2 offset1 = vec2(1.0);
|
||||
vec2 offset0 = vec2(0.0);
|
||||
mat2 rot01 = rotate(0.1 * time);
|
||||
mat2 rot1 = rotate(0.1);
|
||||
vec2 q = vec2(fbm(p + offset1), fbm(rot01 * p + offset1));
|
||||
vec2 r = vec2(fbm(rot1 * q + offset0), fbm(q + offset0));
|
||||
return fbm(p + r);
|
||||
}
|
||||
`;
|
||||
|
||||
const CELL_FRAGMENT = `#version 300 es
|
||||
precision highp float;
|
||||
precision highp int;
|
||||
|
||||
uniform float iTime;
|
||||
uniform vec2 uGridMul;
|
||||
uniform float uNoiseAmp;
|
||||
uniform float uScale;
|
||||
uniform vec2 uMouse;
|
||||
uniform float uMouseStrength;
|
||||
uniform float uUseMouse;
|
||||
uniform float uPageLoadProgress;
|
||||
uniform float uUsePageLoadAnimation;
|
||||
uniform ivec2 uOrigin;
|
||||
uniform sampler2D uPrev0;
|
||||
uniform sampler2D uPrev1;
|
||||
uniform float uDecay;
|
||||
uniform float uFresh;
|
||||
uniform float uHover;
|
||||
|
||||
layout(location = 0) out vec4 outRings;
|
||||
layout(location = 1) out vec4 outExtra;
|
||||
${PATTERN}
|
||||
void main() {
|
||||
time = iTime * 0.333333;
|
||||
ivec2 texel = ivec2(gl_FragCoord.xy);
|
||||
vec2 grid = uGridMul * 15.0;
|
||||
vec2 s = vec2(texel + uOrigin) / grid;
|
||||
float intensity = pattern(s * 0.1) * 1.3 - 0.03;
|
||||
float lift = 0.0;
|
||||
float strike = 0.0;
|
||||
|
||||
if (uUseMouse > 0.5) {
|
||||
vec2 mouseWorld = uMouse * uScale;
|
||||
float distToMouse = distance(s, mouseWorld);
|
||||
float mouseInfluence = exp(-distToMouse * 8.0) * uMouseStrength * 10.0;
|
||||
intensity += mouseInfluence;
|
||||
float ripple = sin(distToMouse * 20.0 - iTime * 5.0) * 0.1 * mouseInfluence;
|
||||
intensity += ripple;
|
||||
lift = mouseInfluence;
|
||||
}
|
||||
|
||||
if (uUsePageLoadAnimation > 0.5) {
|
||||
float cellRandom = fract(sin(dot(s, vec2(12.9898, 78.233))) * 43758.5453);
|
||||
float cellDelay = cellRandom * 0.8;
|
||||
float cellProgress = clamp((uPageLoadProgress - cellDelay) / 0.2, 0.0, 1.0);
|
||||
float fadeAlpha = smoothstep(0.0, 1.0, cellProgress);
|
||||
intensity *= fadeAlpha;
|
||||
strike = sin(3.14159265 * cellProgress) * step(0.1, intensity);
|
||||
}
|
||||
|
||||
vec4 on0 = step(vec4(0.1), intensity - vec4(0.0, 1.0, 2.0, 4.0) * 0.0625);
|
||||
vec2 on1 = step(vec2(0.1), intensity - vec2(5.0, 8.0) * 0.0625);
|
||||
float level = clamp((intensity - 0.1) / 0.6, 0.0, 1.0);
|
||||
float heat = max(clamp(lift / 3.0, 0.0, 1.0) * uHover, strike);
|
||||
|
||||
vec4 prev0 = texelFetch(uPrev0, texel, 0) * (1.0 - uFresh);
|
||||
vec4 prev1 = texelFetch(uPrev1, texel, 0) * (1.0 - uFresh);
|
||||
vec4 fade0 = max(prev0 * uDecay - 1.0 / 255.0, 0.0);
|
||||
vec4 fade1 = max(prev1 * uDecay - 1.0 / 255.0, 0.0);
|
||||
|
||||
outRings = max(on0, fade0);
|
||||
outExtra = vec4(max(on1, fade1.xy), max(level, fade1.z), max(heat, fade1.w));
|
||||
}`;
|
||||
|
||||
const fontArray = `const uint FONT[${FONT_BITS.length}] = uint[${FONT_BITS.length}](${FONT_BITS.map(
|
||||
bits => `${bits}u`
|
||||
).join(', ')});`;
|
||||
|
||||
const MAIN_FRAGMENT = `#version 300 es
|
||||
precision highp float;
|
||||
precision highp int;
|
||||
|
||||
uniform float iTime;
|
||||
uniform vec3 iResolution;
|
||||
uniform float uScale;
|
||||
uniform vec2 uGridMul;
|
||||
uniform float uDigitSize;
|
||||
uniform float uScanlineIntensity;
|
||||
uniform float uGlitchAmount;
|
||||
uniform float uFlickerAmount;
|
||||
uniform float uChromaticAberration;
|
||||
uniform float uDither;
|
||||
uniform float uCurvature;
|
||||
uniform vec3 uTint;
|
||||
uniform float uBrightness;
|
||||
uniform float uLightMode;
|
||||
uniform sampler2D uRings0;
|
||||
uniform sampler2D uRings1;
|
||||
uniform ivec2 uOrigin;
|
||||
uniform ivec2 uCellCount;
|
||||
uniform int uGlyphs;
|
||||
uniform float uGlow;
|
||||
uniform float uScramble;
|
||||
uniform float uMouseGlow;
|
||||
uniform float uVignette;
|
||||
uniform vec4 uClicks[${MAX_CLICKS}];
|
||||
uniform int uClickMode;
|
||||
uniform float uClickSeconds;
|
||||
uniform float uClock;
|
||||
|
||||
out vec4 outColor;
|
||||
|
||||
${fontArray}
|
||||
|
||||
float time;
|
||||
float clickTear;
|
||||
float clickSplit;
|
||||
float pixelHeat;
|
||||
|
||||
float hash21(vec2 p) {
|
||||
p = fract(p * 234.56);
|
||||
p += dot(p, p + 34.56);
|
||||
return fract(p.x * p.y);
|
||||
}
|
||||
|
||||
float hashCell(vec2 p) {
|
||||
vec3 q = fract(vec3(p.xyx) * 0.1031);
|
||||
q += dot(q, q.yzx + 33.33);
|
||||
return fract((q.x + q.y) * q.z);
|
||||
}
|
||||
|
||||
ivec2 cellTexel(vec2 cell) {
|
||||
return clamp(ivec2(cell) - uOrigin, ivec2(0), uCellCount - 1);
|
||||
}
|
||||
|
||||
float ringValue(float n, vec4 r0, vec4 r1) {
|
||||
if (n < 0.5) return r0.x;
|
||||
if (n < 1.5) return r0.y;
|
||||
if (n < 2.5) return r0.z;
|
||||
if (n < 4.5) return r0.w;
|
||||
if (n < 5.5) return r1.x;
|
||||
return r1.y;
|
||||
}
|
||||
|
||||
float digit(vec2 p) {
|
||||
vec2 grid = uGridMul * 15.0;
|
||||
vec2 cell = floor(p * grid);
|
||||
ivec2 texel = cellTexel(cell);
|
||||
vec4 r0 = texelFetch(uRings0, texel, 0);
|
||||
vec4 r1 = texelFetch(uRings1, texel, 0);
|
||||
float boost = 1.0 + r1.w * uMouseGlow * 1.3;
|
||||
pixelHeat = max(pixelHeat, r1.w);
|
||||
p = fract(p * grid);
|
||||
p *= uDigitSize;
|
||||
|
||||
float px5 = p.x * 5.0;
|
||||
float py5 = (1.0 - p.y) * 5.0;
|
||||
float x = fract(px5);
|
||||
float y = fract(py5);
|
||||
float i = floor(py5) - 2.0;
|
||||
float j = floor(px5) - 2.0;
|
||||
float inside = step(0.0, p.x) * step(p.x, 1.0) * step(0.0, p.y) * step(p.y, 1.0);
|
||||
|
||||
if (uGlyphs == 2) {
|
||||
float rate = 1.2 + r1.w * uScramble * 18.0;
|
||||
float phase = hashCell(cell * 1.37 + 4.1);
|
||||
float epoch = floor(iTime * rate + phase * 7.0);
|
||||
float pick = hashCell(cell + vec2(epoch * 0.731, epoch * 1.913));
|
||||
uint glyph = FONT[int(min(pick * float(FONT.length()), float(FONT.length()) - 1.0))];
|
||||
int bit = int(i + 2.0) * 5 + int(j + 2.0);
|
||||
float lit = float((glyph >> uint(clamp(bit, 0, 24))) & 1u);
|
||||
float glow = max(r0.x, r1.z);
|
||||
float shade = 0.35 + 0.65 * r1.z;
|
||||
return inside * lit * glow * shade * boost * (0.2 + y * 0.8) * (0.75 + x * 0.25);
|
||||
}
|
||||
|
||||
float n = i * i + j * j;
|
||||
float on = ringValue(n, r0, r1);
|
||||
if (uGlyphs == 1) {
|
||||
vec2 d = vec2(x, y) - 0.5;
|
||||
float radius = 0.36 + 0.06 * on;
|
||||
float edge = fwidth(px5) * 0.75;
|
||||
float dot = 1.0 - smoothstep(radius - edge, radius + edge, length(d));
|
||||
return inside * on * dot * boost * (0.55 + 0.45 * (1.0 - length(d) / 0.5));
|
||||
}
|
||||
float brightness = on * (0.2 + y * 0.8) * (0.75 + x * 0.25);
|
||||
return inside * brightness * boost;
|
||||
}
|
||||
|
||||
float onOff(float a, float b, float c) {
|
||||
return step(c, sin(iTime + a * cos(iTime * b))) * uFlickerAmount;
|
||||
}
|
||||
|
||||
float displace(vec2 look) {
|
||||
float y = look.y - mod(iTime * 0.25, 1.0);
|
||||
float window = 1.0 / (1.0 + 50.0 * y * y);
|
||||
return sin(look.y * 20.0 + iTime) * 0.0125 * onOff(4.0, 2.0, 0.8) * (1.0 + cos(iTime * 60.0)) * window;
|
||||
}
|
||||
|
||||
vec2 getLight(vec2 p) {
|
||||
float bar = step(mod(p.y + time * 20.0, 1.0), 0.2) * 0.4 + 1.0;
|
||||
bar *= uScanlineIntensity;
|
||||
|
||||
float displacement = displace(p);
|
||||
p.x += displacement;
|
||||
|
||||
if (uGlitchAmount != 1.0) {
|
||||
float extra = displacement * (uGlitchAmount - 1.0);
|
||||
p.x += extra;
|
||||
}
|
||||
|
||||
p.x += clickTear;
|
||||
|
||||
float middle = digit(p);
|
||||
|
||||
const float off = 0.002;
|
||||
float sum = digit(p + vec2(-off, -off)) + digit(p + vec2(0.0, -off)) + digit(p + vec2(off, -off)) +
|
||||
digit(p + vec2(-off, 0.0)) + digit(p + vec2(0.0, 0.0)) + digit(p + vec2(off, 0.0)) +
|
||||
digit(p + vec2(-off, off)) + digit(p + vec2(0.0, off)) + digit(p + vec2(off, off));
|
||||
|
||||
return vec2(0.9 * middle, sum * 0.1 * bar);
|
||||
}
|
||||
|
||||
float glowAt(vec2 p) {
|
||||
vec2 grid = uGridMul * 15.0;
|
||||
vec2 cell = floor(p * grid);
|
||||
vec2 cellPx = iResolution.xy / (uScale * grid);
|
||||
float sigma = 0.5 * min(cellPx.x, cellPx.y);
|
||||
float center = 0.5 * min(1.0, 1.0 / max(uDigitSize, 0.001));
|
||||
float total = 0.0;
|
||||
for (int oy = -1; oy <= 1; oy++) {
|
||||
for (int ox = -1; ox <= 1; ox++) {
|
||||
vec2 c = cell + vec2(float(ox), float(oy));
|
||||
ivec2 texel = cellTexel(c);
|
||||
vec4 r0 = texelFetch(uRings0, texel, 0);
|
||||
vec4 r1 = texelFetch(uRings1, texel, 0);
|
||||
float emission = uGlyphs == 2
|
||||
? max(r0.x, r1.z) * (0.35 + 0.65 * r1.z) * 0.45
|
||||
: (r0.x + 4.0 * (r0.y + r0.z + r0.w + r1.y) + 8.0 * r1.x) / 25.0;
|
||||
emission *= 1.0 + r1.w * uMouseGlow * 1.6;
|
||||
vec2 d = (p - (c + center) / grid) * iResolution.xy / uScale;
|
||||
total += emission * exp(-dot(d, d) / (2.0 * sigma * sigma));
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
vec2 barrel(vec2 uv) {
|
||||
vec2 c = uv * 2.0 - 1.0;
|
||||
float r2 = dot(c, c);
|
||||
c *= 1.0 + uCurvature * r2;
|
||||
return c * 0.5 + 0.5;
|
||||
}
|
||||
|
||||
void main() {
|
||||
time = iTime * 0.333333;
|
||||
vec2 uv = gl_FragCoord.xy / iResolution.xy;
|
||||
|
||||
if (uCurvature != 0.0) {
|
||||
uv = barrel(uv);
|
||||
}
|
||||
|
||||
clickTear = 0.0;
|
||||
clickSplit = 0.0;
|
||||
if (uClickMode > 0) {
|
||||
for (int k = 0; k < ${MAX_CLICKS}; k++) {
|
||||
vec4 click = uClicks[k];
|
||||
if (click.w <= 0.0) continue;
|
||||
float age = uClock - click.z;
|
||||
if (age < 0.0 || age > uClickSeconds) continue;
|
||||
float life = age / uClickSeconds;
|
||||
float envelope = (1.0 - life) * (1.0 - life);
|
||||
if (uClickMode == 1) {
|
||||
float tick = floor(age * 30.0);
|
||||
float bands = 14.0 + 26.0 * hashCell(vec2(click.z, tick * 0.37));
|
||||
float row = floor(uv.y * bands);
|
||||
float pickRow = hashCell(vec2(row + tick * 7.0, click.z * 17.0));
|
||||
float torn = step(0.42, pickRow);
|
||||
float reach = exp(-abs(uv.y - click.y) * 2.5);
|
||||
float shift = (hashCell(vec2(row * 1.7 + tick, click.z)) - 0.5) * 0.22;
|
||||
clickTear += shift * torn * envelope * reach;
|
||||
clickSplit = max(clickSplit, envelope * reach * (0.4 + 0.6 * torn));
|
||||
} else {
|
||||
vec2 aspect = vec2(iResolution.x / iResolution.y, 1.0);
|
||||
vec2 delta = (uv - click.xy) * aspect;
|
||||
float dist = length(delta);
|
||||
float front = age * 1.6;
|
||||
float band = exp(-pow((dist - front) / 0.18, 2.0));
|
||||
float wave = sin((dist - front) * 40.0) * band;
|
||||
uv += delta / aspect * wave * 0.05 * envelope;
|
||||
clickSplit = max(clickSplit, envelope * band);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vec2 p = uv * uScale;
|
||||
pixelHeat = 0.0;
|
||||
vec2 lightG = getLight(p);
|
||||
float heat = pixelHeat;
|
||||
vec2 lightR = lightG;
|
||||
vec2 lightB = lightG;
|
||||
|
||||
float split = uChromaticAberration + clickSplit * 6.0;
|
||||
if (split != 0.0) {
|
||||
vec2 ca = vec2(split) / iResolution.xy;
|
||||
lightR = getLight(p + ca);
|
||||
lightB = getLight(p - ca);
|
||||
}
|
||||
|
||||
if (uGlow > 0.0) {
|
||||
float bloom = uGlow * 0.2 * glowAt(p);
|
||||
lightR.y += bloom;
|
||||
lightG.y += bloom;
|
||||
lightB.y += bloom;
|
||||
}
|
||||
|
||||
vec3 core = vec3(lightR.x, lightG.x, lightB.x);
|
||||
vec3 halo = vec3(lightR.y, lightG.y, lightB.y);
|
||||
vec3 raw = core + halo;
|
||||
|
||||
vec3 luma = vec3(0.2126, 0.7152, 0.0722);
|
||||
float peak = max(uTint.r, max(uTint.g, uTint.b));
|
||||
float phosphor = clamp(uGlow, 0.0, 1.0);
|
||||
vec3 vividTint = clamp(mix(vec3(dot(uTint, luma)), uTint, 1.0 + 0.8 * phosphor), 0.0, 1.0);
|
||||
vec3 coreTint = mix(uTint, vec3(peak), phosphor * 0.45 * smoothstep(0.45, 0.9, core));
|
||||
vec3 col = core * coreTint + halo * vividTint;
|
||||
col += (vec3(1.0) - uTint) * min(raw, vec3(1.0)) * heat * uMouseGlow * 0.6;
|
||||
col *= uBrightness;
|
||||
|
||||
if (uVignette > 0.0) {
|
||||
float edge = 0.04 + 0.22 * uVignette;
|
||||
vec2 fade = smoothstep(vec2(0.0), vec2(edge), uv) * smoothstep(vec2(0.0), vec2(edge), 1.0 - uv);
|
||||
float mask = fade.x * fade.y;
|
||||
mask = mask * mask * (3.0 - 2.0 * mask);
|
||||
float keep = mix(1.0, mask, clamp(uVignette * 1.5, 0.0, 1.0));
|
||||
col *= keep;
|
||||
core *= keep;
|
||||
halo *= keep;
|
||||
}
|
||||
|
||||
if (uLightMode > 0.5) {
|
||||
vec3 luma = vec3(0.2126, 0.7152, 0.0722);
|
||||
float lum = dot(uTint, luma);
|
||||
float peak = max(uTint.r, max(uTint.g, uTint.b));
|
||||
vec3 hue = uTint / max(peak, 0.0001);
|
||||
vec3 vivid = clamp(mix(vec3(dot(hue, luma)), hue, 1.6), 0.0, 1.0);
|
||||
vivid = clamp(vivid * (0.3 / max(dot(vivid, luma), 0.0001)), 0.0, 1.0);
|
||||
vec3 ink = mix(uTint, vivid, smoothstep(0.3, 0.6, lum));
|
||||
vec3 cover = (core * 1.15 + halo * 0.4) * uBrightness * (1.0 + heat * uMouseGlow * 0.4);
|
||||
if (uDither > 0.0) cover += (hash21(gl_FragCoord.xy) - 0.5) * (uDither * 0.003922);
|
||||
cover = clamp(cover, 0.0, 0.94);
|
||||
float alpha = max(cover.r, max(cover.g, cover.b));
|
||||
outColor = vec4(alpha - cover * (1.0 - ink), alpha);
|
||||
return;
|
||||
}
|
||||
|
||||
if (uDither > 0.0) {
|
||||
float rnd = hash21(gl_FragCoord.xy);
|
||||
col += (rnd - 0.5) * (uDither * 0.003922);
|
||||
}
|
||||
|
||||
col = clamp(col, 0.0, 1.0);
|
||||
outColor = vec4(col, max(col.r, max(col.g, col.b)));
|
||||
}`;
|
||||
|
||||
const clamp = (value, min, max) => Math.min(max, Math.max(min, value));
|
||||
|
||||
const compile = (gl, type, source) => {
|
||||
const shader = gl.createShader(type);
|
||||
if (!shader) return null;
|
||||
gl.shaderSource(shader, source);
|
||||
gl.compileShader(shader);
|
||||
if (gl.getShaderParameter(shader, gl.COMPILE_STATUS)) return shader;
|
||||
gl.deleteShader(shader);
|
||||
return null;
|
||||
};
|
||||
|
||||
const link = (gl, fragmentSource) => {
|
||||
const vertex = compile(gl, gl.VERTEX_SHADER, VERTEX);
|
||||
const fragment = compile(gl, gl.FRAGMENT_SHADER, fragmentSource);
|
||||
const program = gl.createProgram();
|
||||
if (!vertex || !fragment || !program) return null;
|
||||
gl.attachShader(program, vertex);
|
||||
gl.attachShader(program, fragment);
|
||||
gl.linkProgram(program);
|
||||
gl.deleteShader(vertex);
|
||||
gl.deleteShader(fragment);
|
||||
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
||||
gl.deleteProgram(program);
|
||||
return null;
|
||||
}
|
||||
const uniforms = {};
|
||||
const count = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
|
||||
for (let i = 0; i < count; i++) {
|
||||
const info = gl.getActiveUniform(program, i);
|
||||
if (!info) continue;
|
||||
const name = info.name.replace(/\[0\]$/, '');
|
||||
uniforms[name] = gl.getUniformLocation(program, name);
|
||||
}
|
||||
return { program, uniforms };
|
||||
};
|
||||
|
||||
const hexToRgb = hex => {
|
||||
let h = String(hex || '#ffffff')
|
||||
.replace('#', '')
|
||||
.trim();
|
||||
if (h.length === 3 || h.length === 4)
|
||||
h = h
|
||||
.slice(0, 3)
|
||||
.split('')
|
||||
.map(c => c + c)
|
||||
.join('');
|
||||
const num = parseInt(h.slice(0, 6), 16);
|
||||
if (Number.isNaN(num)) return [1, 1, 1];
|
||||
return [((num >> 16) & 255) / 255, ((num >> 8) & 255) / 255, (num & 255) / 255];
|
||||
};
|
||||
|
||||
export default function FaultyTerminal({
|
||||
scale = 1,
|
||||
gridMul = [2, 1],
|
||||
digitSize = 1.5,
|
||||
timeScale = 0.3,
|
||||
pause = false,
|
||||
scanlineIntensity = 0.3,
|
||||
glitchAmount = 1,
|
||||
flickerAmount = 1,
|
||||
noiseAmp = 1,
|
||||
chromaticAberration = 0,
|
||||
dither = 0,
|
||||
curvature = 0.2,
|
||||
tint = '#ff5252',
|
||||
mouseReact = true,
|
||||
mouseStrength = 0.2,
|
||||
pageLoadAnimation = true,
|
||||
brightness = 1,
|
||||
glyphs = 'blocks',
|
||||
glow = 0.5,
|
||||
persistence = 0.5,
|
||||
scramble = 0.5,
|
||||
mouseGlow = 0.6,
|
||||
vignette = 0.25,
|
||||
clickEffect = 'glitch',
|
||||
variation = undefined,
|
||||
lightMode = false,
|
||||
dpr = undefined,
|
||||
className = '',
|
||||
style = undefined,
|
||||
...rest
|
||||
}) {
|
||||
const containerRef = useRef(null);
|
||||
const canvasRef = useRef(null);
|
||||
const wakeRef = useRef(null);
|
||||
const settings = {
|
||||
scale: Math.max(0.05, scale),
|
||||
gridX: Math.max(0.1, (gridMul?.[0] ?? 2) * 15),
|
||||
gridY: Math.max(0.1, (gridMul?.[1] ?? 1) * 15),
|
||||
digitSize,
|
||||
timeScale,
|
||||
pause,
|
||||
scanlineIntensity,
|
||||
glitchAmount,
|
||||
flickerAmount,
|
||||
noiseAmp,
|
||||
chromaticAberration,
|
||||
dither: typeof dither === 'boolean' ? (dither ? 1 : 0) : dither,
|
||||
curvature,
|
||||
tint,
|
||||
mouseReact,
|
||||
mouseStrength,
|
||||
pageLoadAnimation,
|
||||
brightness,
|
||||
glyphs: GLYPHS[glyphs] ?? 0,
|
||||
glow: clamp(glow, 0, 3),
|
||||
persistence: clamp(persistence, 0, 1),
|
||||
scramble: clamp(scramble, 0, 1),
|
||||
mouseGlow: clamp(mouseGlow, 0, 1),
|
||||
vignette: clamp(vignette, 0, 1),
|
||||
clickEffect: CLICKS[clickEffect] ?? 0,
|
||||
clickSeconds: CLICK_SECONDS[clickEffect] ?? 1,
|
||||
variation,
|
||||
lightMode,
|
||||
dpr
|
||||
};
|
||||
const settingsRef = useRef(settings);
|
||||
settingsRef.current = settings;
|
||||
|
||||
useEffect(() => {
|
||||
const container = containerRef.current;
|
||||
const canvas = canvasRef.current;
|
||||
const gl = canvas?.getContext('webgl2', {
|
||||
alpha: true,
|
||||
premultipliedAlpha: true,
|
||||
antialias: false,
|
||||
depth: false,
|
||||
stencil: false
|
||||
});
|
||||
if (!container || !canvas || !gl) return undefined;
|
||||
const cellShader = link(gl, CELL_FRAGMENT);
|
||||
const mainShader = link(gl, MAIN_FRAGMENT);
|
||||
if (!cellShader || !mainShader) return undefined;
|
||||
const cu = cellShader.uniforms;
|
||||
const mu = mainShader.uniforms;
|
||||
const vao = gl.createVertexArray();
|
||||
|
||||
const makeTexture = () => {
|
||||
const texture = gl.createTexture();
|
||||
gl.bindTexture(gl.TEXTURE_2D, texture);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
||||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
|
||||
return texture;
|
||||
};
|
||||
const targets = [0, 1].map(() => {
|
||||
const rings = makeTexture();
|
||||
const extra = makeTexture();
|
||||
const framebuffer = gl.createFramebuffer();
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
|
||||
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, rings, 0);
|
||||
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT1, gl.TEXTURE_2D, extra, 0);
|
||||
return { rings, extra, framebuffer };
|
||||
});
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
||||
|
||||
const reduce = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches ?? false;
|
||||
const view = { width: 1, height: 1, ratio: 1, columns: 1 };
|
||||
const cells = { x: 0, y: 0, w: 1, h: 1, key: '' };
|
||||
const pointer = { x: 0.5, y: 0.5, inside: false };
|
||||
const mouse = { x: 0.5, y: 0.5 };
|
||||
const clicks = new Float32Array(MAX_CLICKS * 4);
|
||||
let clickIndex = 0;
|
||||
let clock = 0;
|
||||
let hover = 0;
|
||||
let current = 0;
|
||||
let fresh = true;
|
||||
const seedOffset = settingsRef.current.variation;
|
||||
const initialOffset = typeof seedOffset === 'number' ? seedOffset * 10 : Math.random() * 100;
|
||||
let iTime = initialOffset * settingsRef.current.timeScale;
|
||||
let introClock = settingsRef.current.pageLoadAnimation && !reduce ? 0 : 1;
|
||||
let raf = 0;
|
||||
let last = 0;
|
||||
let visible = true;
|
||||
let quiet = 0;
|
||||
|
||||
const layoutCells = s => {
|
||||
const reach = 1 + Math.max(0, s.curvature) * 2;
|
||||
const uvMin = 0.5 - 0.5 * reach;
|
||||
const uvMax = 0.5 + 0.5 * reach;
|
||||
const margin = 0.06 * Math.max(1, Math.abs(s.glitchAmount)) * Math.max(1, Math.abs(s.flickerAmount)) + 0.2;
|
||||
const gridX = s.gridX * view.columns;
|
||||
const x0 = Math.floor((uvMin * s.scale - margin) * gridX) - 2;
|
||||
const x1 = Math.floor((uvMax * s.scale + margin) * gridX) + 2;
|
||||
const y0 = Math.floor((uvMin * s.scale - margin) * s.gridY) - 2;
|
||||
const y1 = Math.floor((uvMax * s.scale + margin) * s.gridY) + 2;
|
||||
const key = `${x0}:${x1}:${y0}:${y1}`;
|
||||
if (key === cells.key) return;
|
||||
cells.key = key;
|
||||
cells.x = x0;
|
||||
cells.y = y0;
|
||||
cells.w = Math.max(1, Math.min(4096, x1 - x0 + 1));
|
||||
cells.h = Math.max(1, Math.min(4096, y1 - y0 + 1));
|
||||
for (const target of targets) {
|
||||
for (const texture of [target.rings, target.extra]) {
|
||||
gl.bindTexture(gl.TEXTURE_2D, texture);
|
||||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, cells.w, cells.h, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
|
||||
}
|
||||
}
|
||||
fresh = true;
|
||||
};
|
||||
|
||||
const stepCells = (s, decay) => {
|
||||
const source = targets[current];
|
||||
const target = targets[1 - current];
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, target.framebuffer);
|
||||
gl.drawBuffers([gl.COLOR_ATTACHMENT0, gl.COLOR_ATTACHMENT1]);
|
||||
gl.viewport(0, 0, cells.w, cells.h);
|
||||
gl.disable(gl.BLEND);
|
||||
gl.useProgram(cellShader.program);
|
||||
gl.activeTexture(gl.TEXTURE0);
|
||||
gl.bindTexture(gl.TEXTURE_2D, source.rings);
|
||||
gl.activeTexture(gl.TEXTURE1);
|
||||
gl.bindTexture(gl.TEXTURE_2D, source.extra);
|
||||
gl.uniform1i(cu.uPrev0, 0);
|
||||
gl.uniform1i(cu.uPrev1, 1);
|
||||
gl.uniform1f(cu.iTime, iTime);
|
||||
gl.uniform2f(cu.uGridMul, (s.gridX * view.columns) / 15, s.gridY / 15);
|
||||
gl.uniform1f(cu.uNoiseAmp, s.noiseAmp);
|
||||
gl.uniform1f(cu.uScale, s.scale);
|
||||
gl.uniform2f(cu.uMouse, mouse.x, mouse.y);
|
||||
gl.uniform1f(cu.uMouseStrength, s.mouseStrength);
|
||||
gl.uniform1f(cu.uUseMouse, s.mouseReact ? 1 : 0);
|
||||
gl.uniform1f(cu.uPageLoadProgress, introClock);
|
||||
gl.uniform1f(cu.uUsePageLoadAnimation, s.pageLoadAnimation ? 1 : 0);
|
||||
gl.uniform2i(cu.uOrigin, cells.x, cells.y);
|
||||
gl.uniform1f(cu.uDecay, decay);
|
||||
gl.uniform1f(cu.uFresh, fresh ? 1 : 0);
|
||||
gl.uniform1f(cu.uHover, hover);
|
||||
gl.bindVertexArray(vao);
|
||||
gl.drawArrays(gl.TRIANGLES, 0, 3);
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
||||
current = 1 - current;
|
||||
fresh = false;
|
||||
};
|
||||
|
||||
const draw = () => {
|
||||
const s = settingsRef.current;
|
||||
const source = targets[current];
|
||||
gl.viewport(0, 0, canvas.width, canvas.height);
|
||||
gl.clearColor(0, 0, 0, 0);
|
||||
gl.clear(gl.COLOR_BUFFER_BIT);
|
||||
gl.useProgram(mainShader.program);
|
||||
gl.activeTexture(gl.TEXTURE0);
|
||||
gl.bindTexture(gl.TEXTURE_2D, source.rings);
|
||||
gl.activeTexture(gl.TEXTURE1);
|
||||
gl.bindTexture(gl.TEXTURE_2D, source.extra);
|
||||
gl.uniform1i(mu.uRings0, 0);
|
||||
gl.uniform1i(mu.uRings1, 1);
|
||||
gl.uniform1f(mu.iTime, iTime);
|
||||
gl.uniform3f(mu.iResolution, canvas.width, canvas.height, canvas.width / canvas.height);
|
||||
gl.uniform1f(mu.uScale, s.scale);
|
||||
gl.uniform2f(mu.uGridMul, (s.gridX * view.columns) / 15, s.gridY / 15);
|
||||
gl.uniform1f(mu.uDigitSize, s.digitSize);
|
||||
gl.uniform1f(mu.uScanlineIntensity, s.scanlineIntensity);
|
||||
gl.uniform1f(mu.uGlitchAmount, reduce ? 0 : s.glitchAmount);
|
||||
gl.uniform1f(mu.uFlickerAmount, reduce ? 0 : s.flickerAmount);
|
||||
gl.uniform1f(mu.uChromaticAberration, s.chromaticAberration);
|
||||
gl.uniform1f(mu.uDither, s.dither);
|
||||
gl.uniform1f(mu.uCurvature, s.curvature);
|
||||
gl.uniform3fv(mu.uTint, hexToRgb(s.tint));
|
||||
gl.uniform1f(mu.uBrightness, s.brightness);
|
||||
gl.uniform1f(mu.uLightMode, s.lightMode ? 1 : 0);
|
||||
gl.uniform2i(mu.uOrigin, cells.x, cells.y);
|
||||
gl.uniform2i(mu.uCellCount, cells.w, cells.h);
|
||||
gl.uniform1i(mu.uGlyphs, s.glyphs);
|
||||
gl.uniform1f(mu.uGlow, s.glow);
|
||||
gl.uniform1f(mu.uScramble, s.scramble);
|
||||
gl.uniform1f(mu.uMouseGlow, s.mouseGlow);
|
||||
gl.uniform1f(mu.uVignette, s.vignette);
|
||||
gl.uniform4fv(mu.uClicks, clicks);
|
||||
gl.uniform1i(mu.uClickMode, s.clickEffect);
|
||||
gl.uniform1f(mu.uClickSeconds, s.clickSeconds);
|
||||
gl.uniform1f(mu.uClock, clock);
|
||||
gl.bindVertexArray(vao);
|
||||
gl.drawArrays(gl.TRIANGLES, 0, 3);
|
||||
gl.bindVertexArray(null);
|
||||
};
|
||||
|
||||
const resize = () => {
|
||||
const s = settingsRef.current;
|
||||
view.width = Math.max(1, container.clientWidth);
|
||||
view.height = Math.max(1, container.clientHeight);
|
||||
view.ratio = Math.min(s.dpr || window.devicePixelRatio || 1, 2);
|
||||
view.columns = Math.min(1, view.width / view.height / 1.5);
|
||||
canvas.width = Math.max(1, Math.round(view.width * view.ratio));
|
||||
canvas.height = Math.max(1, Math.round(view.height * view.ratio));
|
||||
layoutCells(s);
|
||||
stepCells(s, 0);
|
||||
draw();
|
||||
wake();
|
||||
};
|
||||
|
||||
const frame = now => {
|
||||
raf = 0;
|
||||
if (!visible || document.hidden) return;
|
||||
const s = settingsRef.current;
|
||||
const dt = last ? clamp((now - last) / 1000, 0.001, 1 / 20) : 1 / 60;
|
||||
last = now;
|
||||
clock += dt;
|
||||
if (!s.pause && !reduce) iTime += dt * s.timeScale;
|
||||
const targetX = pointer.inside ? pointer.x : 0.5;
|
||||
const targetY = pointer.inside ? pointer.y : 0.5;
|
||||
const follow = 1 - Math.exp(-dt / (pointer.inside ? 0.19988 : 0.6));
|
||||
mouse.x += (targetX - mouse.x) * follow;
|
||||
mouse.y += (targetY - mouse.y) * follow;
|
||||
hover += ((pointer.inside ? 1 : 0) - hover) * (1 - Math.exp(-dt / 0.35));
|
||||
for (let k = 0; k < MAX_CLICKS; k++) {
|
||||
if (clicks[k * 4 + 3] > 0 && clock - clicks[k * 4 + 2] > s.clickSeconds) clicks[k * 4 + 3] = 0;
|
||||
}
|
||||
layoutCells(s);
|
||||
const decay = s.persistence > 0 ? Math.exp(-dt / (0.08 + s.persistence * 1.4)) : 0;
|
||||
stepCells(s, decay);
|
||||
draw();
|
||||
if (introClock < 1) introClock = Math.min(1, introClock + dt / INTRO_SECONDS);
|
||||
let busy = !(s.pause || reduce) || introClock < 1;
|
||||
busy = busy || Math.abs(targetX - mouse.x) + Math.abs(targetY - mouse.y) > 0.0001;
|
||||
busy = busy || Math.abs((pointer.inside ? 1 : 0) - hover) > 0.001;
|
||||
for (let k = 0; k < MAX_CLICKS; k++) busy = busy || clicks[k * 4 + 3] > 0;
|
||||
quiet = busy ? 0 : quiet + dt;
|
||||
if (quiet < 2.5) raf = requestAnimationFrame(frame);
|
||||
};
|
||||
|
||||
function wake() {
|
||||
quiet = 0;
|
||||
if (!raf && visible && !document.hidden) {
|
||||
last = 0;
|
||||
raf = requestAnimationFrame(frame);
|
||||
}
|
||||
}
|
||||
|
||||
const locate = event => {
|
||||
const rect = container.getBoundingClientRect();
|
||||
const x = (event.clientX - rect.left) / Math.max(rect.width, 1);
|
||||
const y = 1 - (event.clientY - rect.top) / Math.max(rect.height, 1);
|
||||
return { x, y, inside: x >= 0 && x <= 1 && y >= 0 && y <= 1 };
|
||||
};
|
||||
|
||||
const onPointerMove = event => {
|
||||
const { x, y, inside } = locate(event);
|
||||
const was = pointer.inside;
|
||||
pointer.inside = inside;
|
||||
if (inside) {
|
||||
pointer.x = x;
|
||||
pointer.y = y;
|
||||
}
|
||||
if (inside || was) wake();
|
||||
};
|
||||
|
||||
const onPointerDown = event => {
|
||||
const s = settingsRef.current;
|
||||
const { x, y, inside } = locate(event);
|
||||
if (!inside || reduce || !s.clickEffect) return;
|
||||
const o = clickIndex * 4;
|
||||
clicks[o] = x;
|
||||
clicks[o + 1] = y;
|
||||
clicks[o + 2] = clock;
|
||||
clicks[o + 3] = 1;
|
||||
clickIndex = (clickIndex + 1) % MAX_CLICKS;
|
||||
wake();
|
||||
};
|
||||
|
||||
const onPointerLeave = () => {
|
||||
pointer.inside = false;
|
||||
wake();
|
||||
};
|
||||
|
||||
const onVisibility = () => wake();
|
||||
|
||||
const resizeObserver = new ResizeObserver(resize);
|
||||
resizeObserver.observe(container);
|
||||
const intersection = new IntersectionObserver(entries => {
|
||||
visible = entries.some(entry => entry.isIntersecting);
|
||||
if (visible) wake();
|
||||
});
|
||||
intersection.observe(container);
|
||||
window.addEventListener('pointermove', onPointerMove, { passive: true });
|
||||
window.addEventListener('pointerdown', onPointerDown, { passive: true });
|
||||
document.documentElement.addEventListener('pointerleave', onPointerLeave);
|
||||
document.addEventListener('visibilitychange', onVisibility);
|
||||
resize();
|
||||
wakeRef.current = wake;
|
||||
|
||||
return () => {
|
||||
cancelAnimationFrame(raf);
|
||||
wakeRef.current = null;
|
||||
resizeObserver.disconnect();
|
||||
intersection.disconnect();
|
||||
window.removeEventListener('pointermove', onPointerMove);
|
||||
window.removeEventListener('pointerdown', onPointerDown);
|
||||
document.documentElement.removeEventListener('pointerleave', onPointerLeave);
|
||||
document.removeEventListener('visibilitychange', onVisibility);
|
||||
for (const target of targets) {
|
||||
gl.deleteTexture(target.rings);
|
||||
gl.deleteTexture(target.extra);
|
||||
gl.deleteFramebuffer(target.framebuffer);
|
||||
}
|
||||
gl.deleteVertexArray(vao);
|
||||
gl.deleteProgram(cellShader.program);
|
||||
gl.deleteProgram(mainShader.program);
|
||||
gl.getExtension('WEBGL_lose_context')?.loseContext();
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
wakeRef.current?.();
|
||||
});
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={containerRef}
|
||||
className={`relative h-full w-full overflow-hidden${className ? ` ${className}` : ''}`}
|
||||
style={style}
|
||||
{...rest}
|
||||
>
|
||||
<canvas ref={canvasRef} className="absolute inset-0 block h-full w-full" aria-hidden="true" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { lazy, Suspense } from "react";
|
||||
|
||||
const FaultyTerminal = lazy(() => import("./FaultyTerminal.js"));
|
||||
|
||||
export const FaultyTerminalBackdrop = () => (
|
||||
<div aria-hidden="true" className="pointer-events-none fixed inset-0 z-0 opacity-60">
|
||||
<Suspense fallback={null}>
|
||||
<FaultyTerminal
|
||||
tint="#ff5252"
|
||||
glyphs="blocks"
|
||||
brightness={0.7}
|
||||
glow={0.5}
|
||||
vignette={0.28}
|
||||
scanlineIntensity={0.25}
|
||||
persistence={0.4}
|
||||
mouseReact={false}
|
||||
/>
|
||||
</Suspense>
|
||||
</div>
|
||||
);
|
||||
@@ -0,0 +1,175 @@
|
||||
import type { ImgHTMLAttributes } from "react";
|
||||
|
||||
type IconProps = Omit<ImgHTMLAttributes<HTMLImageElement>, "src" | "alt"> & {
|
||||
filled?: boolean;
|
||||
};
|
||||
|
||||
const ImgIcon = ({
|
||||
src,
|
||||
className = "",
|
||||
...props
|
||||
}: { src: string } & IconProps) => (
|
||||
<img
|
||||
src={src}
|
||||
alt=""
|
||||
aria-hidden="true"
|
||||
className={`inline-block h-4 w-4 object-contain ${className}`}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
|
||||
export const FolderIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/folder.webp" {...props} />
|
||||
);
|
||||
|
||||
export const FileIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/document.webp" {...props} />
|
||||
);
|
||||
|
||||
export const ImageIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/picture.webp" {...props} />
|
||||
);
|
||||
|
||||
export const PlayIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/file.webp" {...props} />
|
||||
);
|
||||
|
||||
export const AudioIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/activity.webp" {...props} />
|
||||
);
|
||||
|
||||
export const ArchiveIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/folder.webp" {...props} />
|
||||
);
|
||||
|
||||
export const UploadIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/upload.webp" {...props} />
|
||||
);
|
||||
|
||||
export const DownloadIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/download.webp" {...props} />
|
||||
);
|
||||
|
||||
export const PlusIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/plus.webp" {...props} />
|
||||
);
|
||||
|
||||
export const TrashIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/trash-can.webp" {...props} />
|
||||
);
|
||||
|
||||
export const TrashEmptyIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/trash-empty.webp" {...props} />
|
||||
);
|
||||
|
||||
export const RestoreIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/restore-data.webp" {...props} />
|
||||
);
|
||||
|
||||
export const RefreshIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/synchronize.webp" {...props} />
|
||||
);
|
||||
|
||||
export const StarIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/favorite.webp" {...props} />
|
||||
);
|
||||
|
||||
export const SearchIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/search.webp" {...props} />
|
||||
);
|
||||
|
||||
export const UsersIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/accounts.webp" {...props} />
|
||||
);
|
||||
|
||||
export const SettingsIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/personal-settings.webp" {...props} />
|
||||
);
|
||||
|
||||
export const LogoutIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/sign-out.webp" {...props} />
|
||||
);
|
||||
|
||||
export const ShieldIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/accounts.webp" {...props} />
|
||||
);
|
||||
|
||||
export const HardDriveIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/storage.webp" {...props} />
|
||||
);
|
||||
|
||||
export const ActivityIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/activity.webp" {...props} />
|
||||
);
|
||||
|
||||
export const SearchNavIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/search.webp" {...props} />
|
||||
);
|
||||
|
||||
export const FilterIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/filter.webp" {...props} />
|
||||
);
|
||||
|
||||
export const ShareIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/share.webp" {...props} />
|
||||
);
|
||||
|
||||
export const MenuIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/menu.webp" {...props} />
|
||||
);
|
||||
|
||||
export const CloseIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/close.webp" {...props} />
|
||||
);
|
||||
|
||||
export const ArrowLeftIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/back.webp" {...props} />
|
||||
);
|
||||
|
||||
export const ArrowRightIcon = (props: IconProps) => (
|
||||
<ImgIcon
|
||||
src="/icons/back.webp"
|
||||
{...props}
|
||||
style={{ transform: "rotate(180deg)", ...((props.style as any) || {}) }}
|
||||
/>
|
||||
);
|
||||
|
||||
export const PenIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/edit-pencil.webp" {...props} />
|
||||
);
|
||||
|
||||
export const PinIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/pin.webp" {...props} />
|
||||
);
|
||||
|
||||
export const MoveIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/move.webp" {...props} />
|
||||
);
|
||||
|
||||
export const ChatIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/speech-bubble.webp" {...props} />
|
||||
);
|
||||
|
||||
export const SendIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/send.webp" {...props} />
|
||||
);
|
||||
|
||||
export const ClearIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/clear.webp" {...props} />
|
||||
);
|
||||
|
||||
export const SaveIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/save.webp" {...props} />
|
||||
);
|
||||
|
||||
export const OpenedFolderIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/opened-folder.webp" {...props} />
|
||||
);
|
||||
|
||||
export const DeactivateIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/deactivate.webp" {...props} />
|
||||
);
|
||||
|
||||
export const PasswordResetIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/password-reset.webp" {...props} />
|
||||
);
|
||||
@@ -0,0 +1,244 @@
|
||||
export interface User {
|
||||
id: string;
|
||||
email: string;
|
||||
first_name: string;
|
||||
last_name: string;
|
||||
must_change_password: boolean;
|
||||
}
|
||||
|
||||
export interface Country {
|
||||
id: number;
|
||||
code: string;
|
||||
name: string;
|
||||
phone_code: string | null;
|
||||
}
|
||||
|
||||
export interface Organization {
|
||||
id: string;
|
||||
name: string;
|
||||
slug: string;
|
||||
website: string | null;
|
||||
industry: string | null;
|
||||
phone: string | null;
|
||||
email: string | null;
|
||||
address_line1: string | null;
|
||||
address_line2: string | null;
|
||||
postal_code: string | null;
|
||||
city: string | null;
|
||||
country_id: number | null;
|
||||
country_name: string | null;
|
||||
country_code: string | null;
|
||||
description: string | null;
|
||||
owner_id: string | null;
|
||||
owner_name: string | null;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export interface Contact {
|
||||
id: string;
|
||||
first_name: string;
|
||||
last_name: string;
|
||||
organization_id: string | null;
|
||||
organization_name: string | null;
|
||||
email: string | null;
|
||||
phone: string | null;
|
||||
mobile: string | null;
|
||||
job_title: string | null;
|
||||
country_id: number | null;
|
||||
country_name: string | null;
|
||||
country_code: string | null;
|
||||
external_source: string | null;
|
||||
external_id: string | null;
|
||||
description: string | null;
|
||||
owner_id: string | null;
|
||||
owner_name: string | null;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
/** Corps accepte par les routes creation / mise a jour d'entreprise. */
|
||||
export type OrganizationInput = {
|
||||
name?: string;
|
||||
website?: string | null;
|
||||
industry?: string | null;
|
||||
phone?: string | null;
|
||||
email?: string | null;
|
||||
addressLine1?: string | null;
|
||||
addressLine2?: string | null;
|
||||
postalCode?: string | null;
|
||||
city?: string | null;
|
||||
countryId?: number | null;
|
||||
description?: string | null;
|
||||
};
|
||||
|
||||
/** Corps accepte par les routes creation / mise a jour de prospect. */
|
||||
export type ContactInput = {
|
||||
firstName?: string;
|
||||
lastName?: string;
|
||||
organizationId?: string | null;
|
||||
email?: string | null;
|
||||
phone?: string | null;
|
||||
mobile?: string | null;
|
||||
jobTitle?: string | null;
|
||||
countryId?: number | null;
|
||||
externalSource?: string | null;
|
||||
externalId?: string | null;
|
||||
description?: string | null;
|
||||
};
|
||||
|
||||
/** Pagination renvoyee par les listes, sans type : la donnee est homogene. */
|
||||
export interface Pagination {
|
||||
total: number;
|
||||
page: number;
|
||||
limit: number;
|
||||
}
|
||||
|
||||
export class ApiError extends Error {
|
||||
readonly status: number;
|
||||
|
||||
constructor(status: number, message: string) {
|
||||
super(message);
|
||||
this.name = "ApiError";
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
|
||||
const BASE = "/api/crm";
|
||||
|
||||
/**
|
||||
* Un seul point d'entree HTTP. Le cookie de session est envoye
|
||||
* automatiquement (same-origin), et toute erreur non-2xx devient une
|
||||
* ApiError portant le message serveur, jamais un corps brut.
|
||||
*/
|
||||
const request = async <T>(path: string, init?: RequestInit): Promise<T> => {
|
||||
let response: Response;
|
||||
try {
|
||||
response = await fetch(`${BASE}${path}`, {
|
||||
credentials: "same-origin",
|
||||
...init,
|
||||
headers: {
|
||||
...(init?.body ? { "content-type": "application/json" } : {}),
|
||||
...init?.headers,
|
||||
},
|
||||
});
|
||||
} catch {
|
||||
throw new ApiError(0, "Serveur injoignable. Verifiez votre connexion.");
|
||||
}
|
||||
|
||||
const body: unknown = await response.json().catch(() => null);
|
||||
if (!response.ok) {
|
||||
const message =
|
||||
(body as { error?: { message?: string } } | null)?.error?.message ??
|
||||
"Une erreur est survenue.";
|
||||
throw new ApiError(response.status, message);
|
||||
}
|
||||
return body as T;
|
||||
};
|
||||
|
||||
export const api = {
|
||||
me: () => request<{ user: User }>("/auth/me"),
|
||||
|
||||
login: (email: string, password: string) =>
|
||||
request<{ user: User }>("/auth/login", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ email, password }),
|
||||
}),
|
||||
|
||||
logout: () => request<{ ok: boolean }>("/auth/logout", { method: "POST" }),
|
||||
|
||||
changePassword: (current: string, next: string) =>
|
||||
request<{ ok: boolean }>("/auth/change-password", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ current, next }),
|
||||
}),
|
||||
|
||||
countries: (search?: string) =>
|
||||
request<{ countries: Country[] }>(
|
||||
`/countries${search ? `?q=${encodeURIComponent(search)}` : ""}`,
|
||||
),
|
||||
|
||||
createCountry: (input: { code: string; name: string; phoneCode?: string | null }) =>
|
||||
request<{ country: Country }>("/countries", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(input),
|
||||
}),
|
||||
|
||||
updateCountry: (id: number, input: { code?: string; name?: string; phoneCode?: string | null }) =>
|
||||
request<{ country: Country }>(`/countries/${id}`, {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify(input),
|
||||
}),
|
||||
|
||||
deleteCountry: (id: number) =>
|
||||
request<{ ok: boolean }>(`/countries/${id}`, { method: "DELETE" }),
|
||||
|
||||
organizations: (search?: string, page = 1, limit = 25) => {
|
||||
const params = new URLSearchParams({ page: String(page), limit: String(limit) });
|
||||
if (search) params.set("q", search);
|
||||
return request<{ organizations: Organization[] } & Pagination>(
|
||||
`/organizations?${params.toString()}`,
|
||||
);
|
||||
},
|
||||
|
||||
organization: (id: string) =>
|
||||
request<{ organization: Organization }>(`/organizations/${encodeURIComponent(id)}`),
|
||||
|
||||
createOrganization: (input: OrganizationInput) =>
|
||||
request<{ organization: Organization }>("/organizations", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(input),
|
||||
}),
|
||||
|
||||
updateOrganization: (id: string, input: OrganizationInput) =>
|
||||
request<{ organization: Organization }>(`/organizations/${encodeURIComponent(id)}`, {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify(input),
|
||||
}),
|
||||
|
||||
deleteOrganization: (id: string) =>
|
||||
request<{ ok: boolean }>(`/organizations/${encodeURIComponent(id)}`, { method: "DELETE" }),
|
||||
|
||||
contacts: (options: {
|
||||
search?: string | undefined;
|
||||
organizationId?: string | undefined;
|
||||
page?: number | undefined;
|
||||
limit?: number | undefined;
|
||||
} = {}) => {
|
||||
const params = new URLSearchParams({
|
||||
page: String(options.page ?? 1),
|
||||
limit: String(options.limit ?? 25),
|
||||
});
|
||||
if (options.search) params.set("q", options.search);
|
||||
if (options.organizationId) params.set("organizationId", options.organizationId);
|
||||
return request<{ contacts: Contact[] } & Pagination>(
|
||||
`/contacts?${params.toString()}`,
|
||||
);
|
||||
},
|
||||
|
||||
contact: (id: string) =>
|
||||
request<{ contact: Contact }>(`/contacts/${encodeURIComponent(id)}`),
|
||||
|
||||
createContact: (input: ContactInput) =>
|
||||
request<{ contact: Contact }>("/contacts", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(input),
|
||||
}),
|
||||
|
||||
updateContact: (id: string, input: ContactInput) =>
|
||||
request<{ contact: Contact }>(`/contacts/${encodeURIComponent(id)}`, {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify(input),
|
||||
}),
|
||||
|
||||
deleteContact: (id: string) =>
|
||||
request<{ ok: boolean }>(`/contacts/${encodeURIComponent(id)}`, { method: "DELETE" }),
|
||||
};
|
||||
|
||||
/** Date ISO en date lisible, sans changer de jour a cause du fuseau. */
|
||||
export const formatDate = (iso: string): string =>
|
||||
new Date(iso).toLocaleDateString("fr-FR", {
|
||||
day: "2-digit",
|
||||
month: "2-digit",
|
||||
year: "numeric",
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
import { StrictMode } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import { App } from "./App.js";
|
||||
import "./styles/index.css";
|
||||
|
||||
const container = document.getElementById("root");
|
||||
|
||||
if (!container) {
|
||||
throw new Error("Element racine introuvable");
|
||||
}
|
||||
|
||||
createRoot(container).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
);
|
||||
@@ -0,0 +1,109 @@
|
||||
import { useState, type FormEvent } from "react";
|
||||
import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Input } from "@cohaise/ui";
|
||||
import { ApiError, api, type User } from "../lib/api.js";
|
||||
|
||||
interface Props {
|
||||
user: User;
|
||||
onCompleted: () => void;
|
||||
onLogout: () => void;
|
||||
}
|
||||
|
||||
export const ChangePassword = ({ user, onCompleted, onLogout }: Props) => {
|
||||
const [current, setCurrent] = useState("");
|
||||
const [next, setNext] = useState("");
|
||||
const [confirm, setConfirm] = useState("");
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
|
||||
if (next !== confirm) {
|
||||
setError("Les deux mots de passe ne correspondent pas.");
|
||||
return;
|
||||
}
|
||||
if (next.length < 8) {
|
||||
setError("Le nouveau mot de passe doit contenir au moins 8 caractères.");
|
||||
return;
|
||||
}
|
||||
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
await api.changePassword(current, next);
|
||||
onCompleted();
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Modification impossible.");
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<main className="flex min-h-dvh items-center justify-center bg-background px-4 py-10">
|
||||
<div className="w-full max-w-sm">
|
||||
<header className="mb-6 text-center">
|
||||
<p className="font-display text-xs font-semibold uppercase tracking-logo text-accent">
|
||||
CoHaiSe
|
||||
</p>
|
||||
<h1 className="font-display mt-2 text-lg font-semibold uppercase tracking-label text-foreground">
|
||||
Nouveau mot de passe
|
||||
</h1>
|
||||
<p className="mt-2 text-sm leading-relaxed text-muted-foreground">
|
||||
Bienvenue {user.first_name}. Ce mot de passe a été défini par un
|
||||
administrateur : choisissez le vôtre.
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Changement requis</CardTitle>
|
||||
<CardDescription>
|
||||
Les autres sessions ouvertes sur ce compte seront fermées.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form className="flex flex-col gap-4" onSubmit={(event) => void submit(event)}>
|
||||
<Input
|
||||
label="Mot de passe actuel"
|
||||
type="password"
|
||||
autoComplete="current-password"
|
||||
required
|
||||
autoFocus
|
||||
value={current}
|
||||
onChange={(event) => setCurrent(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Nouveau mot de passe"
|
||||
type="password"
|
||||
autoComplete="new-password"
|
||||
required
|
||||
minLength={8}
|
||||
hint="8 caractères minimum."
|
||||
value={next}
|
||||
onChange={(event) => setNext(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Confirmation"
|
||||
type="password"
|
||||
autoComplete="new-password"
|
||||
required
|
||||
minLength={8}
|
||||
value={confirm}
|
||||
onChange={(event) => setConfirm(event.target.value)}
|
||||
{...(error ? { error } : {})}
|
||||
/>
|
||||
|
||||
<Button type="submit" size="lg" fullWidth isLoading={busy}>
|
||||
Enregistrer
|
||||
</Button>
|
||||
<Button type="button" variant="ghost" size="md" fullWidth onClick={onLogout}>
|
||||
Se déconnecter
|
||||
</Button>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,339 @@
|
||||
import { useCallback, useEffect, useState, type FormEvent } from "react";
|
||||
import { Button, Card, CardContent, CardHeader, CardTitle, Input, Skeleton } from "@cohaise/ui";
|
||||
import {
|
||||
ApiError,
|
||||
api,
|
||||
formatDate,
|
||||
type Contact,
|
||||
type ContactInput,
|
||||
type Country,
|
||||
type Organization,
|
||||
} from "../lib/api.js";
|
||||
|
||||
const EMPTY: ContactInput = {
|
||||
firstName: "",
|
||||
lastName: "",
|
||||
organizationId: null,
|
||||
email: null,
|
||||
phone: null,
|
||||
mobile: null,
|
||||
jobTitle: null,
|
||||
countryId: null,
|
||||
description: null,
|
||||
};
|
||||
|
||||
const text = (value: string): string | null => (value.trim() ? value.trim() : null);
|
||||
|
||||
export const Contacts = () => {
|
||||
const [rows, setRows] = useState<Contact[]>([]);
|
||||
const [organizations, setOrganizations] = useState<Organization[]>([]);
|
||||
const [countries, setCountries] = useState<Country[]>([]);
|
||||
const [total, setTotal] = useState(0);
|
||||
const [search, setSearch] = useState("");
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [editing, setEditing] = useState<Contact | null>(null);
|
||||
const [form, setForm] = useState<ContactInput>(EMPTY);
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
const load = useCallback(async () => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const result = await api.contacts({ search: search || undefined });
|
||||
setRows(result.contacts);
|
||||
setTotal(result.total);
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Chargement impossible.");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [search]);
|
||||
|
||||
useEffect(() => {
|
||||
void load();
|
||||
}, [load]);
|
||||
|
||||
// Les listes deroulantes sont des donnees de reference : leur echec ne doit
|
||||
// pas empecher l'ecran de s'afficher, on les laisse vides.
|
||||
useEffect(() => {
|
||||
void api
|
||||
.countries()
|
||||
.then((result) => setCountries(result.countries))
|
||||
.catch(() => undefined);
|
||||
void api
|
||||
.organizations(undefined, 1, 100)
|
||||
.then((result) => setOrganizations(result.organizations))
|
||||
.catch(() => undefined);
|
||||
}, []);
|
||||
|
||||
const openCreate = () => {
|
||||
setEditing(null);
|
||||
setForm(EMPTY);
|
||||
setError(null);
|
||||
setOpen(true);
|
||||
};
|
||||
|
||||
const openEdit = (contact: Contact) => {
|
||||
setOpen(true);
|
||||
setEditing(contact);
|
||||
setForm({
|
||||
firstName: contact.first_name,
|
||||
lastName: contact.last_name,
|
||||
organizationId: contact.organization_id,
|
||||
email: contact.email,
|
||||
phone: contact.phone,
|
||||
mobile: contact.mobile,
|
||||
jobTitle: contact.job_title,
|
||||
countryId: contact.country_id,
|
||||
description: contact.description,
|
||||
});
|
||||
setError(null);
|
||||
};
|
||||
|
||||
const close = () => {
|
||||
setEditing(null);
|
||||
setForm(EMPTY);
|
||||
setError(null);
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
const firstName = text(form.firstName ?? "");
|
||||
const lastName = text(form.lastName ?? "");
|
||||
if (!firstName || !lastName) {
|
||||
setError("Le prénom et le nom sont obligatoires.");
|
||||
return;
|
||||
}
|
||||
|
||||
const payload: ContactInput = {
|
||||
firstName,
|
||||
lastName,
|
||||
organizationId: form.organizationId ?? null,
|
||||
email: text(form.email ?? ""),
|
||||
phone: text(form.phone ?? ""),
|
||||
mobile: text(form.mobile ?? ""),
|
||||
jobTitle: text(form.jobTitle ?? ""),
|
||||
countryId: form.countryId ?? null,
|
||||
description: text(form.description ?? ""),
|
||||
};
|
||||
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
if (editing) await api.updateContact(editing.id, payload);
|
||||
else await api.createContact(payload);
|
||||
close();
|
||||
await load();
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Enregistrement impossible.");
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
const remove = async (contact: Contact) => {
|
||||
const label = `${contact.first_name} ${contact.last_name}`;
|
||||
if (!window.confirm(`Supprimer « ${label} » ?`)) return;
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
await api.deleteContact(contact.id);
|
||||
await load();
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Suppression impossible.");
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
const set = (key: keyof ContactInput) => (value: string | number | null) => {
|
||||
setForm((current) => ({
|
||||
...current,
|
||||
[key]: key === "countryId" ? (value === null ? null : Number(value)) : text(String(value ?? "")),
|
||||
}));
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex min-h-0 flex-1 flex-col gap-6">
|
||||
<div className="flex flex-wrap items-end justify-between gap-4">
|
||||
<div className="w-full max-w-xs">
|
||||
<Input
|
||||
label="Rechercher"
|
||||
type="search"
|
||||
placeholder="Prénom, nom, e-mail, entreprise…"
|
||||
value={search}
|
||||
onChange={(event) => setSearch(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<Button onClick={openCreate}>Nouveau prospect</Button>
|
||||
</div>
|
||||
|
||||
{open ? (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>{editing ? "Modifier le prospect" : "Nouveau prospect"}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form className="grid gap-4 sm:grid-cols-2" onSubmit={(event) => void submit(event)}>
|
||||
<Input
|
||||
label="Prénom *"
|
||||
required
|
||||
value={form.firstName ?? ""}
|
||||
onChange={(event) => set("firstName")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Nom *"
|
||||
required
|
||||
value={form.lastName ?? ""}
|
||||
onChange={(event) => set("lastName")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Fonction"
|
||||
value={form.jobTitle ?? ""}
|
||||
onChange={(event) => set("jobTitle")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="E-mail"
|
||||
type="email"
|
||||
value={form.email ?? ""}
|
||||
onChange={(event) => set("email")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Téléphone"
|
||||
value={form.phone ?? ""}
|
||||
onChange={(event) => set("phone")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Mobile"
|
||||
value={form.mobile ?? ""}
|
||||
onChange={(event) => set("mobile")(event.target.value)}
|
||||
/>
|
||||
<label className="flex flex-col gap-2 text-sm font-medium text-foreground">
|
||||
Entreprise
|
||||
<select
|
||||
className="h-10 rounded-md border border-border-control bg-background px-3 text-sm"
|
||||
value={form.organizationId ?? ""}
|
||||
onChange={(event) => set("organizationId")(event.target.value || null)}
|
||||
>
|
||||
<option value="">— Aucune —</option>
|
||||
{organizations.map((organization) => (
|
||||
<option key={organization.id} value={organization.id}>
|
||||
{organization.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label className="flex flex-col gap-2 text-sm font-medium text-foreground">
|
||||
Pays
|
||||
<select
|
||||
className="h-10 rounded-md border border-border-control bg-background px-3 text-sm"
|
||||
value={form.countryId ?? ""}
|
||||
onChange={(event) =>
|
||||
set("countryId")(event.target.value ? Number(event.target.value) : null)
|
||||
}
|
||||
>
|
||||
<option value="">— Aucun —</option>
|
||||
{countries.map((country) => (
|
||||
<option key={country.id} value={country.id}>
|
||||
{country.name} ({country.code})
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<div className="sm:col-span-2">
|
||||
<Input
|
||||
label="Notes"
|
||||
value={form.description ?? ""}
|
||||
onChange={(event) => set("description")(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{error ? (
|
||||
<p className="text-sm text-destructive sm:col-span-2" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
<div className="flex gap-3 sm:col-span-2">
|
||||
<Button type="submit" isLoading={busy}>
|
||||
{editing ? "Enregistrer" : "Créer"}
|
||||
</Button>
|
||||
<Button type="button" variant="secondary" onClick={close}>
|
||||
Annuler
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
) : null}
|
||||
|
||||
{loading ? (
|
||||
<div className="flex flex-col gap-3">
|
||||
<Skeleton className="h-10" />
|
||||
<Skeleton className="h-10" />
|
||||
<Skeleton className="h-10" />
|
||||
</div>
|
||||
) : error && rows.length === 0 ? (
|
||||
<p className="text-sm text-destructive">{error}</p>
|
||||
) : rows.length === 0 ? (
|
||||
<Card>
|
||||
<CardContent>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Aucun prospect. Ajoutez le premier pour commencer.
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
) : (
|
||||
<div className="min-h-0 flex-1 overflow-y-auto overflow-x-auto">
|
||||
<table className="w-full border-collapse text-sm">
|
||||
<thead>
|
||||
<tr className="border-b border-border-control text-left text-xs uppercase tracking-label text-subtle-foreground">
|
||||
<th className="py-2 pr-4">Nom</th>
|
||||
<th className="py-2 pr-4">Fonction</th>
|
||||
<th className="py-2 pr-4">Entreprise</th>
|
||||
<th className="py-2 pr-4">Contact</th>
|
||||
<th className="py-2 pr-4">Pays</th>
|
||||
<th className="py-2 pr-4">Ajouté le</th>
|
||||
<th className="py-2 pr-4 text-right">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{rows.map((contact) => (
|
||||
<tr key={contact.id} className="border-b border-border-control/60">
|
||||
<td className="py-3 pr-4 font-medium">
|
||||
{contact.last_name} {contact.first_name}
|
||||
</td>
|
||||
<td className="py-3 pr-4">{contact.job_title ?? "—"}</td>
|
||||
<td className="py-3 pr-4">{contact.organization_name ?? "—"}</td>
|
||||
<td className="py-3 pr-4">{contact.email ?? contact.phone ?? "—"}</td>
|
||||
<td className="py-3 pr-4">{contact.country_code ?? "—"}</td>
|
||||
<td className="py-3 pr-4 text-subtle-foreground">
|
||||
{formatDate(contact.created_at)}
|
||||
</td>
|
||||
<td className="py-3 pr-4">
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button size="sm" variant="secondary" onClick={() => openEdit(contact)}>
|
||||
Modifier
|
||||
</Button>
|
||||
{
|
||||
<Button size="sm" variant="destructive" onClick={() => void remove(contact)}>
|
||||
Supprimer
|
||||
</Button>
|
||||
}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
<p className="mt-3 text-xs text-subtle-foreground">
|
||||
{total} prospect{total > 1 ? "s" : ""}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,226 @@
|
||||
import { useCallback, useEffect, useState, type FormEvent } from "react";
|
||||
import { Button, Card, CardContent, CardHeader, CardTitle, Input, Skeleton } from "@cohaise/ui";
|
||||
import { ApiError, api, type Country } from "../lib/api.js";
|
||||
|
||||
interface Form {
|
||||
code: string;
|
||||
name: string;
|
||||
phoneCode: string;
|
||||
}
|
||||
|
||||
const EMPTY: Form = { code: "", name: "", phoneCode: "" };
|
||||
|
||||
export const Countries = () => {
|
||||
const [rows, setRows] = useState<Country[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [editing, setEditing] = useState<Country | null>(null);
|
||||
const [form, setForm] = useState<Form>(EMPTY);
|
||||
|
||||
const load = useCallback(async () => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const result = await api.countries();
|
||||
setRows(result.countries);
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Chargement impossible.");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
void load();
|
||||
}, [load]);
|
||||
|
||||
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
const code = form.code.trim().toUpperCase();
|
||||
const name = form.name.trim();
|
||||
if (!/^[A-Z]{2}$/.test(code)) {
|
||||
setError("Le code doit contenir exactement deux lettres.");
|
||||
return;
|
||||
}
|
||||
if (!name) {
|
||||
setError("Le nom est obligatoire.");
|
||||
return;
|
||||
}
|
||||
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
const payload = { code, name, phoneCode: form.phoneCode.trim() || null };
|
||||
if (editing) await api.updateCountry(editing.id, payload);
|
||||
else await api.createCountry(payload);
|
||||
setEditing(null);
|
||||
setForm(EMPTY);
|
||||
setOpen(false);
|
||||
await load();
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Enregistrement impossible.");
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
const remove = async (country: Country) => {
|
||||
if (!window.confirm(`Supprimer « ${country.name} » ?`)) return;
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
await api.deleteCountry(country.id);
|
||||
await load();
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Suppression impossible.");
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex min-h-0 flex-1 flex-col gap-6">
|
||||
<div className="flex flex-wrap items-end justify-between gap-4">
|
||||
<p className="max-w-lg text-sm text-muted-foreground">
|
||||
Référentiel ISO 3166 utilisé par les entreprises et les prospects. Il ne contient
|
||||
que les pays déjà saisis dans la base.
|
||||
</p>
|
||||
{
|
||||
<Button
|
||||
onClick={() => {
|
||||
setEditing(null);
|
||||
setForm(EMPTY);
|
||||
setError(null);
|
||||
setOpen(true);
|
||||
}}
|
||||
>
|
||||
Nouveau pays
|
||||
</Button>
|
||||
}
|
||||
</div>
|
||||
|
||||
{open && (
|
||||
<Card className="shrink-0">
|
||||
<CardHeader>
|
||||
<CardTitle>{editing ? "Modifier le pays" : "Nouveau pays"}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form
|
||||
className="grid gap-4 sm:grid-cols-3"
|
||||
onSubmit={(event) => void submit(event)}
|
||||
>
|
||||
<Input
|
||||
label="Code *"
|
||||
required
|
||||
maxLength={2}
|
||||
placeholder="FR"
|
||||
value={form.code}
|
||||
onChange={(event) =>
|
||||
setForm((current) => ({ ...current, code: event.target.value.toUpperCase() }))
|
||||
}
|
||||
/>
|
||||
<Input
|
||||
label="Nom *"
|
||||
required
|
||||
value={form.name}
|
||||
onChange={(event) => setForm((current) => ({ ...current, name: event.target.value }))}
|
||||
/>
|
||||
<Input
|
||||
label="Indicatif"
|
||||
placeholder="+33"
|
||||
value={form.phoneCode}
|
||||
onChange={(event) =>
|
||||
setForm((current) => ({ ...current, phoneCode: event.target.value }))
|
||||
}
|
||||
/>
|
||||
|
||||
{error ? (
|
||||
<p className="text-sm text-destructive sm:col-span-3" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
<div className="flex gap-3 sm:col-span-3">
|
||||
<Button type="submit" isLoading={busy}>
|
||||
{editing ? "Enregistrer" : "Créer"}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="secondary"
|
||||
onClick={() => {
|
||||
setEditing(null);
|
||||
setForm(EMPTY);
|
||||
setError(null);
|
||||
setOpen(false);
|
||||
}}
|
||||
>
|
||||
Annuler
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{error && rows.length === 0 ? (
|
||||
<p className="text-sm text-destructive">{error}</p>
|
||||
) : loading ? (
|
||||
<div className="flex flex-col gap-3">
|
||||
<Skeleton className="h-10" />
|
||||
<Skeleton className="h-10" />
|
||||
<Skeleton className="h-10" />
|
||||
</div>
|
||||
) : (
|
||||
<div className="min-h-0 flex-1 overflow-y-auto overflow-x-auto">
|
||||
<table className="w-full border-collapse text-sm">
|
||||
<thead>
|
||||
<tr className="border-b border-border-control text-left text-xs uppercase tracking-label text-subtle-foreground">
|
||||
<th className="py-2 pr-4">Code</th>
|
||||
<th className="py-2 pr-4">Nom</th>
|
||||
<th className="py-2 pr-4">Indicatif</th>
|
||||
<th className="py-2 pr-4 text-right">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{rows.map((country) => (
|
||||
<tr key={country.id} className="border-b border-border-control/60">
|
||||
<td className="py-3 pr-4 font-medium">{country.code}</td>
|
||||
<td className="py-3 pr-4">{country.name}</td>
|
||||
<td className="py-3 pr-4">{country.phone_code ?? "—"}</td>
|
||||
{
|
||||
<td className="py-3 pr-4">
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="secondary"
|
||||
onClick={() => {
|
||||
setEditing(country);
|
||||
setForm({
|
||||
code: country.code,
|
||||
name: country.name,
|
||||
phoneCode: country.phone_code ?? "",
|
||||
});
|
||||
setError(null);
|
||||
setOpen(true);
|
||||
}}
|
||||
>
|
||||
Modifier
|
||||
</Button>
|
||||
<Button size="sm" variant="destructive" onClick={() => void remove(country)}>
|
||||
Supprimer
|
||||
</Button>
|
||||
</div>
|
||||
</td>
|
||||
}
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
<p className="mt-3 text-xs text-subtle-foreground">{rows.length} pays</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,85 @@
|
||||
import { useState } from "react";
|
||||
import { Button, cn } from "@cohaise/ui";
|
||||
import type { User } from "../lib/api.js";
|
||||
import { Organizations } from "./Organizations.js";
|
||||
import { Contacts } from "./Contacts.js";
|
||||
import { Countries } from "./Countries.js";
|
||||
import { FaultyTerminalBackdrop } from "../components/FaultyTerminalBackdrop.js";
|
||||
import { ActivityIcon, FolderIcon, LogoutIcon, UsersIcon } from "../components/icons.js";
|
||||
|
||||
type Tab = "organizations" | "contacts" | "countries";
|
||||
|
||||
const TABS: { id: Tab; label: string; icon: typeof FolderIcon }[] = [
|
||||
{ id: "organizations", label: "Entreprises", icon: FolderIcon },
|
||||
{ id: "contacts", label: "Prospects", icon: UsersIcon },
|
||||
{ id: "countries", label: "Pays", icon: ActivityIcon },
|
||||
];
|
||||
|
||||
export const Crm = ({ user, onLogout }: { user: User; onLogout: () => void }) => {
|
||||
const [tab, setTab] = useState<Tab>("organizations");
|
||||
|
||||
return (
|
||||
<div className="relative flex h-dvh flex-col overflow-hidden bg-background text-foreground">
|
||||
<FaultyTerminalBackdrop />
|
||||
|
||||
<div className="relative z-10 flex h-full min-h-0 flex-col gap-3 p-3 sm:p-4">
|
||||
<header className="glass flex shrink-0 items-center justify-between gap-4 rounded-xl border border-border/50 px-4 py-3 shadow-sm">
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="font-logo text-sm font-bold tracking-logo text-accent">COHAISE</span>
|
||||
<span className="text-border" aria-hidden="true">
|
||||
/
|
||||
</span>
|
||||
<span className="font-display text-sm font-semibold uppercase tracking-label">CRM</span>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="hidden text-right sm:block">
|
||||
<p className="text-sm font-medium">
|
||||
{user.first_name} {user.last_name}
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={onLogout}
|
||||
iconLeading={<LogoutIcon />}
|
||||
>
|
||||
Se déconnecter
|
||||
</Button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<nav className="glass flex shrink-0 items-center gap-1 rounded-xl border border-border/50 p-1.5">
|
||||
{TABS.map((item) => {
|
||||
const Icon = item.icon;
|
||||
return (
|
||||
<button
|
||||
key={item.id}
|
||||
type="button"
|
||||
onClick={() => setTab(item.id)}
|
||||
aria-current={tab === item.id ? "page" : undefined}
|
||||
className={cn(
|
||||
"flex items-center gap-2 rounded-lg px-3 py-2 text-sm font-medium transition-colors",
|
||||
tab === item.id
|
||||
? "bg-accent/10 text-accent"
|
||||
: "text-muted-foreground hover:bg-surface-hover hover:text-foreground",
|
||||
)}
|
||||
>
|
||||
<Icon />
|
||||
{item.label}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
|
||||
<main className="glass flex min-h-0 flex-1 flex-col overflow-hidden rounded-xl border border-border/50">
|
||||
<div className="mx-auto flex min-h-0 w-full max-w-6xl flex-1 flex-col px-4 py-6">
|
||||
{tab === "organizations" ? <Organizations /> : null}
|
||||
{tab === "contacts" ? <Contacts /> : null}
|
||||
{tab === "countries" ? <Countries /> : null}
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,83 @@
|
||||
import { useState, type FormEvent } from "react";
|
||||
import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Input } from "@cohaise/ui";
|
||||
import { ApiError, api, type User } from "../lib/api.js";
|
||||
|
||||
export const Login = ({ onAuthenticated }: { onAuthenticated: (user: User) => void }) => {
|
||||
const [email, setEmail] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
const { user } = await api.login(email.trim(), password);
|
||||
onAuthenticated(user);
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Connexion impossible.");
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<main className="flex min-h-dvh items-center justify-center bg-background px-4 py-10">
|
||||
<div className="w-full max-w-sm">
|
||||
<header className="mb-6 text-center">
|
||||
<p className="font-display text-xs font-semibold uppercase tracking-logo text-accent">
|
||||
CoHaiSe
|
||||
</p>
|
||||
<h1 className="font-display mt-2 text-lg font-semibold uppercase tracking-label text-foreground">
|
||||
CRM
|
||||
</h1>
|
||||
<p className="mt-2 text-sm leading-relaxed text-muted-foreground">
|
||||
Connectez-vous pour accéder à vos entreprises et prospects.
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Connexion</CardTitle>
|
||||
<CardDescription>Votre session reste ouverte 14 jours.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form className="flex flex-col gap-4" onSubmit={(event) => void submit(event)}>
|
||||
<Input
|
||||
label="Adresse e-mail"
|
||||
type="email"
|
||||
name="email"
|
||||
autoComplete="username"
|
||||
required
|
||||
autoFocus
|
||||
placeholder="[email protected]"
|
||||
value={email}
|
||||
onChange={(event) => setEmail(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Mot de passe"
|
||||
type="password"
|
||||
name="password"
|
||||
autoComplete="current-password"
|
||||
required
|
||||
placeholder="••••••••"
|
||||
value={password}
|
||||
onChange={(event) => setPassword(event.target.value)}
|
||||
{...(error ? { error } : {})}
|
||||
/>
|
||||
|
||||
<Button type="submit" size="lg" fullWidth isLoading={busy}>
|
||||
Se connecter
|
||||
</Button>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<p className="mt-5 text-center text-xs leading-relaxed text-subtle-foreground">
|
||||
Mot de passe oublié ? Contactez un administrateur.
|
||||
</p>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,344 @@
|
||||
import { useCallback, useEffect, useState, type FormEvent } from "react";
|
||||
import { Button, Card, CardContent, CardHeader, CardTitle, Input, Skeleton, Spinner } from "@cohaise/ui";
|
||||
import {
|
||||
ApiError,
|
||||
api,
|
||||
formatDate,
|
||||
type Country,
|
||||
type Organization,
|
||||
type OrganizationInput,
|
||||
} from "../lib/api.js";
|
||||
|
||||
const EMPTY: OrganizationInput = {
|
||||
name: "",
|
||||
website: null,
|
||||
industry: null,
|
||||
phone: null,
|
||||
email: null,
|
||||
addressLine1: null,
|
||||
addressLine2: null,
|
||||
postalCode: null,
|
||||
city: null,
|
||||
countryId: null,
|
||||
description: null,
|
||||
};
|
||||
|
||||
const text = (value: string): string | null => (value.trim() ? value.trim() : null);
|
||||
|
||||
export const Organizations = () => {
|
||||
const [rows, setRows] = useState<Organization[]>([]);
|
||||
const [countries, setCountries] = useState<Country[]>([]);
|
||||
const [total, setTotal] = useState(0);
|
||||
const [search, setSearch] = useState("");
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [editing, setEditing] = useState<Organization | null>(null);
|
||||
const [form, setForm] = useState<OrganizationInput>(EMPTY);
|
||||
// Un etat explicite : comparer form a EMPTY ne fonctionnerait pas, car
|
||||
// saisir puis effacer recrée un objet different de la constante.
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
const load = useCallback(async () => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const result = await api.organizations(search || undefined);
|
||||
setRows(result.organizations);
|
||||
setTotal(result.total);
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Chargement impossible.");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [search]);
|
||||
|
||||
useEffect(() => {
|
||||
void load();
|
||||
}, [load]);
|
||||
|
||||
useEffect(() => {
|
||||
void api
|
||||
.countries()
|
||||
.then((result) => setCountries(result.countries))
|
||||
.catch(() => undefined);
|
||||
}, []);
|
||||
|
||||
const openCreate = () => {
|
||||
setEditing(null);
|
||||
setForm(EMPTY);
|
||||
setError(null);
|
||||
setOpen(true);
|
||||
};
|
||||
|
||||
const openEdit = (organization: Organization) => {
|
||||
setOpen(true);
|
||||
setEditing(organization);
|
||||
setForm({
|
||||
name: organization.name,
|
||||
website: organization.website,
|
||||
industry: organization.industry,
|
||||
phone: organization.phone,
|
||||
email: organization.email,
|
||||
addressLine1: organization.address_line1,
|
||||
addressLine2: organization.address_line2,
|
||||
postalCode: organization.postal_code,
|
||||
city: organization.city,
|
||||
countryId: organization.country_id,
|
||||
description: organization.description,
|
||||
});
|
||||
setError(null);
|
||||
};
|
||||
|
||||
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
const name = text(form.name ?? "");
|
||||
if (!name) {
|
||||
setError("Le nom de l'entreprise est obligatoire.");
|
||||
return;
|
||||
}
|
||||
|
||||
const payload: OrganizationInput = {
|
||||
name,
|
||||
website: text(form.website ?? ""),
|
||||
industry: text(form.industry ?? ""),
|
||||
phone: text(form.phone ?? ""),
|
||||
email: text(form.email ?? ""),
|
||||
addressLine1: text(form.addressLine1 ?? ""),
|
||||
addressLine2: text(form.addressLine2 ?? ""),
|
||||
postalCode: text(form.postalCode ?? ""),
|
||||
city: text(form.city ?? ""),
|
||||
countryId: form.countryId ?? null,
|
||||
description: text(form.description ?? ""),
|
||||
};
|
||||
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
if (editing) await api.updateOrganization(editing.id, payload);
|
||||
else await api.createOrganization(payload);
|
||||
setEditing(null);
|
||||
setForm(EMPTY);
|
||||
setOpen(false);
|
||||
await load();
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Enregistrement impossible.");
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
const remove = async (organization: Organization) => {
|
||||
if (!window.confirm(`Supprimer « ${organization.name} » ? Cette action est réversible par un administrateur.`)) {
|
||||
return;
|
||||
}
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
await api.deleteOrganization(organization.id);
|
||||
await load();
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Suppression impossible.");
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
const set = (key: keyof OrganizationInput) => (value: string | number | null) => {
|
||||
setForm((current) => ({
|
||||
...current,
|
||||
[key]: key === "countryId" ? (value === null ? null : Number(value)) : text(String(value ?? "")),
|
||||
}));
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex min-h-0 flex-1 flex-col gap-6">
|
||||
<div className="flex flex-wrap items-end justify-between gap-4">
|
||||
<div className="w-full max-w-xs">
|
||||
<Input
|
||||
label="Rechercher"
|
||||
type="search"
|
||||
placeholder="Nom, ville, secteur…"
|
||||
value={search}
|
||||
onChange={(event) => setSearch(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<Button onClick={openCreate}>Nouvelle entreprise</Button>
|
||||
</div>
|
||||
|
||||
{open ? (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>{editing ? "Modifier l'entreprise" : "Nouvelle entreprise"}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form className="grid gap-4 sm:grid-cols-2" onSubmit={(event) => void submit(event)}>
|
||||
<Input
|
||||
label="Nom *"
|
||||
required
|
||||
value={form.name ?? ""}
|
||||
onChange={(event) => set("name")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Secteur"
|
||||
value={form.industry ?? ""}
|
||||
onChange={(event) => set("industry")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Site web"
|
||||
type="url"
|
||||
value={form.website ?? ""}
|
||||
onChange={(event) => set("website")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="E-mail"
|
||||
type="email"
|
||||
value={form.email ?? ""}
|
||||
onChange={(event) => set("email")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Téléphone"
|
||||
value={form.phone ?? ""}
|
||||
onChange={(event) => set("phone")(event.target.value)}
|
||||
/>
|
||||
<label className="flex flex-col gap-2 text-sm font-medium text-foreground">
|
||||
Pays
|
||||
<select
|
||||
className="h-10 rounded-md border border-border-control bg-background px-3 text-sm"
|
||||
value={form.countryId ?? ""}
|
||||
onChange={(event) =>
|
||||
set("countryId")(event.target.value ? Number(event.target.value) : null)
|
||||
}
|
||||
>
|
||||
<option value="">— Aucun —</option>
|
||||
{countries.map((country) => (
|
||||
<option key={country.id} value={country.id}>
|
||||
{country.name} ({country.code})
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<Input
|
||||
label="Adresse"
|
||||
value={form.addressLine1 ?? ""}
|
||||
onChange={(event) => set("addressLine1")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Complément"
|
||||
value={form.addressLine2 ?? ""}
|
||||
onChange={(event) => set("addressLine2")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Code postal"
|
||||
value={form.postalCode ?? ""}
|
||||
onChange={(event) => set("postalCode")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Ville"
|
||||
value={form.city ?? ""}
|
||||
onChange={(event) => set("city")(event.target.value)}
|
||||
/>
|
||||
<div className="sm:col-span-2">
|
||||
<Input
|
||||
label="Notes"
|
||||
value={form.description ?? ""}
|
||||
onChange={(event) => set("description")(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{error ? (
|
||||
<p className="text-sm text-destructive sm:col-span-2" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
<div className="flex gap-3 sm:col-span-2">
|
||||
<Button type="submit" isLoading={busy}>
|
||||
{editing ? "Enregistrer" : "Créer"}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="secondary"
|
||||
onClick={() => {
|
||||
setEditing(null);
|
||||
setForm(EMPTY);
|
||||
setError(null);
|
||||
setOpen(false);
|
||||
}}
|
||||
>
|
||||
Annuler
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
) : null}
|
||||
|
||||
{loading ? (
|
||||
<div className="flex flex-col gap-3">
|
||||
<Skeleton className="h-10" />
|
||||
<Skeleton className="h-10" />
|
||||
<Skeleton className="h-10" />
|
||||
</div>
|
||||
) : error && rows.length === 0 ? (
|
||||
<p className="text-sm text-destructive">{error}</p>
|
||||
) : rows.length === 0 ? (
|
||||
<Card>
|
||||
<CardContent>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Aucune entreprise. Créez la première pour commencer.
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
) : (
|
||||
<div className="min-h-0 flex-1 overflow-y-auto overflow-x-auto">
|
||||
<table className="w-full border-collapse text-sm">
|
||||
<thead>
|
||||
<tr className="border-b border-border-control text-left text-xs uppercase tracking-label text-subtle-foreground">
|
||||
<th className="py-2 pr-4">Nom</th>
|
||||
<th className="py-2 pr-4">Ville</th>
|
||||
<th className="py-2 pr-4">Pays</th>
|
||||
<th className="py-2 pr-4">Secteur</th>
|
||||
<th className="py-2 pr-4">Contact</th>
|
||||
<th className="py-2 pr-4">Créée le</th>
|
||||
<th className="py-2 pr-4 text-right">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{rows.map((organization) => (
|
||||
<tr key={organization.id} className="border-b border-border-control/60">
|
||||
<td className="py-3 pr-4 font-medium">{organization.name}</td>
|
||||
<td className="py-3 pr-4">{organization.city ?? "—"}</td>
|
||||
<td className="py-3 pr-4">{organization.country_code ?? "—"}</td>
|
||||
<td className="py-3 pr-4">{organization.industry ?? "—"}</td>
|
||||
<td className="py-3 pr-4">
|
||||
{organization.email ?? organization.phone ?? "—"}
|
||||
</td>
|
||||
<td className="py-3 pr-4 text-subtle-foreground">
|
||||
{formatDate(organization.created_at)}
|
||||
</td>
|
||||
<td className="py-3 pr-4">
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button size="sm" variant="secondary" onClick={() => openEdit(organization)}>
|
||||
Modifier
|
||||
</Button>
|
||||
{
|
||||
<Button size="sm" variant="destructive" onClick={() => void remove(organization)}>
|
||||
Supprimer
|
||||
</Button>
|
||||
}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
<p className="mt-3 text-xs text-subtle-foreground">
|
||||
{total} entreprise{total > 1 ? "s" : ""}
|
||||
{loading ? <Spinner size="xs" /> : null}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
@import "tailwindcss";
|
||||
@import "@cohaise/ui/styles";
|
||||
|
||||
@source "../../../../frontend/shared/src";
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
||||
"jsx": "react-jsx",
|
||||
"types": ["vite/client"],
|
||||
"noEmit": true
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.tsx"]
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { defineConfig } from "vite";
|
||||
import react from "@vitejs/plugin-react";
|
||||
import tailwindcss from "@tailwindcss/vite";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react(), tailwindcss()],
|
||||
server: {
|
||||
host: true,
|
||||
port: 5175,
|
||||
// En developpement, l'API CRM tourne sur 3002 ; en production nginx
|
||||
// intercepte /api/ lui-meme. Meme chemin des deux cotes.
|
||||
proxy: {
|
||||
"/api": {
|
||||
target: "http://127.0.0.1:3202",
|
||||
changeOrigin: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,186 @@
|
||||
# @cohaise/ui
|
||||
|
||||
Design system partagé de l'écosystème CoHaiSe. Point d'entrée unique des jetons de style
|
||||
utilisés par `frontend/web`, `frontend/crm` et `frontend/cloud`, garantissant une identité visuelle
|
||||
homogène et la thématisation dynamique clair/sombre.
|
||||
|
||||
## Couche de jetons
|
||||
|
||||
Ce paquet expose une chaîne CSS en trois fichiers, du plus primitif au plus dérivé.
|
||||
|
||||
| Fichier | Rôle |
|
||||
|---|---|
|
||||
| `src/styles/tokens.css` | Variables CSS brutes (`--cohaise-*`). Échelle de gris en `oklch`, jetons sémantiques, ombres, typographie, rayons, courbes et durées de mouvement. |
|
||||
| `src/styles/theme.css` | Directive `@theme inline` mappant les variables brutes vers les utilitaires Tailwind (`bg-surface`, `text-muted-foreground`, `border-border`...). |
|
||||
| `src/styles/index.css` | Point d'entrée, importe les deux fichiers ci-dessus. |
|
||||
|
||||
### Mouvement
|
||||
|
||||
Tailwind v4 ne réserve pas de namespace de thème aux durées : `duration-*` est un
|
||||
utilitaire à valeur nue. Les trois durées sont donc exposées via `@utility` dans
|
||||
`theme.css`, adossées aux jetons `--cohaise-duration-*`.
|
||||
|
||||
`--default-transition-duration` et `--default-transition-timing-function` sont
|
||||
également déclarés, si bien que toute classe `transition-*` hérite du mouvement du
|
||||
design system sans avoir à le répéter :
|
||||
|
||||
```css
|
||||
.transition-colors {
|
||||
transition-timing-function: var(--tw-ease, var(--cohaise-ease-out-soft));
|
||||
transition-duration: var(--tw-duration, var(--cohaise-duration-base));
|
||||
}
|
||||
```
|
||||
|
||||
Les utilitaires `duration-fast`, `duration-base`, `duration-slow` et `ease-out-soft`
|
||||
surchargent ces valeurs au cas par cas.
|
||||
|
||||
### Chaîne de résolution
|
||||
|
||||
```mermaid
|
||||
flowchart TD
|
||||
A["tokens.css<br/>--cohaise-gray-*, --cohaise-crimson-*"] --> B["tokens.css<br/>--cohaise-background, --cohaise-border, ..."]
|
||||
B --> C["theme.css<br/>@theme inline"]
|
||||
C --> D["Tailwind CSS<br/>compile les utilitaires"]
|
||||
D --> E["frontend/web · frontend/crm · frontend/cloud"]
|
||||
|
||||
F["Classe .dark sur <html>"] -.->|surcharge les jetons sémantiques| B
|
||||
```
|
||||
|
||||
L'échelle de gris et l'échelle carmin sont les seules sources de vérité des couleurs
|
||||
brutes. Les jetons sémantiques n'y font référence que par `var()`, jamais par une valeur
|
||||
littérale, sauf pour les statuts (`success`, `warning`, `info`) et l'ombre carmin, qui
|
||||
n'existent que dans le mode sombre.
|
||||
|
||||
La source de vérité du rouge est `--clr-accent` du site, soit `#b71c1c`, et non le
|
||||
carmin `#c3073f` qui apparaît davantage dans la feuille de style compilée. Les deux
|
||||
valeurs ont été retenues à un moment de la construction du thème : le carmin est plus
|
||||
vif, la valeur déclarée plus profonde et moins magenta. Sur un outil de gestion de
|
||||
fichiers, c'est la seconde qui tient le mieux sur de grandes surfaces.
|
||||
|
||||
## Couleurs
|
||||
|
||||
Les valeurs viennent de `esiah.dev`. Le fond sombre est un noir à dominante rouge
|
||||
(`#050000`), pas un gris neutre, et l'accent est le carmin `#b71c1c`.
|
||||
|
||||
| Rôle | Clair | Sombre |
|
||||
|---|---|---|
|
||||
| Fond | `#f7f5f4` | `#050000` |
|
||||
| Surface | `#ffffff` | `#1a0505` |
|
||||
| Surface surélevée | `#ffffff` | `#1e1e22` |
|
||||
| Texte | `#1a1a1a` | `#f4f4f2` |
|
||||
| Texte atténué | `#5c5656` | `#a8a0a0` |
|
||||
| Primaire | `#b71c1c` | `#b71c1c` |
|
||||
| Accent graphique | `#b71c1c` | `#c92a2a` |
|
||||
| Filet de séparation | `#e8dcdc` | `#2e1c1c` |
|
||||
|
||||
Un seul rouge de marque dans les deux modes, ce qui rend les captures et les
|
||||
comparaisons d'écran reproductibles. Il n'est appliqué qu'en aplat plein, avec du texte
|
||||
blanc dessus, où il atteint 6,57:1.
|
||||
|
||||
`accent-graphic` est un ton séparé, réservé aux **petits éléments posés sur** une
|
||||
surface : filet de carte, carré de liste, anneau de focus. Ces éléments sont lus comme
|
||||
interface et relèvent du seuil de 3:1, or le rouge de marque ne donne que 2,65:1 sur la
|
||||
surface sombre. Le même raisonnement impose une bordure de champ distincte, à 3,57:1 en
|
||||
sombre et 3,73:1 en clair.
|
||||
|
||||
**Le destructif est ambre, pas rouge.** C'est une décision de lisibilité, pas un goût :
|
||||
l'accent du site est un rouge, donc un bouton « supprimer » rouge serait confondu avec un
|
||||
bouton d'accent. `destructive` occupe donc le ton `oklch(0.768 0.188 70)`, déjà présent
|
||||
dans la palette, et `warning` garde le jaune plus clair. Le prix à payer est que
|
||||
« supprimer » et « attention » sont proches en teinte ; ils ne se croisent jamais dans le
|
||||
même écran, et c'est un choix à revoir si l'interface grossit.
|
||||
|
||||
**Les bordures de champs de formulaire ont leur propre jeton.** Les bordures
|
||||
décoratives restent très discrètes, `1.2:1` sur le fond en mode sombre, pour respecter le
|
||||
grain du site. Un champ de formulaire doit en revanche pouvoir être identifié sans le
|
||||
remplir ni le survoler, ce que la WCAG 1.4.11 chiffre à `3:1`. `border-control` est
|
||||
donc nettement plus clair, `3.5:1` en sombre et `3.7:1` en clair, et c'est lui que
|
||||
`Input` utilise. Les deux valeurs ont été retenues en mesurant le contraste réel plutôt
|
||||
qu'à l'œil.
|
||||
|
||||
## Polices
|
||||
|
||||
| Usage | Police | Variable |
|
||||
|---|---|---|
|
||||
| Titres, libellés, boutons | Orbitron | `--cohaise-font-display` |
|
||||
| Texte courant et paragraphes | Poppins | `--cohaise-font-sans` |
|
||||
| Marque | Orbitron | `--cohaise-font-logo` |
|
||||
| Accroche courte, registre éditorial | Cinzel | `--cohaise-font-serif` |
|
||||
| Code | JetBrains Mono et replis | `--cohaise-font-mono` |
|
||||
|
||||
Le partage vient du site, où `body` est en Orbitron. Orbitron a une chasse très large : à
|
||||
32 px, un titre paraît écrit à la main, et un mot-symbole doit être resserré pour ne pas
|
||||
s'éparpiller. D'où quatre jetons d'interlettrage dédiés, dont un négatif pour les titres.
|
||||
|
||||
Orbitron est donc cantonnée aux **chaînes courtes** — titres jusqu'à `h3`, libellés en
|
||||
capitales, boutons — avec `tracking-label` en positif. Au-delà de `h3`, la chasse est trop
|
||||
large pour la taille du texte. Le flux est en Poppins. C'est pourquoi `font-display` est
|
||||
appliqué dans la couche `base` plutôt que laissé au soin de chaque composant : c'est la
|
||||
seule façon d'éviter qu'un titre revienne en Poppins parce qu'un écran l'a oublié.
|
||||
|
||||
Cinzel est conservée en réserve. C'est un bon caractère, mais une serif d'inscription
|
||||
romaine sur des libellés d'interface ou un paragraphe devient vite illisible, et c'est
|
||||
précisément ce qui donnait au premier jet de ce thème son aspect de thème généré.
|
||||
|
||||
Les trois faces sont **auto-hébergées** dans `frontend/shared/fonts`, 53,6 Ko au total,
|
||||
soit 30 Ko de moins que Roboto seul. Un appel à Google Fonts aurait fait fuiter l'adresse
|
||||
IP de chaque visiteur de ton NAS vers un tiers, ce qui n'a pas sa place dans un écosystème
|
||||
privé.
|
||||
|
||||
## Modes clair et sombre
|
||||
|
||||
Le mode est piloté par la classe `.dark` appliquée sur `<html>`. `:root` porte le mode
|
||||
clair, `.dark` surcharge l'ensemble des jetons sémantiques. `color-scheme` est défini
|
||||
sur les deux blocs pour aligner les contrôles natifs et les barres de défilement.
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
subgraph Light["`:root` — mode clair"]
|
||||
LA["--cohaise-background<br/>#f7f5f4"]
|
||||
LB["--cohaise-foreground<br/>#1a1a1a"]
|
||||
LC["--cohaise-primary<br/>#b71c1c"]
|
||||
end
|
||||
subgraph Dark["`.dark` — mode sombre"]
|
||||
DA["--cohaise-background<br/>#050000"]
|
||||
DB["--cohaise-foreground<br/>#f4f4f2"]
|
||||
DC["--cohaise-primary<br/>#b71c1c"]
|
||||
end
|
||||
Light -->|bascule de classe| Dark
|
||||
```
|
||||
|
||||
Aucune règle `@media (prefers-color-scheme)` n'est déclarée : la bascule est
|
||||
explicite, ce qui garantit un comportement unique quelle que soit la préférence
|
||||
système.
|
||||
|
||||
## Forme
|
||||
|
||||
Les rayons sont quasi nuls, de 2 à 6 px, contre 4 à 12 px pour les valeurs par défaut de
|
||||
Tailwind. Les tuiles à coins arrondis sont la signature la plus immédiate d'une interface
|
||||
sans intention, et un registre d'instrument se lit dans l'angle autant que dans la
|
||||
couleur.
|
||||
|
||||
Trois marques complètent le registre : un filet carmin d'un pixel en tête de `Card`, un
|
||||
carré plein de 6 px devant chaque élément de liste au lieu d'une puce ronde, et des
|
||||
libellés en capitales espacées. Aucune n'est décorative au sens strict : elles servent à
|
||||
séparer des blocs sans ajouter de bordure lourde, et à rendre les métriques denses
|
||||
scannables.
|
||||
|
||||
## Consommation
|
||||
|
||||
```css
|
||||
@import "tailwindcss";
|
||||
@import "@cohaise/ui/styles";
|
||||
```
|
||||
|
||||
L'application conserve la main sur la directive `tailwindcss` et sur sa configuration ;
|
||||
ce paquet ne fournit que les jetons. Le build Vite résout l'entrée via le champ
|
||||
`exports` du `package.json`.
|
||||
|
||||
## Contraintes
|
||||
|
||||
- Aucune valeur de couleur littérale n'est autorisée dans les composants : uniquement
|
||||
des utilitaires derivés des jetons sémantiques, sinon la thématisation casse.
|
||||
- `@theme inline` est obligatoire plutôt que `@theme`, car les utilitaires doivent
|
||||
référencer la variable pour résoudre la valeur au changement de mode.
|
||||
- Aucune durée ne doit être écrite en dur dans un composant (`duration-150` est
|
||||
interdit) : passer par `duration-fast`, `duration-base` ou `duration-slow`.
|
||||
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"name": "@cohaise/ui",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"sideEffects": ["**/*.css"],
|
||||
"style": "./src/styles/index.css",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"default": "./dist/index.js"
|
||||
},
|
||||
"./styles": "./src/styles/index.css",
|
||||
"./styles/tokens": "./src/styles/tokens.css",
|
||||
"./styles/theme": "./src/styles/theme.css"
|
||||
},
|
||||
"files": ["dist", "src/styles"],
|
||||
"scripts": {
|
||||
"build": "tsc --build",
|
||||
"clean": "node --eval \"import('node:fs').then(fs => { fs.rmSync('dist', { recursive: true, force: true }); fs.rmSync('tsconfig.tsbuildinfo', { force: true }); })\"",
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^19.0.0",
|
||||
"react-dom": "^19.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^19.3.0",
|
||||
"@types/react-dom": "^19.3.0",
|
||||
"react": "^19.3.0",
|
||||
"react-dom": "^19.3.0",
|
||||
"typescript": "^7.0.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"clsx": "^2.1.1",
|
||||
"tailwind-merge": "^3.7.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import type { ButtonHTMLAttributes, ReactNode } from "react";
|
||||
import { cn } from "../lib/cn.js";
|
||||
import { Spinner } from "./Spinner.js";
|
||||
import type { SpinnerSize } from "./Spinner.js";
|
||||
|
||||
const variantClasses = {
|
||||
primary: "bg-primary text-primary-foreground hover:bg-primary-hover",
|
||||
secondary: "border border-border-strong bg-surface text-foreground hover:bg-surface-hover",
|
||||
ghost: "text-foreground hover:bg-surface-hover",
|
||||
destructive: "bg-destructive text-destructive-foreground hover:bg-destructive-hover",
|
||||
} as const;
|
||||
|
||||
const sizeClasses = {
|
||||
sm: "h-8 gap-1.5 rounded-sm px-3 text-[0.6875rem]",
|
||||
md: "h-10 gap-2 rounded-md px-4 text-xs",
|
||||
lg: "h-12 gap-2.5 rounded-lg px-6 text-sm",
|
||||
} as const;
|
||||
|
||||
const spinnerBySize: Record<keyof typeof sizeClasses, SpinnerSize> = {
|
||||
sm: "xs",
|
||||
md: "sm",
|
||||
lg: "md",
|
||||
};
|
||||
|
||||
export type ButtonVariant = keyof typeof variantClasses;
|
||||
export type ButtonSize = keyof typeof sizeClasses;
|
||||
|
||||
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
||||
variant?: ButtonVariant;
|
||||
size?: ButtonSize;
|
||||
isLoading?: boolean;
|
||||
showTextWhileLoading?: boolean;
|
||||
iconLeading?: ReactNode;
|
||||
iconTrailing?: ReactNode;
|
||||
fullWidth?: boolean;
|
||||
}
|
||||
|
||||
export const Button = ({
|
||||
variant = "primary",
|
||||
size = "md",
|
||||
isLoading = false,
|
||||
showTextWhileLoading = true,
|
||||
iconLeading,
|
||||
iconTrailing,
|
||||
fullWidth = false,
|
||||
disabled,
|
||||
type = "button",
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: ButtonProps) => (
|
||||
<button
|
||||
type={type}
|
||||
disabled={disabled === true || isLoading}
|
||||
aria-busy={isLoading}
|
||||
className={cn(
|
||||
"inline-flex select-none items-center justify-center whitespace-nowrap font-display font-semibold uppercase tracking-label",
|
||||
"focus-visible:ring-ring focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-offset-background",
|
||||
"transition-[background-color,border-color,color,box-shadow,opacity]",
|
||||
"disabled:pointer-events-none disabled:opacity-50",
|
||||
variantClasses[variant],
|
||||
sizeClasses[size],
|
||||
fullWidth && "w-full",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{isLoading ? <Spinner size={spinnerBySize[size]} /> : iconLeading}
|
||||
{isLoading && !showTextWhileLoading ? null : children}
|
||||
{isLoading ? null : iconTrailing}
|
||||
</button>
|
||||
);
|
||||
@@ -0,0 +1,49 @@
|
||||
import type { HTMLAttributes } from "react";
|
||||
import { cn } from "../lib/cn.js";
|
||||
|
||||
export const Card = ({ className, ...props }: HTMLAttributes<HTMLDivElement>) => (
|
||||
<div
|
||||
className={cn(
|
||||
"relative overflow-hidden rounded-lg border border-border bg-surface text-foreground shadow-sm",
|
||||
"transition-colors duration-base ease-out-soft",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
|
||||
/* Signature du produit : un filet carmin d'un pixel en tete de carte. Invisible sur
|
||||
une grille dense, mais c'est lui qui donne aux cartes leur epaisseur et evite
|
||||
l'aspect de tuiles interchangeables. */
|
||||
export const CardHeader = ({ className, ...props }: HTMLAttributes<HTMLDivElement>) => (
|
||||
<div
|
||||
className={cn(
|
||||
"relative flex flex-col gap-1.5 p-5",
|
||||
"before:absolute before:inset-x-0 before:top-0 before:h-px before:bg-accent-graphic",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
|
||||
export const CardTitle = ({ className, ...props }: HTMLAttributes<HTMLHeadingElement>) => (
|
||||
<h3
|
||||
className={cn(
|
||||
"font-display text-sm font-semibold uppercase leading-tight tracking-label",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
|
||||
export const CardDescription = ({ className, ...props }: HTMLAttributes<HTMLParagraphElement>) => (
|
||||
<p className={cn("text-sm leading-relaxed text-muted-foreground", className)} {...props} />
|
||||
);
|
||||
|
||||
export const CardContent = ({ className, ...props }: HTMLAttributes<HTMLDivElement>) => (
|
||||
<div className={cn("p-5 pt-0", className)} {...props} />
|
||||
);
|
||||
|
||||
export const CardFooter = ({ className, ...props }: HTMLAttributes<HTMLDivElement>) => (
|
||||
<div className={cn("flex items-center gap-2 p-5 pt-0", className)} {...props} />
|
||||
);
|
||||
@@ -0,0 +1,72 @@
|
||||
import { useId } from "react";
|
||||
import type { InputHTMLAttributes, ReactNode } from "react";
|
||||
import { cn } from "../lib/cn.js";
|
||||
|
||||
export interface InputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "size"> {
|
||||
label?: ReactNode;
|
||||
hint?: ReactNode;
|
||||
error?: ReactNode;
|
||||
sizeVariant?: "sm" | "md" | "lg";
|
||||
}
|
||||
|
||||
const inputSize = {
|
||||
sm: "h-8 px-2.5 text-xs",
|
||||
md: "h-10 px-3 text-sm",
|
||||
lg: "h-12 px-4 text-base",
|
||||
} as const;
|
||||
|
||||
export const Input = ({
|
||||
label,
|
||||
hint,
|
||||
error,
|
||||
sizeVariant = "md",
|
||||
id,
|
||||
className,
|
||||
disabled,
|
||||
...props
|
||||
}: InputProps) => {
|
||||
const generatedId = useId();
|
||||
const inputId = id ?? generatedId;
|
||||
const messageId = `${inputId}-message`;
|
||||
const isInvalid = error !== undefined && error !== null && error !== "";
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-1.5">
|
||||
{label ? (
|
||||
<label
|
||||
htmlFor={inputId}
|
||||
className="font-display text-[0.6875rem] font-semibold uppercase tracking-label text-foreground"
|
||||
>
|
||||
{label}
|
||||
</label>
|
||||
) : null}
|
||||
|
||||
<input
|
||||
id={inputId}
|
||||
disabled={disabled}
|
||||
aria-invalid={isInvalid}
|
||||
aria-describedby={isInvalid || hint ? messageId : undefined}
|
||||
className={cn(
|
||||
"w-full rounded-sm border bg-surface text-foreground placeholder:text-subtle-foreground",
|
||||
"transition-[background-color,border-color,box-shadow] duration-fast ease-out-soft",
|
||||
"focus-visible:ring-ring focus-visible:border-border-strong focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-offset-background focus-visible:outline-none",
|
||||
"disabled:cursor-not-allowed disabled:bg-surface-muted disabled:opacity-60",
|
||||
isInvalid ? "border-destructive focus-visible:ring-destructive" : "border-border-control",
|
||||
inputSize[sizeVariant],
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
|
||||
{isInvalid || hint ? (
|
||||
<p
|
||||
id={messageId}
|
||||
role={isInvalid ? "alert" : undefined}
|
||||
className={cn("text-xs leading-relaxed", isInvalid ? "text-destructive" : "text-muted-foreground")}
|
||||
>
|
||||
{isInvalid ? error : hint}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
import type { HTMLAttributes } from "react";
|
||||
import { cn } from "../lib/cn.js";
|
||||
|
||||
export type SkeletonProps = HTMLAttributes<HTMLDivElement> & {
|
||||
width?: string;
|
||||
height?: string;
|
||||
radius?: "sm" | "md" | "lg" | "xl" | "full";
|
||||
};
|
||||
|
||||
const skeletonRadius = {
|
||||
sm: "rounded-sm",
|
||||
md: "rounded-md",
|
||||
lg: "rounded-lg",
|
||||
xl: "rounded-xl",
|
||||
full: "rounded-full",
|
||||
} as const;
|
||||
|
||||
export const Skeleton = ({
|
||||
width,
|
||||
height,
|
||||
radius = "md",
|
||||
className,
|
||||
style,
|
||||
...props
|
||||
}: SkeletonProps) => (
|
||||
<div
|
||||
aria-hidden="true"
|
||||
style={{ width, height, ...style }}
|
||||
className={cn("animate-pulse bg-skeleton-base motion-reduce:animate-none", skeletonRadius[radius], className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
@@ -0,0 +1,36 @@
|
||||
import type { SVGProps } from "react";
|
||||
import { cn } from "../lib/cn.js";
|
||||
|
||||
const spinnerSize = {
|
||||
xs: "size-3",
|
||||
sm: "size-3.5",
|
||||
md: "size-4",
|
||||
lg: "size-4.5",
|
||||
} as const;
|
||||
|
||||
export type SpinnerSize = keyof typeof spinnerSize;
|
||||
|
||||
export interface SpinnerProps extends Omit<SVGProps<SVGSVGElement>, "children"> {
|
||||
size?: SpinnerSize;
|
||||
label?: string;
|
||||
}
|
||||
|
||||
export const Spinner = ({ size = "md", label, className, ...props }: SpinnerProps) => (
|
||||
<svg
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
role={label ? "status" : undefined}
|
||||
aria-label={label}
|
||||
aria-hidden={label ? undefined : true}
|
||||
className={cn("shrink-0 animate-spin motion-reduce:animate-none", spinnerSize[size], className)}
|
||||
{...props}
|
||||
>
|
||||
<circle cx="12" cy="12" r="9" stroke="currentColor" strokeWidth="2.5" opacity="0.25" />
|
||||
<path
|
||||
d="M21 12a9 9 0 0 0-9-9"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2.5"
|
||||
strokeLinecap="round"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
@@ -0,0 +1,10 @@
|
||||
export { cn } from "./lib/cn.js";
|
||||
export type { SpinnerProps, SpinnerSize } from "./components/Spinner.js";
|
||||
export { Spinner } from "./components/Spinner.js";
|
||||
export type { ButtonProps, ButtonSize, ButtonVariant } from "./components/Button.js";
|
||||
export { Button } from "./components/Button.js";
|
||||
export type { SkeletonProps } from "./components/Skeleton.js";
|
||||
export { Skeleton } from "./components/Skeleton.js";
|
||||
export { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "./components/Card.js";
|
||||
export type { InputProps } from "./components/Input.js";
|
||||
export { Input } from "./components/Input.js";
|
||||
@@ -0,0 +1,5 @@
|
||||
import { clsx } from "clsx";
|
||||
import type { ClassValue } from "clsx";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
export const cn = (...inputs: ClassValue[]): string => twMerge(clsx(inputs));
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
Poppins n'existe qu'en graisses statiques chez Google Fonts, deux fichiers sont donc
|
||||
necessaires. Elle couvre 300 Ko de plus que Cinzel et Orbitron reunis, d'ou l'arbitrage
|
||||
suivant : Poppins porte le texte courant, Cinzel et Orbitron restent deux faces de
|
||||
caractere Reserves aux chaines courtes.
|
||||
*/
|
||||
|
||||
@font-face {
|
||||
font-family: "Poppins";
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
font-display: swap;
|
||||
src: url("../../fonts/poppins-400.woff2") format("woff2");
|
||||
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
|
||||
U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
|
||||
U+2212, U+2215, U+FEFF, U+FFFD;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "Poppins";
|
||||
font-style: normal;
|
||||
font-weight: 600;
|
||||
font-display: swap;
|
||||
src: url("../../fonts/poppins-600.woff2") format("woff2");
|
||||
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
|
||||
U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
|
||||
U+2212, U+2215, U+FEFF, U+FFFD;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "JetBrains Mono";
|
||||
font-style: normal;
|
||||
font-weight: 400 700;
|
||||
font-display: swap;
|
||||
src: url("../../fonts/jetbrains-mono-latin.woff2") format("woff2");
|
||||
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
|
||||
U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
|
||||
U+2212, U+2215, U+FEFF, U+FFFD;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "Orbitron";
|
||||
font-style: normal;
|
||||
font-weight: 400 900;
|
||||
font-display: swap;
|
||||
src: url("../../fonts/orbitron-latin.woff2") format("woff2");
|
||||
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
|
||||
U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
|
||||
U+2212, U+2215, U+FEFF, U+FFFD;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "Cinzel";
|
||||
font-style: normal;
|
||||
font-weight: 400 900;
|
||||
font-display: swap;
|
||||
src: url("../../fonts/cinzel-latin.woff2") format("woff2");
|
||||
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
|
||||
U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
|
||||
U+2212, U+2215, U+FEFF, U+FFFD;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
@import "./fonts.css";
|
||||
@import "./tokens.css";
|
||||
@import "./theme.css";
|
||||
@@ -0,0 +1,105 @@
|
||||
@theme inline {
|
||||
--color-background: var(--cohaise-background);
|
||||
--color-foreground: var(--cohaise-foreground);
|
||||
|
||||
--color-surface: var(--cohaise-surface);
|
||||
--color-surface-raised: var(--cohaise-surface-raised);
|
||||
--color-surface-sunken: var(--cohaise-surface-sunken);
|
||||
--color-surface-muted: var(--cohaise-surface-muted);
|
||||
--color-surface-hover: var(--cohaise-surface-hover);
|
||||
--color-surface-overlay: var(--cohaise-surface-overlay);
|
||||
|
||||
--color-muted-foreground: var(--cohaise-muted-foreground);
|
||||
--color-subtle-foreground: var(--cohaise-subtle-foreground);
|
||||
|
||||
--color-border: var(--cohaise-border);
|
||||
--color-border-strong: var(--cohaise-border-strong);
|
||||
--color-border-control: var(--cohaise-border-control);
|
||||
|
||||
--color-primary: var(--cohaise-primary);
|
||||
--color-primary-foreground: var(--cohaise-primary-foreground);
|
||||
--color-primary-hover: var(--cohaise-primary-hover);
|
||||
|
||||
--color-accent: var(--cohaise-accent);
|
||||
--color-accent-foreground: var(--cohaise-accent-foreground);
|
||||
--color-accent-hover: var(--cohaise-accent-hover);
|
||||
--color-accent-graphic: var(--cohaise-accent-graphic);
|
||||
|
||||
--color-ring: var(--cohaise-ring);
|
||||
|
||||
--color-destructive: var(--cohaise-destructive);
|
||||
--color-destructive-foreground: var(--cohaise-destructive-foreground);
|
||||
--color-destructive-hover: var(--cohaise-destructive-hover);
|
||||
|
||||
--color-success: var(--cohaise-success);
|
||||
--color-success-foreground: var(--cohaise-success-foreground);
|
||||
--color-warning: var(--cohaise-warning);
|
||||
--color-warning-foreground: var(--cohaise-warning-foreground);
|
||||
--color-info: var(--cohaise-info);
|
||||
--color-info-foreground: var(--cohaise-info-foreground);
|
||||
|
||||
--color-skeleton-base: var(--cohaise-skeleton-base);
|
||||
--color-skeleton-highlight: var(--cohaise-skeleton-highlight);
|
||||
|
||||
--shadow-sm: var(--cohaise-shadow-sm);
|
||||
--shadow-md: var(--cohaise-shadow-md);
|
||||
--shadow-lg: var(--cohaise-shadow-lg);
|
||||
--shadow-crimson: var(--cohaise-shadow-crimson, 0 0 0 0 transparent);
|
||||
|
||||
--font-display: var(--cohaise-font-display);
|
||||
--font-logo: var(--cohaise-font-logo);
|
||||
--font-sans: var(--cohaise-font-sans);
|
||||
--font-serif: var(--cohaise-font-serif);
|
||||
--font-mono: var(--cohaise-font-mono);
|
||||
|
||||
--tracking-display: var(--cohaise-tracking-display);
|
||||
--tracking-logo: var(--cohaise-tracking-logo);
|
||||
--tracking-label: var(--cohaise-tracking-label);
|
||||
--tracking-body: var(--cohaise-tracking-body);
|
||||
|
||||
--radius-sm: var(--cohaise-radius-sm);
|
||||
--radius-md: var(--cohaise-radius-md);
|
||||
--radius-lg: var(--cohaise-radius-lg);
|
||||
--radius-xl: var(--cohaise-radius-xl);
|
||||
--radius-full: var(--cohaise-radius-full);
|
||||
|
||||
--ease-out-soft: var(--cohaise-ease-out-soft);
|
||||
--ease-in-out-soft: var(--cohaise-ease-in-out-soft);
|
||||
|
||||
--default-transition-duration: var(--cohaise-duration-base);
|
||||
--default-transition-timing-function: var(--cohaise-ease-out-soft);
|
||||
}
|
||||
|
||||
@layer base {
|
||||
html,
|
||||
body {
|
||||
background-color: var(--cohaise-background);
|
||||
}
|
||||
|
||||
body {
|
||||
color: var(--cohaise-foreground);
|
||||
font-family: var(--cohaise-font-sans);
|
||||
letter-spacing: var(--cohaise-tracking-body);
|
||||
}
|
||||
|
||||
/* Orbitron sur les titres seulement, jusqu'a h3. Au-dela la chasse est trop large
|
||||
pour la taille du texte et le titre devient illisible. */
|
||||
h1,
|
||||
h2,
|
||||
h3 {
|
||||
font-family: var(--cohaise-font-display);
|
||||
letter-spacing: var(--cohaise-tracking-display);
|
||||
}
|
||||
}
|
||||
|
||||
@utility duration-fast {
|
||||
transition-duration: var(--cohaise-duration-fast);
|
||||
}
|
||||
|
||||
@utility duration-base {
|
||||
transition-duration: var(--cohaise-duration-base);
|
||||
}
|
||||
|
||||
@utility duration-slow {
|
||||
transition-duration: var(--cohaise-duration-slow);
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
:root {
|
||||
color-scheme: light;
|
||||
|
||||
--cohaise-gray-50: #f7f5f4;
|
||||
--cohaise-gray-100: #f0eeee;
|
||||
--cohaise-gray-200: #e4e0e0;
|
||||
--cohaise-gray-300: #d6d1d1;
|
||||
--cohaise-gray-400: #a8a0a0;
|
||||
--cohaise-gray-500: #7a7373;
|
||||
--cohaise-gray-600: #5c5656;
|
||||
--cohaise-gray-700: #423d3d;
|
||||
--cohaise-gray-800: #2a2626;
|
||||
--cohaise-gray-900: #1a1616;
|
||||
--cohaise-gray-950: #0d0909;
|
||||
|
||||
/* Echelle organisee autour de #b71c1c, la valeur reelle de --clr-accent du site.
|
||||
Les tons plus sombres servent au survol en mode clair, les plus clairs au
|
||||
survol et au focus en mode sombre. */
|
||||
--cohaise-crimson-950: #3d070e;
|
||||
--cohaise-crimson-900: #5e0a14;
|
||||
--cohaise-crimson-800: #8f1116;
|
||||
--cohaise-crimson-700: #b71c1c;
|
||||
--cohaise-crimson-600: #c92a2a;
|
||||
--cohaise-crimson-500: #d32f2f;
|
||||
|
||||
--cohaise-yellow-500: oklch(0.828 0.189 84);
|
||||
|
||||
--cohaise-background: var(--cohaise-gray-50);
|
||||
--cohaise-foreground: #1a1a1a;
|
||||
|
||||
--cohaise-surface: #ffffff;
|
||||
--cohaise-surface-raised: #ffffff;
|
||||
--cohaise-surface-sunken: #f0eeee;
|
||||
--cohaise-surface-muted: #f4f2f2;
|
||||
--cohaise-surface-hover: #ece8e8;
|
||||
--cohaise-surface-overlay: #ffffff;
|
||||
|
||||
--cohaise-muted-foreground: #5c5656;
|
||||
--cohaise-subtle-foreground: #7a7373;
|
||||
|
||||
/* Les separateurs sont des filets carmin tres desatures, pas du gris. C'est ce
|
||||
qui donne au produit son teinte plutot que celle d'une carte bancaire. */
|
||||
--cohaise-border: #e8dcdc;
|
||||
--cohaise-border-strong: #d4bfbf;
|
||||
--cohaise-border-control: #8f8181;
|
||||
|
||||
--cohaise-primary: var(--cohaise-crimson-700);
|
||||
--cohaise-primary-foreground: #ffffff;
|
||||
--cohaise-primary-hover: var(--cohaise-crimson-800);
|
||||
|
||||
--cohaise-accent: var(--cohaise-crimson-700);
|
||||
--cohaise-accent-foreground: #ffffff;
|
||||
--cohaise-accent-hover: var(--cohaise-crimson-800);
|
||||
|
||||
/* Ton dedie aux petits elements qui sont poses SUR une surface, donc lus
|
||||
comme element d'interface et non comme aplat de marque : filet de carte,
|
||||
carre de liste, anneau de focus. Le rouge de marque n'y atteint que
|
||||
2.65:1 sur la surface sombre. */
|
||||
--cohaise-accent-graphic: var(--cohaise-crimson-700);
|
||||
|
||||
--cohaise-ring: var(--cohaise-crimson-700);
|
||||
|
||||
--cohaise-destructive: #d32f2f;
|
||||
--cohaise-destructive-foreground: #ffffff;
|
||||
--cohaise-destructive-hover: #a31818;
|
||||
|
||||
--cohaise-success: oklch(0.52 0.128 155);
|
||||
--cohaise-success-foreground: #ffffff;
|
||||
|
||||
--cohaise-warning: var(--cohaise-yellow-500);
|
||||
--cohaise-warning-foreground: #1a0505;
|
||||
|
||||
--cohaise-info: #0f6d78;
|
||||
--cohaise-info-foreground: #ffffff;
|
||||
|
||||
--cohaise-skeleton-base: #e4e0e0;
|
||||
--cohaise-skeleton-highlight: #f7f5f4;
|
||||
|
||||
--cohaise-shadow-sm: 0 1px 2px 0 oklch(0.1 0.02 20 / 0.06);
|
||||
--cohaise-shadow-md: 0 4px 12px -2px oklch(0.1 0.02 20 / 0.1);
|
||||
--cohaise-shadow-lg: 0 12px 32px -8px oklch(0.1 0.02 20 / 0.16);
|
||||
|
||||
/* Orbitron porte les chaines courtes, la marque et les titres. Poppins porte le
|
||||
texte courant : Orbitron est trop large pour etre lu en flux. Cinzel reste
|
||||
disponible pour une accroche courte ou Editorial, jamais pour un paragraphe. */
|
||||
--cohaise-font-display: "Orbitron", "Cinzel", sans-serif;
|
||||
--cohaise-font-logo: "Orbitron", "Cinzel", sans-serif;
|
||||
--cohaise-font-sans: "Poppins", ui-sans-serif, system-ui, -apple-system, "Segoe UI",
|
||||
sans-serif;
|
||||
--cohaise-font-serif: "Cinzel", "Times New Roman", serif;
|
||||
/* Auto-hebergee comme les trois autres. En repli systeme, la meme taille de
|
||||
chiffres se rendait differemment sur le P330, le portable et le telephone. */
|
||||
--cohaise-font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", "Menlo",
|
||||
"Consolas", monospace;
|
||||
|
||||
/* Orbitron a des chassees tres larges : sans correction, un titre de 32 px
|
||||
parait avoir ete espace a la main et un mot-symlose des caracteres. */
|
||||
--cohaise-tracking-display: -0.015em;
|
||||
--cohaise-tracking-logo: 0.16em;
|
||||
--cohaise-tracking-label: 0.09em;
|
||||
--cohaise-tracking-body: 0;
|
||||
|
||||
/* Deux echelles et non une seule. Un conteneur qui enveloppe du contenu
|
||||
merite d'etre plus doux qu'un bouton qu'on presse : c'est ce decalage qui
|
||||
donne la hierarchie, la ou un rayon unique uniforme rend tout interchangeable. */
|
||||
--cohaise-radius-sm: 0.375rem;
|
||||
--cohaise-radius-md: 0.5rem;
|
||||
--cohaise-radius-lg: 0.75rem;
|
||||
--cohaise-radius-xl: 1rem;
|
||||
--cohaise-radius-full: 9999px;
|
||||
|
||||
--cohaise-ease-out-soft: cubic-bezier(0.22, 1, 0.36, 1);
|
||||
--cohaise-ease-in-out-soft: cubic-bezier(0.65, 0, 0.35, 1);
|
||||
--cohaise-duration-fast: 150ms;
|
||||
--cohaise-duration-base: 250ms;
|
||||
--cohaise-duration-slow: 400ms;
|
||||
}
|
||||
|
||||
.dark {
|
||||
color-scheme: dark;
|
||||
|
||||
--cohaise-background: #050000;
|
||||
--cohaise-foreground: #f4f4f2;
|
||||
|
||||
/* Surfaces neutres comme sur le site, le fond porte seul la dominante rouge. */
|
||||
--cohaise-surface: #1a1a1a;
|
||||
--cohaise-surface-raised: #242424;
|
||||
--cohaise-surface-sunken: #0a0a0a;
|
||||
--cohaise-surface-muted: #1f1f1f;
|
||||
--cohaise-surface-hover: #2a2a2a;
|
||||
--cohaise-surface-overlay: #242424;
|
||||
|
||||
--cohaise-muted-foreground: #a8a0a0;
|
||||
--cohaise-subtle-foreground: #7a7373;
|
||||
|
||||
--cohaise-border: #2e1c1c;
|
||||
--cohaise-border-strong: #46262a;
|
||||
--cohaise-border-control: #a85a62;
|
||||
|
||||
/* #b71c1c reste lisible dans les deux modes : texte blanc a 6.57:1, et
|
||||
3.18:1 sur le fond, au-dessus du seuil de 3:1 pour un element d'interface. */
|
||||
--cohaise-primary: var(--cohaise-crimson-700);
|
||||
--cohaise-primary-foreground: #ffffff;
|
||||
--cohaise-primary-hover: var(--cohaise-crimson-600);
|
||||
|
||||
--cohaise-accent: var(--cohaise-crimson-700);
|
||||
--cohaise-accent-foreground: #ffffff;
|
||||
--cohaise-accent-hover: var(--cohaise-crimson-600);
|
||||
|
||||
--cohaise-accent-graphic: var(--cohaise-crimson-600);
|
||||
|
||||
--cohaise-ring: var(--cohaise-crimson-600);
|
||||
|
||||
--cohaise-destructive: #ef4444;
|
||||
--cohaise-destructive-foreground: #1a0505;
|
||||
--cohaise-destructive-hover: #f87171;
|
||||
|
||||
--cohaise-success: oklch(0.792 0.152 155);
|
||||
--cohaise-success-foreground: #050000;
|
||||
|
||||
--cohaise-warning: var(--cohaise-yellow-500);
|
||||
--cohaise-warning-foreground: #1a0505;
|
||||
|
||||
--cohaise-info: oklch(0.752 0.112 194);
|
||||
--cohaise-info-foreground: #050000;
|
||||
|
||||
--cohaise-skeleton-base: #2a1a1a;
|
||||
--cohaise-skeleton-highlight: #3a2222;
|
||||
|
||||
--cohaise-shadow-sm: 0 1px 2px 0 oklch(0 0 0 / 0.4);
|
||||
--cohaise-shadow-md: 0 4px 12px -2px oklch(0 0 0 / 0.5);
|
||||
--cohaise-shadow-lg: 0 12px 32px -8px oklch(0 0 0 / 0.6);
|
||||
|
||||
--cohaise-shadow-crimson: 0 0 0 1px oklch(0.55 0.22 15 / 0.28),
|
||||
0 8px 30px -12px oklch(0.55 0.22 15 / 0.55);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
||||
"jsx": "react-jsx",
|
||||
"rootDir": "src",
|
||||
"outDir": "dist",
|
||||
"composite": true,
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"sourceMap": true
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.tsx"]
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
# @cohaise/web
|
||||
|
||||
Vitrine institutionnelle de `cohaise.dev`. Première application du monorepo CoHaiSe et premier consommateur réel du design system partagé.
|
||||
|
||||
## Rôle
|
||||
|
||||
| Responsabilité | Localisation |
|
||||
| -------------------------------------------- | ----------------- |
|
||||
| Design system, jetons, composants | `frontend/shared` |
|
||||
| vitrine institutionnelle | `frontend/web` |
|
||||
| Point d'entrée local, publication des builds | `docker/nginx` |
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
subgraph navigateur
|
||||
app["frontend/web<br/>React + Vite"]
|
||||
end
|
||||
subgraph monorepo
|
||||
ui["frontend/shared<br/>@cohaise/ui"]
|
||||
end
|
||||
subgraph infrastructure
|
||||
web["nginx<br/>cohaise.dev"]
|
||||
end
|
||||
app -->|import| ui
|
||||
app -->|build statique| web
|
||||
```
|
||||
|
||||
## Prérequis
|
||||
|
||||
- Node.js `>=22.23.1`
|
||||
- npm `>=10`
|
||||
|
||||
## Commandes
|
||||
|
||||
| Commande | Effet |
|
||||
| ----------------------------------- | ----------------------------------------------------------- |
|
||||
| `npm run dev -w @cohaise/web` | serveur Vite sur `http://localhost:5173` |
|
||||
| `npm run build -w @cohaise/web` | vérification de types puis build de production dans `dist/` |
|
||||
| `npm run preview -w @cohaise/web` | sert le build de production localement |
|
||||
| `npm run typecheck -w @cohaise/web` | vérification de types seule |
|
||||
| `make web` | construit l'image et republie le build dans le volume Nginx |
|
||||
|
||||
## Publication dans l'infrastructure
|
||||
|
||||
Le `Dockerfile` est un build multi-étapes. Le contexte de construction est la racine du
|
||||
monorepo, car le build a besoin des workspaces, du lockfile et des références
|
||||
TypeScript partagées.
|
||||
|
||||
```text
|
||||
node:22-alpine deps installation déterministe via npm ci
|
||||
node:22-alpine builder tsc --build puis vite build
|
||||
alpine:3.21 export /app/dist, copié dans le volume web_data
|
||||
```
|
||||
|
||||
Le service `cohaise-web-build` copie le résultat dans le volume `web_data`, que Nginx
|
||||
monte déjà sur `/usr/share/nginx/html/web`. Aucune modification de la configuration
|
||||
Nginx n'est nécessaire, et la publication reste découplée des autres applications.
|
||||
|
||||
## Consommation du design system
|
||||
|
||||
L'application importe la feuille de style publique du package partagé une seule fois, dans `src/styles/index.css` :
|
||||
|
||||
```css
|
||||
@import "tailwindcss";
|
||||
@import "@cohaise/ui/styles";
|
||||
|
||||
@source "../../../../frontend/shared/src";
|
||||
```
|
||||
|
||||
La directive `@source` est indispensable. Sans elle, Tailwind ignore `node_modules` et les classes utilisées par les composants de `frontend/shared` ne sont jamais générées : les composants s'afficheraient sans style.
|
||||
|
||||
## Thème
|
||||
|
||||
Le thème est appliqué par la classe `dark` sur `<html>`. Le script inline de `index.html` applique la préférence enregistrée ou celle du système avant le premier rendu, ce qui évite le flash de thème clair. `src/hooks/useTheme.ts` pilote le changement et persiste le choix dans `localStorage` sous la clé `cohaise-theme`.
|
||||
|
||||
## Structure
|
||||
|
||||
```text
|
||||
frontend/web
|
||||
├── index.html amorce de thème et point de montage
|
||||
├── public/favicon.webp
|
||||
├── src
|
||||
│ ├── App.tsx composition de la page
|
||||
│ ├── main.tsx point d'entrée React
|
||||
│ ├── components
|
||||
│ │ ├── DemoCard.tsx états repos, chargement, chargé
|
||||
│ │ └── ThemeToggle.tsx
|
||||
│ ├── hooks
|
||||
│ │ └── useTheme.ts
|
||||
│ └── styles/index.css import du design system
|
||||
├── tsconfig.json
|
||||
├── tsconfig.node.json
|
||||
└── vite.config.ts
|
||||
```
|
||||
|
||||
## Limites actuelles
|
||||
|
||||
- Aucun appel réseau : toutes les données de démonstration sont locales.
|
||||
- Aucun routage : la page est un point d'entrée unique.
|
||||
- Les URL d'API devront passer par un wrapper dédié, jamais codées en dur dans les composants.
|
||||
|
||||
## Variables d'environnement
|
||||
|
||||
L'application ne déclare aucune variable pour l'instant. Le gabarit `frontend/web/.env.example`
|
||||
prendra une entrée `VITE_API_BASE_URL` au moment où le premier appel réseau existera, afin
|
||||
que l'URL reste définie à un seul endroit. Seules les variables préfixées par `VITE_` sont
|
||||
exposées au bundle ; aucun secret ne doit jamais être lu par le navigateur.
|
||||
@@ -0,0 +1,30 @@
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="color-scheme" content="light dark" />
|
||||
<meta
|
||||
name="description"
|
||||
content="CoHaiSe conçoit des sites vitrines, applications mobiles et logiciels sur mesure : modernes, rapides et agréables à utiliser."
|
||||
/>
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.webp" />
|
||||
<title>
|
||||
CoHaiSe — Développement web, applications et design sur mesure
|
||||
</title>
|
||||
<script>
|
||||
(() => {
|
||||
const stored = localStorage.getItem("cohaise-theme");
|
||||
const prefersDark = window.matchMedia(
|
||||
"(prefers-color-scheme: dark)",
|
||||
).matches;
|
||||
const theme = stored ?? (prefersDark ? "dark" : "light");
|
||||
if (theme === "dark") document.documentElement.classList.add("dark");
|
||||
})();
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "@cohaise/web",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc --noEmit && vite build",
|
||||
"preview": "vite preview",
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"@cohaise/ui": "*",
|
||||
"gsap": "^3.15.1",
|
||||
"react": "^19.3.0",
|
||||
"react-dom": "^19.3.0",
|
||||
"react-icons": "^5.7.0",
|
||||
"three": "^0.187.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/vite": "^4.3.3",
|
||||
"@types/react": "^19.3.0",
|
||||
"@types/react-dom": "^19.3.0",
|
||||
"@types/three": "^0.187.0",
|
||||
"@vitejs/plugin-react": "^6.1.1",
|
||||
"tailwindcss": "^4.3.3",
|
||||
"typescript": "^7.0.2",
|
||||
"vite": "^8.3.1"
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 184 KiB |
|
After Width: | Height: | Size: 162 KiB |
|
After Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 125 KiB |
@@ -0,0 +1,50 @@
|
||||
import { lazy, Suspense } from "react";
|
||||
import { LanguageProvider } from "./lib/i18n.js";
|
||||
import { useScrollReveal } from "./hooks/useScrollReveal.js";
|
||||
import { Header } from "./components/Header.js";
|
||||
import { Hero } from "./components/Hero.js";
|
||||
import { Services } from "./components/Services.js";
|
||||
import { Demos } from "./components/Demos.js";
|
||||
import { Stack } from "./components/Stack.js";
|
||||
import { About } from "./components/About.js";
|
||||
import { Contact } from "./components/Contact.js";
|
||||
import { Footer } from "./components/Footer.js";
|
||||
import { BackToTop } from "./components/BackToTop.js";
|
||||
import { services } from "./data/services.js";
|
||||
import { demos } from "./data/demos.js";
|
||||
import { stack } from "./data/stack.js";
|
||||
|
||||
// Le fond WebGL (topographie) est lourd : chargé à la demande. Il vit en
|
||||
// `position: fixed` (z-0) : le défilement n'a aucune incidence sur lui, seul
|
||||
// le contenu (z-10) défile au-dessus.
|
||||
const Topography = lazy(() => import("./components/background/Topography.js"));
|
||||
|
||||
export const App = () => {
|
||||
useScrollReveal();
|
||||
|
||||
return (
|
||||
<LanguageProvider>
|
||||
<div id="top" className="relative flex min-h-screen flex-col bg-background text-foreground">
|
||||
<div className="pointer-events-none fixed inset-0 z-0" aria-hidden="true">
|
||||
<Suspense fallback={null}>
|
||||
<Topography color="#ff5252" opacity={0.5} speed={0.22} clickEffect="none" />
|
||||
</Suspense>
|
||||
</div>
|
||||
|
||||
<div className="relative z-10 flex flex-1 flex-col">
|
||||
<Header />
|
||||
<main className="flex flex-1 flex-col">
|
||||
<Hero />
|
||||
<Services services={services} />
|
||||
<Demos demos={demos} />
|
||||
<Stack items={stack} />
|
||||
<About />
|
||||
<Contact />
|
||||
</main>
|
||||
<Footer />
|
||||
<BackToTop />
|
||||
</div>
|
||||
</div>
|
||||
</LanguageProvider>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,18 @@
|
||||
import { useLanguage } from "../lib/i18n.js";
|
||||
import { Section, SectionHeading } from "./Section.js";
|
||||
|
||||
export const About = () => {
|
||||
const { t } = useLanguage();
|
||||
|
||||
return (
|
||||
<Section id="about">
|
||||
<SectionHeading title={t("about.title")} />
|
||||
<p
|
||||
data-reveal
|
||||
className="max-w-2xl text-base leading-relaxed text-muted-foreground sm:text-lg"
|
||||
>
|
||||
{t("about.body")}
|
||||
</p>
|
||||
</Section>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { cn } from "@cohaise/ui";
|
||||
import { scrollToSection } from "../lib/gsap.js";
|
||||
|
||||
export const BackToTop = () => {
|
||||
const [visible, setVisible] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const onScroll = () => setVisible(window.scrollY > 400);
|
||||
onScroll();
|
||||
window.addEventListener("scroll", onScroll, { passive: true });
|
||||
return () => window.removeEventListener("scroll", onScroll);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => scrollToSection("#top")}
|
||||
aria-label="Retour en haut"
|
||||
title="Retour en haut"
|
||||
className={cn(
|
||||
"glass fixed bottom-6 right-6 z-50 flex size-11 items-center justify-center rounded-full border border-border/60 text-foreground shadow-md transition-all duration-base hover:border-border-strong",
|
||||
visible ? "translate-y-0 opacity-100" : "pointer-events-none translate-y-3 opacity-0",
|
||||
)}
|
||||
>
|
||||
<svg
|
||||
width="18"
|
||||
height="18"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path d="M12 19V5M5 12l7-7 7 7" />
|
||||
</svg>
|
||||
</button>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,123 @@
|
||||
import { useState, type FormEvent } from "react";
|
||||
import { Input } from "@cohaise/ui";
|
||||
import { useLanguage } from "../lib/i18n.js";
|
||||
import { LEADS_ENDPOINT } from "../lib/api.js";
|
||||
import { Section, SectionHeading } from "./Section.js";
|
||||
|
||||
type Status = "idle" | "sending" | "success" | "error";
|
||||
|
||||
const text = (value: FormDataEntryValue | null): string => String(value ?? "").trim();
|
||||
|
||||
export const Contact = () => {
|
||||
const { t } = useLanguage();
|
||||
const [status, setStatus] = useState<Status>("idle");
|
||||
|
||||
const handleSubmit = async (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
const form = event.currentTarget;
|
||||
const data = new FormData(form);
|
||||
|
||||
const payload = {
|
||||
firstName: text(data.get("firstName")),
|
||||
lastName: text(data.get("lastName")),
|
||||
email: text(data.get("email")),
|
||||
organization: text(data.get("organization")) || null,
|
||||
phone: text(data.get("phone")) || null,
|
||||
message: text(data.get("message")),
|
||||
website: text(data.get("website")),
|
||||
};
|
||||
|
||||
if (!payload.firstName || !payload.lastName || !payload.email) {
|
||||
setStatus("error");
|
||||
return;
|
||||
}
|
||||
|
||||
setStatus("sending");
|
||||
try {
|
||||
const response = await fetch(LEADS_ENDPOINT, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
if (!response.ok) throw new Error("request failed");
|
||||
setStatus("success");
|
||||
form.reset();
|
||||
} catch {
|
||||
setStatus("error");
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Section id="contact">
|
||||
<SectionHeading title={t("contact.title")} subtitle={t("contact.subtitle")} />
|
||||
|
||||
<form
|
||||
onSubmit={(event) => void handleSubmit(event)}
|
||||
className="glass max-w-2xl rounded-lg border border-border/60 p-6 sm:p-8"
|
||||
data-reveal
|
||||
noValidate
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
name="website"
|
||||
tabIndex={-1}
|
||||
autoComplete="off"
|
||||
aria-hidden="true"
|
||||
className="absolute -left-[9999px] h-px w-px opacity-0"
|
||||
/>
|
||||
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<Input name="firstName" label={t("contact.firstName")} required autoComplete="given-name" />
|
||||
<Input name="lastName" label={t("contact.lastName")} required autoComplete="family-name" />
|
||||
</div>
|
||||
|
||||
<div className="mt-4 grid gap-4 sm:grid-cols-2">
|
||||
<Input name="organization" label={t("contact.company")} autoComplete="organization" />
|
||||
<Input name="phone" label={t("contact.phone")} type="tel" autoComplete="tel" />
|
||||
</div>
|
||||
|
||||
<div className="mt-4">
|
||||
<Input name="email" label={t("contact.email")} type="email" required autoComplete="email" />
|
||||
</div>
|
||||
|
||||
<div className="mt-4 flex flex-col gap-1.5">
|
||||
<label
|
||||
htmlFor="message"
|
||||
className="font-display text-[0.6875rem] font-semibold uppercase tracking-label text-foreground"
|
||||
>
|
||||
{t("contact.message")}
|
||||
</label>
|
||||
<textarea
|
||||
id="message"
|
||||
name="message"
|
||||
rows={5}
|
||||
required
|
||||
className="w-full rounded-sm border border-border-control bg-surface px-3 py-2.5 text-sm text-foreground placeholder:text-subtle-foreground transition-[border-color,box-shadow] duration-fast focus-visible:border-border-strong focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="mt-6 flex flex-wrap items-center gap-4">
|
||||
<button
|
||||
type="submit"
|
||||
disabled={status === "sending"}
|
||||
className="inline-flex h-12 items-center gap-2.5 rounded-lg bg-primary px-6 font-display text-sm font-semibold uppercase tracking-label text-primary-foreground transition-colors hover:bg-primary-hover disabled:pointer-events-none disabled:opacity-50"
|
||||
>
|
||||
{status === "sending" ? t("contact.sending") : t("contact.submit")}
|
||||
</button>
|
||||
|
||||
{status === "success" ? (
|
||||
<p className="text-sm text-success" role="status">
|
||||
{t("contact.success")}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
{status === "error" ? (
|
||||
<p className="text-sm text-destructive" role="alert">
|
||||
{t("contact.error")}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
</form>
|
||||
</Section>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,110 @@
|
||||
import { cn } from "@cohaise/ui";
|
||||
import type { DemoVariant } from "../data/demos.js";
|
||||
|
||||
const Bar = ({ className }: { className?: string }) => (
|
||||
<span className={cn("block rounded-full bg-surface-hover", className)} aria-hidden="true" />
|
||||
);
|
||||
|
||||
const Dot = ({ className }: { className?: string }) => (
|
||||
<span className={cn("block rounded-full bg-surface-hover", className)} aria-hidden="true" />
|
||||
);
|
||||
|
||||
/** Mini-interface neutre, dessinée en CSS : aucune capture, aucun logo, aucune marque. */
|
||||
export const DemoMockup = ({ variant }: { variant: DemoVariant }) => (
|
||||
<div className="relative aspect-[16/9] w-full overflow-hidden border-b border-border/60 bg-surface-sunken p-3 sm:p-4">
|
||||
<div className="flex h-full flex-col">
|
||||
<div className="mb-3 flex items-center gap-1.5" aria-hidden="true">
|
||||
<Dot className="size-2 bg-border-control" />
|
||||
<Dot className="size-2 bg-border-control" />
|
||||
<Dot className="size-2 bg-accent-graphic" />
|
||||
<span className="ml-auto h-2 w-24 rounded-full bg-surface-hover" />
|
||||
</div>
|
||||
{variant === "crm" ? <CrmMock /> : variant === "inventory" ? <InventoryMock /> : <LeaderboardMock />}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
const CrmMock = () => (
|
||||
<div className="flex min-h-0 flex-1 gap-3">
|
||||
<div className="flex w-14 shrink-0 flex-col gap-2 rounded-md border border-border/50 bg-surface/50 p-2" aria-hidden="true">
|
||||
<span className="h-1.5 w-6 rounded-full bg-accent-graphic" />
|
||||
<Bar className="h-1.5 w-9" />
|
||||
<Bar className="h-1.5 w-9" />
|
||||
<Bar className="h-1.5 w-7" />
|
||||
<div className="mt-auto" />
|
||||
<Bar className="h-1.5 w-6" />
|
||||
</div>
|
||||
<div className="flex min-w-0 flex-1 flex-col gap-3">
|
||||
<div className="grid shrink-0 grid-cols-3 gap-2" aria-hidden="true">
|
||||
{[0, 1, 2].map((index) => (
|
||||
<div key={index} className="flex flex-col gap-1.5 rounded-md border border-border/50 bg-surface/50 p-2">
|
||||
<Bar className="h-1.5 w-8" />
|
||||
<span className="h-3 w-7 rounded-sm bg-accent-graphic/70" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div className="flex min-h-0 flex-1 flex-col gap-2.5 rounded-md border border-border/50 bg-surface/50 p-2.5" aria-hidden="true">
|
||||
{[0, 1, 2, 3].map((index) => (
|
||||
<div key={index} className="flex items-center gap-2">
|
||||
<Dot className="size-3.5 shrink-0" />
|
||||
<Bar className="h-2 w-1/2" />
|
||||
<Bar className={cn("ml-auto h-1.5 w-9 rounded-full", index % 2 === 0 ? "bg-accent-graphic/50" : "bg-surface-hover")} />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
const InventoryMock = () => (
|
||||
<div className="flex min-h-0 flex-1 flex-col gap-3">
|
||||
<div className="flex shrink-0 items-center gap-2" aria-hidden="true">
|
||||
<span className="h-5 w-28 rounded-sm border border-border/50 bg-surface/50" />
|
||||
<span className="ml-auto h-5 w-16 rounded-sm bg-accent-graphic/70" />
|
||||
</div>
|
||||
<div className="flex min-h-0 flex-1 gap-3">
|
||||
<div className="flex min-w-0 flex-1 flex-col gap-2.5 rounded-md border border-border/50 bg-surface/50 p-2.5" aria-hidden="true">
|
||||
{[0, 1, 2, 3, 4].map((index) => (
|
||||
<div key={index} className="flex items-center gap-2">
|
||||
<span className="size-3.5 shrink-0 rounded-sm bg-surface-hover" />
|
||||
<Bar className="h-2 w-2/5" />
|
||||
<Bar className="ml-auto h-2 w-14" />
|
||||
<Bar className="h-1.5 w-8 rounded-full bg-accent-graphic/50" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div className="flex w-16 shrink-0 flex-col justify-end gap-1.5 rounded-md border border-border/50 bg-surface/50 p-2" aria-hidden="true">
|
||||
{["h-1/3", "h-2/3", "h-1/2", "h-4/5"].map((height, index) => (
|
||||
<span key={index} className={cn("w-full rounded-sm", height, index === 3 ? "bg-accent-graphic/70" : "bg-surface-hover")} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
const LeaderboardMock = () => (
|
||||
<div className="flex min-h-0 flex-1 gap-3">
|
||||
<div className="flex w-2/5 shrink-0 flex-col justify-end gap-2" aria-hidden="true">
|
||||
{[
|
||||
{ label: "h-1/2", accent: true },
|
||||
{ label: "h-4/5", accent: false },
|
||||
{ label: "h-2/3", accent: false },
|
||||
].map((item, index) => (
|
||||
<div key={index} className="flex items-end justify-center gap-1">
|
||||
<span className={cn("w-full rounded-md", item.label, item.accent ? "bg-accent-graphic" : "bg-surface-hover")} />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div className="flex min-w-0 flex-1 flex-col gap-2.5 rounded-md border border-border/50 bg-surface/50 p-2.5" aria-hidden="true">
|
||||
{[0, 1, 2, 3].map((index) => (
|
||||
<div key={index} className="flex items-center gap-2">
|
||||
<Dot className="size-3.5 shrink-0 rounded-full bg-accent-graphic/70" />
|
||||
<Bar className="h-2 w-1/3" />
|
||||
<div className="ml-auto h-1.5 w-24 overflow-hidden rounded-full bg-surface-hover">
|
||||
<span className={cn("block h-full rounded-full bg-accent-graphic/60", index === 0 ? "w-4/5" : index === 1 ? "w-3/5" : index === 2 ? "w-2/5" : "w-1/4")} />
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
@@ -0,0 +1,59 @@
|
||||
import { useLanguage } from "../lib/i18n.js";
|
||||
import type { Demo } from "../data/demos.js";
|
||||
import { DemoMockup } from "./DemoMockup.js";
|
||||
import { Section, SectionHeading } from "./Section.js";
|
||||
|
||||
export const Demos = ({ demos }: { demos: Demo[] }) => {
|
||||
const { t, pick } = useLanguage();
|
||||
|
||||
return (
|
||||
<Section id="demos">
|
||||
<SectionHeading title={t("demos.title")} subtitle={t("demos.subtitle")} />
|
||||
|
||||
<div className="grid gap-6 md:grid-cols-3">
|
||||
{demos.map((demo, index) => (
|
||||
<article
|
||||
key={demo.slug}
|
||||
data-reveal
|
||||
data-reveal-delay={String(index * 0.08)}
|
||||
className="glass flex flex-col overflow-hidden rounded-lg border border-border/60 shadow-sm"
|
||||
>
|
||||
<DemoMockup variant={demo.mockup} />
|
||||
|
||||
<div className="flex flex-1 flex-col gap-3 p-5">
|
||||
<span className="font-display text-[0.625rem] font-semibold uppercase tracking-label text-accent-graphic">
|
||||
{pick(demo.category)}
|
||||
</span>
|
||||
<h3 className="font-display text-lg font-bold uppercase tracking-display">
|
||||
{demo.title}
|
||||
</h3>
|
||||
<p className="text-sm leading-relaxed text-muted-foreground">
|
||||
{pick(demo.description)}
|
||||
</p>
|
||||
|
||||
<ul className="flex flex-wrap gap-2">
|
||||
{demo.tech.map((name) => (
|
||||
<li
|
||||
key={name}
|
||||
className="rounded-full border border-border/60 px-2.5 py-1 text-[0.625rem] uppercase tracking-label text-subtle-foreground"
|
||||
>
|
||||
{name}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
|
||||
<a
|
||||
href={demo.href}
|
||||
target="_blank"
|
||||
rel="noreferrer noopener"
|
||||
className="mt-auto inline-flex items-center gap-1.5 pt-1 font-display text-xs font-semibold uppercase tracking-label text-foreground transition-colors hover:text-accent"
|
||||
>
|
||||
{t("demos.source")} <span aria-hidden="true">↗</span>
|
||||
</a>
|
||||
</div>
|
||||
</article>
|
||||
))}
|
||||
</div>
|
||||
</Section>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,45 @@
|
||||
import { useLanguage } from "../lib/i18n.js";
|
||||
|
||||
const year = new Date().getFullYear();
|
||||
|
||||
export const Footer = () => {
|
||||
const { t } = useLanguage();
|
||||
|
||||
return (
|
||||
<footer className="border-t border-border/60">
|
||||
<div className="mx-auto flex w-full max-w-6xl flex-col gap-6 px-4 py-10 sm:flex-row sm:items-center sm:justify-between sm:px-6">
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="font-logo text-sm font-bold tracking-logo text-foreground">
|
||||
{t("brand.name")}
|
||||
</span>
|
||||
<span className="text-xs text-subtle-foreground">
|
||||
{t("footer.built")}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<nav className="flex flex-wrap gap-x-6 gap-y-2" aria-label="Liens">
|
||||
<a
|
||||
href="https://git.cohaise.dev/Esiah"
|
||||
target="_blank"
|
||||
rel="noreferrer noopener"
|
||||
className="text-xs uppercase tracking-label text-muted-foreground transition-colors hover:text-foreground"
|
||||
>
|
||||
Gitea (self-hosted)
|
||||
</a>
|
||||
<a
|
||||
href="https://github.com/xEsiah"
|
||||
target="_blank"
|
||||
rel="noreferrer noopener"
|
||||
className="text-xs uppercase tracking-label text-muted-foreground transition-colors hover:text-foreground"
|
||||
>
|
||||
GitHub
|
||||
</a>
|
||||
</nav>
|
||||
|
||||
<span className="text-xs text-subtle-foreground">
|
||||
© {year} {t("brand.name")} — {t("footer.rights")}
|
||||
</span>
|
||||
</div>
|
||||
</footer>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,101 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { cn } from "@cohaise/ui";
|
||||
import { useLanguage } from "../lib/i18n.js";
|
||||
import { useTheme } from "../hooks/useTheme.js";
|
||||
import { scrollToSection } from "../lib/gsap.js";
|
||||
|
||||
const links = [
|
||||
{ href: "#services", key: "nav.services" },
|
||||
{ href: "#demos", key: "nav.demos" },
|
||||
{ href: "#stack", key: "nav.stack" },
|
||||
{ href: "#about", key: "nav.about" },
|
||||
{ href: "#contact", key: "nav.contact" },
|
||||
] as const;
|
||||
|
||||
export const Header = () => {
|
||||
const { t, lang, setLang } = useLanguage();
|
||||
const { theme, toggleTheme } = useTheme();
|
||||
const [active, setActive] = useState<string>("");
|
||||
|
||||
useEffect(() => {
|
||||
const sections = links
|
||||
.map((link) => document.getElementById(link.href.slice(1)))
|
||||
.filter((element): element is HTMLElement => element !== null);
|
||||
|
||||
const observer = new IntersectionObserver(
|
||||
(entries) => {
|
||||
for (const entry of entries) {
|
||||
if (entry.isIntersecting) setActive(entry.target.id);
|
||||
}
|
||||
},
|
||||
{ rootMargin: "-45% 0px -50% 0px" },
|
||||
);
|
||||
|
||||
sections.forEach((section) => observer.observe(section));
|
||||
return () => observer.disconnect();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<header className="sticky top-0 z-40 border-b border-border/60 bg-background/70 backdrop-blur-xl">
|
||||
<div className="mx-auto flex h-16 max-w-6xl items-center gap-4 px-4 sm:px-6">
|
||||
<a
|
||||
href="#top"
|
||||
onClick={(event) => {
|
||||
event.preventDefault();
|
||||
scrollToSection("#top");
|
||||
}}
|
||||
className="flex items-center gap-2.5"
|
||||
>
|
||||
<img src="/images/cohaise.webp" alt="" className="size-7 object-contain" aria-hidden="true" />
|
||||
<span className="font-logo text-sm font-bold tracking-logo text-foreground">
|
||||
{t("brand.name")}
|
||||
</span>
|
||||
</a>
|
||||
|
||||
<nav className="ml-auto hidden items-center gap-1 md:flex" aria-label="Navigation">
|
||||
{links.map((link) => {
|
||||
const id = link.href.slice(1);
|
||||
return (
|
||||
<a
|
||||
key={link.href}
|
||||
href={link.href}
|
||||
onClick={(event) => {
|
||||
event.preventDefault();
|
||||
scrollToSection(link.href);
|
||||
}}
|
||||
aria-current={active === id ? "true" : undefined}
|
||||
className={cn(
|
||||
"rounded-md px-3 py-1.5 font-display text-[0.625rem] font-semibold uppercase tracking-label transition-colors",
|
||||
active === id
|
||||
? "bg-surface-hover text-foreground"
|
||||
: "text-muted-foreground hover:bg-surface-hover hover:text-foreground",
|
||||
)}
|
||||
>
|
||||
{t(link.key)}
|
||||
</a>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
|
||||
<div className="flex items-center gap-2 md:ml-6">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setLang(lang === "fr" ? "en" : "fr")}
|
||||
className="rounded-md border border-border px-2.5 py-1.5 font-display text-[0.625rem] font-semibold uppercase tracking-label text-muted-foreground transition-colors hover:border-border-strong hover:text-foreground"
|
||||
aria-label={lang === "fr" ? "Switch to English" : "Passer en français"}
|
||||
>
|
||||
{lang === "fr" ? "EN" : "FR"}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={toggleTheme}
|
||||
className="rounded-md border border-border px-2.5 py-1.5 font-display text-[0.625rem] font-semibold uppercase tracking-label text-muted-foreground transition-colors hover:border-border-strong hover:text-foreground"
|
||||
aria-label={t(theme === "dark" ? "theme.light" : "theme.dark")}
|
||||
>
|
||||
{t(theme === "dark" ? "theme.light" : "theme.dark")}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,61 @@
|
||||
import { useLanguage } from "../lib/i18n.js";
|
||||
import { scrollToSection } from "../lib/gsap.js";
|
||||
|
||||
export const Hero = () => {
|
||||
const { t } = useLanguage();
|
||||
|
||||
return (
|
||||
<section className="mx-auto flex w-full max-w-6xl flex-col items-start gap-6 px-4 pb-28 pt-24 sm:px-6 sm:pt-32">
|
||||
<h1
|
||||
data-reveal
|
||||
data-reveal-delay="0.08"
|
||||
className="font-display text-5xl font-black uppercase leading-none tracking-display sm:text-7xl md:text-8xl"
|
||||
>
|
||||
{t("brand.name")}
|
||||
</h1>
|
||||
|
||||
<p
|
||||
data-reveal
|
||||
data-reveal-delay="0.16"
|
||||
className="max-w-2xl text-xl font-medium leading-relaxed text-foreground sm:text-2xl"
|
||||
>
|
||||
{t("hero.tagline")}
|
||||
</p>
|
||||
|
||||
<p
|
||||
data-reveal
|
||||
data-reveal-delay="0.24"
|
||||
className="max-w-xl text-base leading-relaxed text-muted-foreground"
|
||||
>
|
||||
{t("hero.subtitle")}
|
||||
</p>
|
||||
|
||||
<div
|
||||
data-reveal
|
||||
data-reveal-delay="0.32"
|
||||
className="mt-6 flex flex-wrap gap-3"
|
||||
>
|
||||
<a
|
||||
href="#services"
|
||||
onClick={(event) => {
|
||||
event.preventDefault();
|
||||
scrollToSection("#services");
|
||||
}}
|
||||
className="inline-flex h-12 items-center gap-2.5 rounded-lg bg-primary px-6 font-display text-sm font-semibold uppercase tracking-label text-primary-foreground transition-colors hover:bg-primary-hover"
|
||||
>
|
||||
{t("hero.primary")}
|
||||
</a>
|
||||
<a
|
||||
href="#contact"
|
||||
onClick={(event) => {
|
||||
event.preventDefault();
|
||||
scrollToSection("#contact");
|
||||
}}
|
||||
className="inline-flex h-12 items-center gap-2.5 rounded-lg border border-border-strong bg-surface px-6 font-display text-sm font-semibold uppercase tracking-label text-foreground transition-colors hover:bg-surface-hover"
|
||||
>
|
||||
{t("hero.secondary")}
|
||||
</a>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
export const Section = ({ id, children }: { id: string; children: ReactNode }) => (
|
||||
<section id={id} className="mx-auto w-full max-w-6xl scroll-mt-24 px-4 py-24 sm:px-6">
|
||||
{children}
|
||||
</section>
|
||||
);
|
||||
|
||||
export const SectionHeading = ({
|
||||
eyebrow,
|
||||
title,
|
||||
subtitle,
|
||||
}: {
|
||||
eyebrow?: string;
|
||||
title: string;
|
||||
subtitle?: string;
|
||||
}) => (
|
||||
<div className="mb-12 flex flex-col gap-3" data-reveal>
|
||||
{eyebrow ? (
|
||||
<span className="font-display text-[0.625rem] font-semibold uppercase tracking-label text-accent-graphic">
|
||||
{eyebrow}
|
||||
</span>
|
||||
) : null}
|
||||
<h2 className="font-display text-3xl font-bold uppercase tracking-display sm:text-4xl">{title}</h2>
|
||||
{subtitle ? (
|
||||
<p className="max-w-2xl text-sm leading-relaxed text-muted-foreground sm:text-base">{subtitle}</p>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
@@ -0,0 +1,79 @@
|
||||
import { useState } from "react";
|
||||
import { cn } from "@cohaise/ui";
|
||||
import { useLanguage } from "../lib/i18n.js";
|
||||
import type { Service } from "../data/services.js";
|
||||
import { Section, SectionHeading } from "./Section.js";
|
||||
|
||||
export const Services = ({ services }: { services: Service[] }) => {
|
||||
const { t, pick } = useLanguage();
|
||||
const [open, setOpen] = useState<string | null>(services[0]?.slug ?? null);
|
||||
|
||||
return (
|
||||
<Section id="services">
|
||||
<SectionHeading title={t("services.title")} subtitle={t("services.subtitle")} />
|
||||
|
||||
<div className="flex flex-col" data-reveal>
|
||||
{services.map((service) => {
|
||||
const isOpen = open === service.slug;
|
||||
return (
|
||||
<article key={service.slug} className="border-b border-border/60 first:border-t">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setOpen(isOpen ? null : service.slug)}
|
||||
aria-expanded={isOpen}
|
||||
className="group flex w-full items-center gap-4 py-6 text-left sm:gap-8 sm:py-8"
|
||||
>
|
||||
<span className="font-display text-2xl font-bold uppercase tracking-display text-foreground transition-colors group-hover:text-accent sm:text-3xl md:text-4xl">
|
||||
{pick(service.title)}
|
||||
</span>
|
||||
<span
|
||||
className={cn(
|
||||
"ml-auto font-display text-3xl font-light text-accent-graphic transition-transform duration-base",
|
||||
isOpen ? "rotate-45" : "rotate-0",
|
||||
)}
|
||||
aria-hidden="true"
|
||||
>
|
||||
+
|
||||
</span>
|
||||
</button>
|
||||
|
||||
<div
|
||||
className={cn(
|
||||
"grid transition-[grid-template-rows] duration-slow ease-in-out-soft",
|
||||
isOpen ? "grid-rows-[1fr]" : "grid-rows-[0fr]",
|
||||
)}
|
||||
>
|
||||
<div className="overflow-hidden">
|
||||
<div className="flex flex-col gap-6 pb-8 md:flex-row md:items-start md:gap-10">
|
||||
<img
|
||||
src={service.image}
|
||||
alt=""
|
||||
loading="lazy"
|
||||
decoding="async"
|
||||
className="aspect-[3/2] w-full rounded-lg border border-border/60 object-cover md:w-64"
|
||||
/>
|
||||
<div className="flex flex-col gap-4">
|
||||
<p className="max-w-2xl text-base leading-relaxed text-muted-foreground sm:text-lg">
|
||||
{pick(service.description)}
|
||||
</p>
|
||||
<ul className="flex flex-wrap gap-2.5">
|
||||
{service.tags.map((tag) => (
|
||||
<li
|
||||
key={pick(tag)}
|
||||
className="rounded-full border border-border/60 px-4 py-1.5 text-[0.6875rem] uppercase tracking-label text-foreground transition-colors hover:bg-surface-hover"
|
||||
>
|
||||
{pick(tag)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</Section>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,65 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
import { gsap, prefersReducedMotion } from "../lib/gsap.js";
|
||||
import { useLanguage } from "../lib/i18n.js";
|
||||
import type { StackItem } from "../data/stack.js";
|
||||
import { Section, SectionHeading } from "./Section.js";
|
||||
|
||||
export const Stack = ({ items }: { items: StackItem[] }) => {
|
||||
const { t } = useLanguage();
|
||||
const trackRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const track = trackRef.current;
|
||||
if (!track || prefersReducedMotion()) return;
|
||||
|
||||
// Deux copies rendues dans le JSX : -50 % = exactement une copie, boucle sans couture.
|
||||
const tween = gsap.to(track, {
|
||||
xPercent: -50,
|
||||
duration: 36,
|
||||
ease: "none",
|
||||
repeat: -1,
|
||||
});
|
||||
|
||||
const slow = () => gsap.to(tween, { timeScale: 0.25, duration: 0.6, overwrite: true });
|
||||
const resume = () => gsap.to(tween, { timeScale: 1, duration: 0.6, overwrite: true });
|
||||
|
||||
track.addEventListener("mouseenter", slow);
|
||||
track.addEventListener("mouseleave", resume);
|
||||
|
||||
return () => {
|
||||
track.removeEventListener("mouseenter", slow);
|
||||
track.removeEventListener("mouseleave", resume);
|
||||
tween.kill();
|
||||
};
|
||||
}, []);
|
||||
|
||||
const doubled = [...items, ...items];
|
||||
|
||||
return (
|
||||
<Section id="stack">
|
||||
<SectionHeading title={t("stack.title")} subtitle={t("stack.subtitle")} />
|
||||
|
||||
<div className="overflow-hidden [mask-image:linear-gradient(to_right,transparent,black_10%,black_90%,transparent)]">
|
||||
<div ref={trackRef} className="flex w-max items-center gap-12">
|
||||
{doubled.map((item, index) => {
|
||||
const Icon = item.Icon;
|
||||
return (
|
||||
<span
|
||||
key={`${item.name}-${index}`}
|
||||
className="group/item flex shrink-0 items-center gap-3 whitespace-nowrap"
|
||||
>
|
||||
<Icon
|
||||
className="size-7 text-subtle-foreground transition-transform duration-300 ease-out group-hover/item:scale-125"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<span className="font-display text-lg uppercase tracking-label text-subtle-foreground">
|
||||
{item.name}
|
||||
</span>
|
||||
</span>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</Section>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,52 @@
|
||||
import type { Localized } from "../lib/i18n.js";
|
||||
|
||||
export type DemoVariant = "crm" | "inventory" | "leaderboard";
|
||||
|
||||
export interface Demo {
|
||||
slug: string;
|
||||
title: string;
|
||||
category: Localized;
|
||||
description: Localized;
|
||||
tech: string[];
|
||||
mockup: DemoVariant;
|
||||
href: string;
|
||||
}
|
||||
|
||||
export const demos: Demo[] = [
|
||||
{
|
||||
slug: "crm",
|
||||
title: "CRM",
|
||||
category: { fr: "Candidatures", en: "Applications" },
|
||||
description: {
|
||||
fr: "Suivi des prospects, organisations et pipelines de candidatures, avec workflows d'e-mails automatisés. Des connexions externes (WordPress, L'Express Éducation, d'autres sites) peuvent être mises en place.",
|
||||
en: "Track prospects, organizations and application pipelines, with automated email workflows. External connections (WordPress, L'Express Éducation, other sites) can be set up as needed.",
|
||||
},
|
||||
tech: ["Next.js", "Express", "MariaDB", "Docker"],
|
||||
mockup: "crm",
|
||||
href: "https://github.com/Ensemble-Scolaire-Jean-XXIII/jeanxxiii-crm",
|
||||
},
|
||||
{
|
||||
slug: "inventory",
|
||||
title: "Inventaire IT",
|
||||
category: { fr: "Inventaire", en: "Inventory" },
|
||||
description: {
|
||||
fr: "Inventaire du parc informatique : équipements par gabarit, champs personnalisés, validation MAC/IP et graphiques.",
|
||||
en: "IT asset inventory: equipment by template, custom fields, MAC/IP validation and charts.",
|
||||
},
|
||||
tech: ["Next.js", "Express", "MariaDB", "Docker"],
|
||||
mockup: "inventory",
|
||||
href: "https://github.com/Ensemble-Scolaire-Jean-XXIII/Inventory-IT",
|
||||
},
|
||||
{
|
||||
slug: "vie-de-classe",
|
||||
title: "Vie de classe",
|
||||
category: { fr: "Gamification scolaire", en: "Classroom gamification" },
|
||||
description: {
|
||||
fr: "Points, niveaux et médailles : un classement qui motive les classes et accompagne l'intégration des élèves.",
|
||||
en: "Points, levels and medals: a leaderboard that motivates classes and supports student onboarding.",
|
||||
},
|
||||
tech: ["Next.js", "Express", "MariaDB", "Docker"],
|
||||
mockup: "leaderboard",
|
||||
href: "https://github.com/Ensemble-Scolaire-Jean-XXIII/DEFI-Vie-de-classe",
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,69 @@
|
||||
import type { Localized } from "../lib/i18n.js";
|
||||
|
||||
export interface Service {
|
||||
slug: string;
|
||||
title: Localized;
|
||||
description: Localized;
|
||||
tags: Localized[];
|
||||
image: string;
|
||||
}
|
||||
|
||||
export const services: Service[] = [
|
||||
{
|
||||
slug: "web",
|
||||
title: { fr: "Développement web", en: "Web development" },
|
||||
description: {
|
||||
fr: "Des sites propres, rapides et responsives avec React et Next.js. Je vise la vitesse, la visibilité et la conversion de vos visiteurs en clients.",
|
||||
en: "Clean, fast, responsive sites with React and Next.js. I focus on speed, visibility and turning your visitors into clients.",
|
||||
},
|
||||
tags: [
|
||||
{ fr: "Sites vitrines", en: "Showcase sites" },
|
||||
{ fr: "SEO & performance", en: "SEO & performance" },
|
||||
{ fr: "Intégration CMS", en: "CMS integration" },
|
||||
],
|
||||
image: "/images/webDevelopment.webp",
|
||||
},
|
||||
{
|
||||
slug: "mobile",
|
||||
title: { fr: "Applications mobiles", en: "Mobile apps" },
|
||||
description: {
|
||||
fr: "Vos idées en vraies applications. React Native pour des expériences fluides, parfaites sur tous les téléphones.",
|
||||
en: "Your ideas as real apps. React Native for smooth experiences that work perfectly on every phone.",
|
||||
},
|
||||
tags: [
|
||||
{ fr: "Cross-platform", en: "Cross-platform" },
|
||||
{ fr: "Publication sur les stores", en: "App store submission" },
|
||||
{ fr: "Interfaces soignées", en: "Polished interfaces" },
|
||||
],
|
||||
image: "/images/mobileApps.webp",
|
||||
},
|
||||
{
|
||||
slug: "design",
|
||||
title: { fr: "UI/UX Design", en: "UI/UX Design" },
|
||||
description: {
|
||||
fr: "Des designs simples et efficaces. Des interfaces belles, qui aident vos utilisateurs à trouver ce qu'ils cherchent sans effort.",
|
||||
en: "Simple, effective design. Interfaces that look great and help users find what they need, effortlessly.",
|
||||
},
|
||||
tags: [
|
||||
{ fr: "Wireframes & prototypes", en: "Wireframing & prototyping" },
|
||||
{ fr: "Mobile-first", en: "Mobile-first" },
|
||||
{ fr: "Identité visuelle", en: "Visual identity" },
|
||||
],
|
||||
image: "/images/uxUI.webp",
|
||||
},
|
||||
{
|
||||
slug: "custom",
|
||||
title: { fr: "Logiciels sur mesure", en: "Custom software" },
|
||||
description: {
|
||||
fr: "Un besoin précis ? Je construis des outils et tableaux de bord sur mesure pour automatiser vos tâches et gagner du temps.",
|
||||
en: "Something specific in mind? I build custom tools and dashboards to automate your daily tasks and save you time.",
|
||||
},
|
||||
tags: [
|
||||
{ fr: "Outils web", en: "Web tools" },
|
||||
{ fr: "Applications desktop", en: "Desktop apps" },
|
||||
{ fr: "Tableaux de bord", en: "Dashboards" },
|
||||
{ fr: "Connexions API", en: "API connections" },
|
||||
],
|
||||
image: "/images/customSoftware.webp",
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,43 @@
|
||||
import type { IconType } from "react-icons";
|
||||
import {
|
||||
SiReact,
|
||||
SiNextdotjs,
|
||||
SiTypescript,
|
||||
SiNodedotjs,
|
||||
SiExpress,
|
||||
SiMariadb,
|
||||
SiPostgresql,
|
||||
SiDocker,
|
||||
SiTailwindcss,
|
||||
SiFigma,
|
||||
SiGit,
|
||||
SiLinux,
|
||||
SiCloudflare,
|
||||
SiVercel,
|
||||
SiElectron,
|
||||
SiDotnet,
|
||||
} from "react-icons/si";
|
||||
|
||||
export interface StackItem {
|
||||
name: string;
|
||||
Icon: IconType;
|
||||
}
|
||||
|
||||
export const stack: StackItem[] = [
|
||||
{ name: "React", Icon: SiReact },
|
||||
{ name: "Next.js", Icon: SiNextdotjs },
|
||||
{ name: "TypeScript", Icon: SiTypescript },
|
||||
{ name: "Node.js", Icon: SiNodedotjs },
|
||||
{ name: "Express", Icon: SiExpress },
|
||||
{ name: "MariaDB", Icon: SiMariadb },
|
||||
{ name: "PostgreSQL", Icon: SiPostgresql },
|
||||
{ name: "Docker", Icon: SiDocker },
|
||||
{ name: "Tailwind CSS", Icon: SiTailwindcss },
|
||||
{ name: "Figma", Icon: SiFigma },
|
||||
{ name: "Git", Icon: SiGit },
|
||||
{ name: "Linux", Icon: SiLinux },
|
||||
{ name: "Cloudflare", Icon: SiCloudflare },
|
||||
{ name: "Vercel", Icon: SiVercel },
|
||||
{ name: "Electron", Icon: SiElectron },
|
||||
{ name: ".NET", Icon: SiDotnet },
|
||||
];
|
||||
@@ -0,0 +1,30 @@
|
||||
import { useLayoutEffect } from "react";
|
||||
import { gsap, prefersReducedMotion } from "../lib/gsap.js";
|
||||
|
||||
/**
|
||||
* Anime à l'entrée tout élément portant `data-reveal` (fade-up au scroll).
|
||||
* Un `data-reveal-delay` optionnel (secondes) retarde l'élément pour créer
|
||||
* un décalage entre des éléments voisins.
|
||||
*/
|
||||
export const useScrollReveal = (): void => {
|
||||
useLayoutEffect(() => {
|
||||
if (prefersReducedMotion()) return;
|
||||
|
||||
const context = gsap.context(() => {
|
||||
const elements = gsap.utils.toArray<HTMLElement>("[data-reveal]");
|
||||
elements.forEach((element) => {
|
||||
const delay = Number.parseFloat(element.dataset.revealDelay ?? "0") || 0;
|
||||
gsap.from(element, {
|
||||
y: 32,
|
||||
opacity: 0,
|
||||
duration: 0.9,
|
||||
delay,
|
||||
ease: "power3.out",
|
||||
scrollTrigger: { trigger: element, start: "top 88%" },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
return () => context.revert();
|
||||
}, []);
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
|
||||
export type Theme = "light" | "dark";
|
||||
|
||||
const storageKey = "cohaise-theme";
|
||||
|
||||
const readInitialTheme = (): Theme =>
|
||||
document.documentElement.classList.contains("dark") ? "dark" : "light";
|
||||
|
||||
export const useTheme = () => {
|
||||
const [theme, setTheme] = useState<Theme>(readInitialTheme);
|
||||
|
||||
useEffect(() => {
|
||||
document.documentElement.classList.toggle("dark", theme === "dark");
|
||||
localStorage.setItem(storageKey, theme);
|
||||
}, [theme]);
|
||||
|
||||
const toggleTheme = useCallback(() => {
|
||||
setTheme((current) => (current === "dark" ? "light" : "dark"));
|
||||
}, []);
|
||||
|
||||
return { theme, toggleTheme };
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
/** Point d'entrée de l'API CRM. Surchargeable via VITE_CRM_API_URL au build. */
|
||||
const host = typeof window !== "undefined" ? window.location.hostname : "";
|
||||
const isLocal = host === "localhost" || host === "127.0.0.1" || host === "0.0.0.0";
|
||||
|
||||
const base =
|
||||
(import.meta.env.VITE_CRM_API_URL as string | undefined) ??
|
||||
(isLocal ? "http://localhost:8082" : "https://crm.cohaise.dev");
|
||||
|
||||
const trimmed = base.replace(/\/+$/, "");
|
||||
|
||||
/** Endpoint public qui crée un prospect depuis le formulaire de contact. */
|
||||
export const LEADS_ENDPOINT = `${trimmed}/api/crm/leads`;
|
||||