create-astratra-app 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -0
- package/package.json +3 -2
- package/src/bricks.js +4 -4
- package/src/createProject.js +66 -11
- package/templates/mobile/README.md +70 -0
- package/templates/mobile/app/_layout.tsx +58 -0
- package/templates/mobile/app/dashboard.tsx +73 -0
- package/templates/mobile/app/forgot-password.tsx +64 -0
- package/templates/mobile/app/home.tsx +32 -0
- package/templates/mobile/app/index.tsx +27 -0
- package/templates/mobile/app/login.tsx +118 -0
- package/templates/mobile/app/notifications.tsx +67 -0
- package/templates/mobile/app/onboarding/_layout.tsx +5 -0
- package/templates/mobile/app/onboarding/done.tsx +45 -0
- package/templates/mobile/app/onboarding/index.tsx +52 -0
- package/templates/mobile/app/settings.tsx +95 -0
- package/templates/mobile/app.config.js +37 -0
- package/templates/mobile/babel.config.js +17 -0
- package/templates/mobile/components/AnimatedPressable.tsx +34 -0
- package/templates/mobile/components/BrandBackground.tsx +33 -0
- package/templates/mobile/components/ErrorBoundary.tsx +28 -0
- package/templates/mobile/components/GlassPanel.tsx +67 -0
- package/templates/mobile/components/GridBackground.tsx +35 -0
- package/templates/mobile/components/KeyboardScreen.tsx +81 -0
- package/templates/mobile/components/PasswordEyeIcon.tsx +41 -0
- package/templates/mobile/components/SessionGuard.tsx +29 -0
- package/templates/mobile/components/dashboard/DashboardHeader.tsx +71 -0
- package/templates/mobile/components/dashboard/DashboardReveal.tsx +46 -0
- package/templates/mobile/components/dashboard/KpiBubble.tsx +169 -0
- package/templates/mobile/components/dashboard/MoreButton.tsx +65 -0
- package/templates/mobile/components/dashboard/NotificationBell.tsx +80 -0
- package/templates/mobile/components/dashboard/StaffTabBar.tsx +70 -0
- package/templates/mobile/components/dashboard/ToolCard.tsx +136 -0
- package/templates/mobile/components/glass/LiquidGlassSurface.tsx +266 -0
- package/templates/mobile/components/onboarding/StepScreen.tsx +185 -0
- package/templates/mobile/constants/dashboard.ts +50 -0
- package/templates/mobile/constants/theme.ts +104 -0
- package/templates/mobile/context/AuthContext.tsx +106 -0
- package/templates/mobile/eas.json +9 -0
- package/templates/mobile/env.example +2 -0
- package/templates/mobile/features/routes.ts +23 -0
- package/templates/mobile/gitignore +7 -0
- package/templates/mobile/i18n/config.ts +24 -0
- package/templates/mobile/i18n/locales/en.json +62 -0
- package/templates/mobile/i18n/locales/fr.json +62 -0
- package/templates/mobile/package.json +48 -0
- package/templates/mobile/services/push.ts +67 -0
- package/templates/mobile/services/session.ts +77 -0
- package/templates/mobile/tsconfig.json +8 -0
package/README.md
CHANGED
|
@@ -41,6 +41,27 @@ Template API seule :
|
|
|
41
41
|
npm create astratra-app@latest my-api -- --template api
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
+
Template mobile :
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npm create astratra-app@latest my-app -- --template mobile
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Il crée une application **Expo Router** montée sur `@astratra/native` et
|
|
51
|
+
`@astratra/client` :
|
|
52
|
+
|
|
53
|
+
- session dans le trousseau du téléphone, rafraîchissement à vol unique ;
|
|
54
|
+
- verrou biométrique et interrupteur de notifications dans les réglages ;
|
|
55
|
+
- notifications natives : canaux, veille au premier plan, route vérifiée avant
|
|
56
|
+
d'ouvrir un écran ;
|
|
57
|
+
- écrans splash, accueil public, connexion, mot de passe oublié, tableau de
|
|
58
|
+
bord, réglages, notifications ;
|
|
59
|
+
- i18n (en, fr) et thème dans `constants/theme.ts`.
|
|
60
|
+
|
|
61
|
+
Ce template ne prend pas de briques : elles sont du câblage serveur. Générez
|
|
62
|
+
l'API avec le template `fullstack` et pointez l'application dessus par
|
|
63
|
+
`EXPO_PUBLIC_API_BASE_URL`.
|
|
64
|
+
|
|
44
65
|
## Après Génération
|
|
45
66
|
|
|
46
67
|
```bash
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-astratra-app",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "CLI generator for new Astratra SaaS applications.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=20"
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
},
|
|
12
12
|
"files": [
|
|
13
13
|
"bin",
|
|
14
|
-
"src"
|
|
14
|
+
"src",
|
|
15
|
+
"templates"
|
|
15
16
|
],
|
|
16
17
|
"scripts": {
|
|
17
18
|
"test": "node --test __tests__/*.test.js"
|
package/src/bricks.js
CHANGED
|
@@ -22,7 +22,7 @@ const FULLSTACK_ONLY = new Set(['client', 'prerender']);
|
|
|
22
22
|
const BRICKS = {
|
|
23
23
|
credentials: {
|
|
24
24
|
package: '@astratra/credentials',
|
|
25
|
-
version: '^0.
|
|
25
|
+
version: '^0.3.0',
|
|
26
26
|
summary: 'clés de service chiffrées en base, modifiables sans redémarrage',
|
|
27
27
|
file: 'api/bricks/credentials.js',
|
|
28
28
|
contents: () => `import { createFieldCipher } from '@astratra/security';
|
|
@@ -71,7 +71,7 @@ export const hydrator = createEnvHydrator({ vault });
|
|
|
71
71
|
|
|
72
72
|
entitlements: {
|
|
73
73
|
package: '@astratra/entitlements',
|
|
74
|
-
version: '^0.
|
|
74
|
+
version: '^0.4.0',
|
|
75
75
|
summary: 'plans, droits d’accès, isolation par locataire, invitations',
|
|
76
76
|
file: 'api/bricks/entitlements.js',
|
|
77
77
|
contents: () => `import { createFeatureGuard, createPlanCatalog, createTenantScope } from '@astratra/entitlements';
|
|
@@ -136,7 +136,7 @@ export async function sendWelcome(to, name) {
|
|
|
136
136
|
|
|
137
137
|
payments: {
|
|
138
138
|
package: '@astratra/payments',
|
|
139
|
-
version: '^0.
|
|
139
|
+
version: '^0.2.0',
|
|
140
140
|
summary: 'webhooks de paiement : signature, rejeux, exemptions',
|
|
141
141
|
file: 'api/bricks/payments.js',
|
|
142
142
|
contents: () => `import {
|
|
@@ -336,7 +336,7 @@ export const archive = createArchiveBuilder({
|
|
|
336
336
|
|
|
337
337
|
client: {
|
|
338
338
|
package: '@astratra/client',
|
|
339
|
-
version: '^0.
|
|
339
|
+
version: '^0.3.0',
|
|
340
340
|
summary: 'session sur 401, garde de route, mots de passe, file hors ligne',
|
|
341
341
|
file: 'web/src/lib/client.js',
|
|
342
342
|
contents: () => `import { createPasswordRules, createRouteGuard, createSessionClient } from '@astratra/client';
|
package/src/createProject.js
CHANGED
|
@@ -1,8 +1,48 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
3
4
|
import { BRICK_NAMES, brickDependencies, brickFiles, resolveBricks } from './bricks.js';
|
|
4
5
|
|
|
5
|
-
const VALID_TEMPLATES = new Set(['api', 'fullstack']);
|
|
6
|
+
const VALID_TEMPLATES = new Set(['api', 'fullstack', 'mobile']);
|
|
7
|
+
|
|
8
|
+
/* The mobile template is a real Expo file tree, copied as-is.
|
|
9
|
+
Writing an Expo app as inline JS strings — the method the API and web
|
|
10
|
+
templates use — would add well over a thousand lines of quoted TSX to this
|
|
11
|
+
file, unreadable and impossible to lint as what it is. */
|
|
12
|
+
const TEMPLATES_DIR = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'templates');
|
|
13
|
+
|
|
14
|
+
/* npm strips a .gitignore from a published tarball, and a .env.example is easy
|
|
15
|
+
to lose the same way. They ship under neutral names and are restored here. */
|
|
16
|
+
const TEMPLATE_RENAMES = new Map([
|
|
17
|
+
['gitignore', '.gitignore'],
|
|
18
|
+
['env.example', '.env.example']
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
function copyTemplate(templateName, targetDir, projectName) {
|
|
22
|
+
const source = path.join(TEMPLATES_DIR, templateName);
|
|
23
|
+
if (!fs.existsSync(source)) throw new Error(`Template files are missing: ${source}`);
|
|
24
|
+
|
|
25
|
+
const walk = (from, to) => {
|
|
26
|
+
fs.mkdirSync(to, { recursive: true });
|
|
27
|
+
for (const entry of fs.readdirSync(from, { withFileTypes: true })) {
|
|
28
|
+
const renamed = TEMPLATE_RENAMES.get(entry.name) || entry.name;
|
|
29
|
+
const fromPath = path.join(from, entry.name);
|
|
30
|
+
const toPath = path.join(to, renamed);
|
|
31
|
+
if (entry.isDirectory()) {
|
|
32
|
+
walk(fromPath, toPath);
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
let contents = fs.readFileSync(fromPath, 'utf8');
|
|
36
|
+
if (entry.name === 'package.json') {
|
|
37
|
+
contents = contents.replace('"name": "astratra-mobile-app"', `"name": "${toPackageName(projectName)}"`);
|
|
38
|
+
}
|
|
39
|
+
contents = contents.replaceAll('__PROJECT_NAME__', projectName);
|
|
40
|
+
fs.writeFileSync(toPath, contents);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
walk(source, targetDir);
|
|
45
|
+
}
|
|
6
46
|
|
|
7
47
|
function toPackageName(projectName) {
|
|
8
48
|
return projectName
|
|
@@ -28,10 +68,10 @@ function assertCanCreate(targetDir, force) {
|
|
|
28
68
|
|
|
29
69
|
function packageJson(projectName, template, bricks = []) {
|
|
30
70
|
const dependencies = {
|
|
31
|
-
'@astratra/ai': '^1.
|
|
32
|
-
'@astratra/core': '^1.0.
|
|
33
|
-
'@astratra/saas-kit': '^1.
|
|
34
|
-
'@astratra/security': '^1.
|
|
71
|
+
'@astratra/ai': '^1.2.0',
|
|
72
|
+
'@astratra/core': '^1.0.1',
|
|
73
|
+
'@astratra/saas-kit': '^1.6.0',
|
|
74
|
+
'@astratra/security': '^1.10.0'
|
|
35
75
|
};
|
|
36
76
|
// Scaffolded (api/stores/mongo.js, api/db/mongo.js) but not wired into
|
|
37
77
|
// api/server.js by default — the project starts on the in-memory store.
|
|
@@ -39,13 +79,13 @@ function packageJson(projectName, template, bricks = []) {
|
|
|
39
79
|
// real driver dependency) before the project has ever chosen to use it.
|
|
40
80
|
// `npm install @astratra/store-mongo mongoose` to switch to MongoDB.
|
|
41
81
|
const optionalDependencies = {
|
|
42
|
-
'@astratra/store-mongo': '^1.0
|
|
82
|
+
'@astratra/store-mongo': '^1.1.0',
|
|
43
83
|
mongoose: '^8.17.0'
|
|
44
84
|
};
|
|
45
85
|
const devDependencies = {};
|
|
46
86
|
|
|
47
87
|
if (template === 'fullstack') {
|
|
48
|
-
dependencies['@astratra/saas-kit-ui'] = '^1.0.
|
|
88
|
+
dependencies['@astratra/saas-kit-ui'] = '^1.0.1';
|
|
49
89
|
dependencies.react = '^19.0.0';
|
|
50
90
|
dependencies['react-dom'] = '^19.0.0';
|
|
51
91
|
devDependencies['@vitejs/plugin-react'] = '^4.3.4';
|
|
@@ -77,7 +117,6 @@ function packageJson(projectName, template, bricks = []) {
|
|
|
77
117
|
function apiServer() {
|
|
78
118
|
return `import fs from 'node:fs';
|
|
79
119
|
import path from 'node:path';
|
|
80
|
-
import { BRICK_NAMES, brickDependencies, brickFiles, resolveBricks } from './bricks.js';
|
|
81
120
|
import saasKit from '@astratra/saas-kit';
|
|
82
121
|
import { env } from './config/env.js';
|
|
83
122
|
import { createAuthSecurity } from './security/auth.js';
|
|
@@ -379,7 +418,6 @@ function notificationsModule() {
|
|
|
379
418
|
function viteConfig() {
|
|
380
419
|
return `import fs from 'node:fs';
|
|
381
420
|
import path from 'node:path';
|
|
382
|
-
import { BRICK_NAMES, brickDependencies, brickFiles, resolveBricks } from './bricks.js';
|
|
383
421
|
import react from '@vitejs/plugin-react';
|
|
384
422
|
import { defineConfig } from 'vite';
|
|
385
423
|
|
|
@@ -630,12 +668,18 @@ export function parseArgs(args) {
|
|
|
630
668
|
|
|
631
669
|
if (!options.targetDir) {
|
|
632
670
|
throw new Error(
|
|
633
|
-
'Usage: create-astratra-app <directory> [--template api|fullstack] ' +
|
|
671
|
+
'Usage: create-astratra-app <directory> [--template api|fullstack|mobile] ' +
|
|
634
672
|
`[--with ${BRICK_NAMES.slice(0, 3).join(',')},...|all] [--force]`
|
|
635
673
|
);
|
|
636
674
|
}
|
|
637
675
|
if (!VALID_TEMPLATES.has(options.template)) {
|
|
638
|
-
throw new Error(`Unknown template "${options.template}". Use api or
|
|
676
|
+
throw new Error(`Unknown template "${options.template}". Use api, fullstack or mobile.`);
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
// Les briques sont du câblage serveur : elles n'ont rien à faire dans une
|
|
680
|
+
// application mobile, et l'accepter en silence livrerait des fichiers morts.
|
|
681
|
+
if (options.template === 'mobile' && options.bricks.length > 0) {
|
|
682
|
+
throw new Error('The mobile template takes no bricks — they are server-side wiring.');
|
|
639
683
|
}
|
|
640
684
|
|
|
641
685
|
// Résolu ici plutôt qu'à l'écriture : un nom de brique fautif doit échouer
|
|
@@ -652,6 +696,17 @@ export function createProject({ targetDir, template = 'fullstack', force = false
|
|
|
652
696
|
assertCanCreate(absoluteTarget, force);
|
|
653
697
|
fs.mkdirSync(absoluteTarget, { recursive: true });
|
|
654
698
|
|
|
699
|
+
/* The mobile template shares nothing with the API one: no Express server, no
|
|
700
|
+
Vite, no bricks — those are server-side wiring. */
|
|
701
|
+
if (template === 'mobile') {
|
|
702
|
+
copyTemplate('mobile', absoluteTarget, projectName);
|
|
703
|
+
return {
|
|
704
|
+
targetDir: absoluteTarget,
|
|
705
|
+
bricks: [],
|
|
706
|
+
nextSteps: [`cd ${targetDir}`, 'npm install', 'cp .env.example .env', 'npm start']
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
|
|
655
710
|
const selectedBricks = resolveBricks(bricks, template);
|
|
656
711
|
|
|
657
712
|
writeFile(absoluteTarget, 'package.json', `${packageJson(projectName, template, selectedBricks)}\n`);
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# __PROJECT_NAME__
|
|
2
|
+
|
|
3
|
+
Application mobile Expo, montée sur `@astratra/native` et `@astratra/client`.
|
|
4
|
+
|
|
5
|
+
## Démarrer
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install
|
|
9
|
+
cp .env.example .env
|
|
10
|
+
npm start
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
L'URL de l'API a une valeur de développement par défaut : `localhost:3000/api`
|
|
14
|
+
sur simulateur iOS, `10.0.2.2:3000` sur émulateur Android — celui-ci tourne
|
|
15
|
+
dans sa propre VM réseau, où « localhost » désigne l'émulateur lui-même.
|
|
16
|
+
|
|
17
|
+
## Ce qui est déjà là
|
|
18
|
+
|
|
19
|
+
| Fichier | Rôle |
|
|
20
|
+
|---|---|
|
|
21
|
+
| `services/session.ts` | trousseau, jetons, rafraîchissement à vol unique, langue par appel |
|
|
22
|
+
| `services/push.ts` | notifications natives : canaux, catégories, enregistrement de l'appareil |
|
|
23
|
+
| `features/routes.ts` | ce qui est public, et où une notification a le droit de mener |
|
|
24
|
+
| `context/AuthContext.tsx` | qui est connecté, restauration au lancement, déconnexion propre |
|
|
25
|
+
| `components/SessionGuard.tsx` | la pile fermée derrière la session |
|
|
26
|
+
| `app/` | splash, accueil public, connexion, mot de passe oublié, tableau de bord, réglages, notifications |
|
|
27
|
+
| `components/KeyboardScreen.tsx` | l'écran qui survit au clavier — enveloppe tout formulaire |
|
|
28
|
+
| `components/glass/` | la surface de verre : flou natif iOS, réfraction Skia, repli ailleurs |
|
|
29
|
+
| `components/dashboard/` | en-tête, cloche, bandeau de KPI, tuiles, barre d'onglets, apparition en cascade |
|
|
30
|
+
| `constants/dashboard.ts` | ce que le tableau de bord affiche, **en données** — c'est ce qu'on édite pour changer d'application |
|
|
31
|
+
|
|
32
|
+
## Le clavier
|
|
33
|
+
|
|
34
|
+
Tout écran portant un formulaire s'enveloppe dans `KeyboardScreen`. Ne recopiez
|
|
35
|
+
pas un `KeyboardAvoidingView` à la main : Expo règle Android en
|
|
36
|
+
`softwareKeyboardLayoutMode: 'resize'`, donc le système redimensionne déjà la
|
|
37
|
+
fenêtre. Ajouter `behavior="height"` par-dessus corrige deux fois la même chose
|
|
38
|
+
et fait sauter la mise en page. iOS, lui, ne redimensionne pas et a besoin de
|
|
39
|
+
`padding`. `KeyboardScreen` tranche une fois pour toutes.
|
|
40
|
+
|
|
41
|
+
## Un *development build*, pas Expo Go
|
|
42
|
+
|
|
43
|
+
L'application démarre dans Expo Go pour un aperçu rapide, mais deux choses n'y
|
|
44
|
+
fonctionnent pas :
|
|
45
|
+
|
|
46
|
+
- **les notifications push** — retirées d'Expo Go depuis le SDK 53 ;
|
|
47
|
+
- **l'effet de verre** — Skia et `expo-glass-effect` sont des modules natifs.
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
npx expo run:ios # ou run:android
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
C'est de toute façon ce dont a besoin une vraie application livrée à un client.
|
|
54
|
+
|
|
55
|
+
## Ce qu'il faut changer en premier
|
|
56
|
+
|
|
57
|
+
1. `app.config.js` — nom, slug, `scheme`, identifiants iOS/Android.
|
|
58
|
+
2. `features/routes.ts` — les écrans publics et les routes de notification de
|
|
59
|
+
VOTRE application. Les deux listes nomment ce qui est **autorisé** : un
|
|
60
|
+
écran ajouté plus tard et oublié reste fermé, ce qui est le bon défaut.
|
|
61
|
+
3. `services/push.ts` — les canaux Android et les points d'API qui
|
|
62
|
+
enregistrent un appareil.
|
|
63
|
+
4. `constants/theme.ts` — couleurs et espacements.
|
|
64
|
+
5. `i18n/locales/` — les textes.
|
|
65
|
+
|
|
66
|
+
## Ce qui n'est pas fourni
|
|
67
|
+
|
|
68
|
+
Le métier. Les écrans livrés sont le socle qu'aucune application ne réécrit :
|
|
69
|
+
se connecter, rester connecté, être notifié, se déconnecter. Ce qui distingue
|
|
70
|
+
votre application se construit par-dessus.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shell every screen sits in: session, guard, notifications, language.
|
|
3
|
+
*
|
|
4
|
+
* The order matters. The guard must be INSIDE the auth provider — it needs to
|
|
5
|
+
* know whether the session is still restoring — and the notification listeners
|
|
6
|
+
* must start after both, because where a tapped notification leads depends on
|
|
7
|
+
* who is signed in.
|
|
8
|
+
*/
|
|
9
|
+
import { useEffect } from 'react';
|
|
10
|
+
import Constants, { ExecutionEnvironment } from 'expo-constants';
|
|
11
|
+
import { Stack } from 'expo-router';
|
|
12
|
+
import { StatusBar } from 'expo-status-bar';
|
|
13
|
+
import { SafeAreaProvider } from 'react-native-safe-area-context';
|
|
14
|
+
import { AuthProvider, useAuth } from '../context/AuthContext';
|
|
15
|
+
import { SessionGuard } from '../components/SessionGuard';
|
|
16
|
+
import { ErrorBoundary } from '../components/ErrorBoundary';
|
|
17
|
+
import { push } from '../services/push';
|
|
18
|
+
import '../i18n/config';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Expo Go cannot receive push notifications — remote push was removed from it
|
|
22
|
+
* in SDK 53 — and merely touching the module there raises a red error banner
|
|
23
|
+
* over a perfectly healthy app. Starting the listeners is skipped, rather than
|
|
24
|
+
* attempted and failed noisily.
|
|
25
|
+
*
|
|
26
|
+
* Nothing else changes: in a development build, and in the shipped app, this
|
|
27
|
+
* is false and the listeners start normally.
|
|
28
|
+
*/
|
|
29
|
+
const IN_EXPO_GO = Constants.executionEnvironment === ExecutionEnvironment.StoreClient;
|
|
30
|
+
|
|
31
|
+
function NotificationBridge() {
|
|
32
|
+
const { user } = useAuth();
|
|
33
|
+
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (!user || IN_EXPO_GO) return undefined;
|
|
36
|
+
let stop: (() => void) | undefined;
|
|
37
|
+
void push.startListeners(user.role).then((dispose) => { stop = dispose; });
|
|
38
|
+
return () => { if (stop) stop(); };
|
|
39
|
+
}, [user]);
|
|
40
|
+
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export default function RootLayout() {
|
|
45
|
+
return (
|
|
46
|
+
<SafeAreaProvider>
|
|
47
|
+
<ErrorBoundary>
|
|
48
|
+
<AuthProvider>
|
|
49
|
+
<SessionGuard>
|
|
50
|
+
<NotificationBridge />
|
|
51
|
+
<StatusBar style="light" />
|
|
52
|
+
<Stack screenOptions={{ headerShown: false, animation: 'fade' }} />
|
|
53
|
+
</SessionGuard>
|
|
54
|
+
</AuthProvider>
|
|
55
|
+
</ErrorBoundary>
|
|
56
|
+
</SafeAreaProvider>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The dashboard, built from the real components.
|
|
3
|
+
*
|
|
4
|
+
* Everything on this screen is DATA, not markup: the KPI row and the tiles are
|
|
5
|
+
* declared as lists, so a product changes what its dashboard shows by editing
|
|
6
|
+
* `constants/dashboard.ts` — not by rewriting a screen. That is what lets one
|
|
7
|
+
* dashboard serve several roles.
|
|
8
|
+
*/
|
|
9
|
+
import { useMemo } from 'react';
|
|
10
|
+
import { ScrollView, View } from 'react-native';
|
|
11
|
+
import { useRouter } from 'expo-router';
|
|
12
|
+
import { useTranslation } from 'react-i18next';
|
|
13
|
+
import DashboardHeader from '../components/dashboard/DashboardHeader';
|
|
14
|
+
import DashboardReveal from '../components/dashboard/DashboardReveal';
|
|
15
|
+
import KpiBubble from '../components/dashboard/KpiBubble';
|
|
16
|
+
import MoreButton from '../components/dashboard/MoreButton';
|
|
17
|
+
import StaffTabBar from '../components/dashboard/StaffTabBar';
|
|
18
|
+
import ToolCard from '../components/dashboard/ToolCard';
|
|
19
|
+
import { useAuth } from '../context/AuthContext';
|
|
20
|
+
import { colors, spacing } from '../constants/theme';
|
|
21
|
+
import GridBackground from '../components/GridBackground';
|
|
22
|
+
import { dashboardKpis, dashboardTabs, dashboardTools } from '../constants/dashboard';
|
|
23
|
+
|
|
24
|
+
export default function Dashboard() {
|
|
25
|
+
const { t } = useTranslation();
|
|
26
|
+
const { user } = useAuth();
|
|
27
|
+
const router = useRouter();
|
|
28
|
+
|
|
29
|
+
const kpis = useMemo(() => dashboardKpis(t), [t]);
|
|
30
|
+
const tools = useMemo(() => dashboardTools(t), [t]);
|
|
31
|
+
const tabs = useMemo(() => dashboardTabs(t), [t]);
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<View style={{ flex: 1, backgroundColor: colors.background }}>
|
|
35
|
+
<GridBackground />
|
|
36
|
+
{/* Room at the bottom for the tab bar, which floats over the content. */}
|
|
37
|
+
<ScrollView contentContainerStyle={{ padding: spacing.lg, paddingTop: spacing.xl * 2, paddingBottom: 120 }}>
|
|
38
|
+
<DashboardHeader name={user?.fullName || user?.email || ''} online unread={0} />
|
|
39
|
+
|
|
40
|
+
<DashboardReveal delay={60}>
|
|
41
|
+
<View style={{ marginTop: spacing.lg }}>
|
|
42
|
+
<KpiBubble items={kpis} />
|
|
43
|
+
</View>
|
|
44
|
+
</DashboardReveal>
|
|
45
|
+
|
|
46
|
+
<View style={{ flexDirection: 'row', flexWrap: 'wrap', gap: 12, marginTop: spacing.lg }}>
|
|
47
|
+
{tools.map((tool, index) => (
|
|
48
|
+
<DashboardReveal key={tool.label} delay={120 + index * 60}>
|
|
49
|
+
<ToolCard
|
|
50
|
+
card={tool}
|
|
51
|
+
index={index}
|
|
52
|
+
gridPadding={spacing.lg * 2}
|
|
53
|
+
onPress={() => tool.path && router.push(tool.path as never)}
|
|
54
|
+
/>
|
|
55
|
+
</DashboardReveal>
|
|
56
|
+
))}
|
|
57
|
+
</View>
|
|
58
|
+
|
|
59
|
+
<MoreButton
|
|
60
|
+
label={t('dashboard.see_all')}
|
|
61
|
+
delay={120 + tools.length * 60}
|
|
62
|
+
onPress={() => router.push('/settings' as never)}
|
|
63
|
+
/>
|
|
64
|
+
</ScrollView>
|
|
65
|
+
|
|
66
|
+
<StaffTabBar
|
|
67
|
+
tabs={tabs}
|
|
68
|
+
activeKey="home"
|
|
69
|
+
onSelect={(tab) => tab.path && router.push(tab.path as never)}
|
|
70
|
+
/>
|
|
71
|
+
</View>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asking for a reset link.
|
|
3
|
+
*
|
|
4
|
+
* The answer is deliberately the same whether the address exists or not: a
|
|
5
|
+
* screen that says "unknown address" is an account-enumeration oracle.
|
|
6
|
+
*/
|
|
7
|
+
import { useState } from 'react';
|
|
8
|
+
import { Text, TextInput } from 'react-native';
|
|
9
|
+
import { useTranslation } from 'react-i18next';
|
|
10
|
+
import { api } from '../services/session';
|
|
11
|
+
import { AnimatedPressable } from '../components/AnimatedPressable';
|
|
12
|
+
import { GlassPanel } from '../components/GlassPanel';
|
|
13
|
+
import { KeyboardScreen } from '../components/KeyboardScreen';
|
|
14
|
+
import GridBackground from '../components/GridBackground';
|
|
15
|
+
import { colors, fontWeights, spacing } from '../constants/theme';
|
|
16
|
+
|
|
17
|
+
export default function ForgotPassword() {
|
|
18
|
+
const { t } = useTranslation();
|
|
19
|
+
const [email, setEmail] = useState('');
|
|
20
|
+
const [sent, setSent] = useState(false);
|
|
21
|
+
|
|
22
|
+
const submit = async () => {
|
|
23
|
+
try {
|
|
24
|
+
await api.request('/auth/forgot-password', { method: 'POST', body: JSON.stringify({ email: email.trim() }) });
|
|
25
|
+
} catch {
|
|
26
|
+
/* same answer either way */
|
|
27
|
+
}
|
|
28
|
+
setSent(true);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<KeyboardScreen background={<GridBackground />} contentStyle={{ justifyContent: 'center', padding: spacing.lg }}>
|
|
33
|
+
<GlassPanel>
|
|
34
|
+
<Text style={{ color: colors.text, fontSize: 22, fontWeight: fontWeights.bold }}>{t('auth.forgot')}</Text>
|
|
35
|
+
<TextInput
|
|
36
|
+
style={{
|
|
37
|
+
color: colors.text,
|
|
38
|
+
backgroundColor: colors.surface,
|
|
39
|
+
borderColor: colors.border,
|
|
40
|
+
borderWidth: 1,
|
|
41
|
+
borderRadius: 14,
|
|
42
|
+
padding: spacing.md,
|
|
43
|
+
marginTop: spacing.md
|
|
44
|
+
}}
|
|
45
|
+
placeholder={t('auth.email')}
|
|
46
|
+
placeholderTextColor={colors.muted}
|
|
47
|
+
autoCapitalize="none"
|
|
48
|
+
keyboardType="email-address"
|
|
49
|
+
value={email}
|
|
50
|
+
onChangeText={setEmail}
|
|
51
|
+
/>
|
|
52
|
+
{sent && <Text style={{ color: colors.muted, marginTop: spacing.sm }}>{t('auth.reset_sent')}</Text>}
|
|
53
|
+
<AnimatedPressable
|
|
54
|
+
onPress={submit}
|
|
55
|
+
style={{ marginTop: spacing.lg, backgroundColor: colors.accent, borderRadius: 14, padding: spacing.md }}
|
|
56
|
+
>
|
|
57
|
+
<Text style={{ color: colors.onAccent, textAlign: 'center', fontWeight: fontWeights.semibold }}>
|
|
58
|
+
{t('auth.send_link')}
|
|
59
|
+
</Text>
|
|
60
|
+
</AnimatedPressable>
|
|
61
|
+
</GlassPanel>
|
|
62
|
+
</KeyboardScreen>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Text, View } from 'react-native';
|
|
2
|
+
import { useRouter } from 'expo-router';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
|
+
import { AnimatedPressable } from '../components/AnimatedPressable';
|
|
5
|
+
import { GlassPanel } from '../components/GlassPanel';
|
|
6
|
+
import GridBackground from '../components/GridBackground';
|
|
7
|
+
import { colors, fontWeights, spacing } from '../constants/theme';
|
|
8
|
+
|
|
9
|
+
export default function Home() {
|
|
10
|
+
const { t } = useTranslation();
|
|
11
|
+
const router = useRouter();
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<View style={{ flex: 1, backgroundColor: colors.background }}>
|
|
15
|
+
<GridBackground />
|
|
16
|
+
<View style={{ flex: 1, justifyContent: 'center', padding: spacing.lg }}>
|
|
17
|
+
<GlassPanel>
|
|
18
|
+
<Text style={{ color: colors.text, fontSize: 28, fontWeight: fontWeights.bold }}>{t('home.welcome')}</Text>
|
|
19
|
+
<Text style={{ color: colors.muted, marginTop: spacing.sm }}>{t('app.name')}</Text>
|
|
20
|
+
<AnimatedPressable
|
|
21
|
+
onPress={() => router.push('/login')}
|
|
22
|
+
style={{ marginTop: spacing.lg, backgroundColor: colors.accent, borderRadius: 14, padding: spacing.md }}
|
|
23
|
+
>
|
|
24
|
+
<Text style={{ color: colors.onAccent, textAlign: 'center', fontWeight: fontWeights.semibold }}>
|
|
25
|
+
{t('home.start')}
|
|
26
|
+
</Text>
|
|
27
|
+
</AnimatedPressable>
|
|
28
|
+
</GlassPanel>
|
|
29
|
+
</View>
|
|
30
|
+
</View>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The splash: it decides where to go, so the guard does not have to.
|
|
3
|
+
*
|
|
4
|
+
* While the session restores, nothing is decided. Redirecting on the transient
|
|
5
|
+
* state is what makes the sign-in screen flash at every cold start.
|
|
6
|
+
*/
|
|
7
|
+
import { useEffect } from 'react';
|
|
8
|
+
import { ActivityIndicator, View } from 'react-native';
|
|
9
|
+
import { useRouter } from 'expo-router';
|
|
10
|
+
import { useAuth } from '../context/AuthContext';
|
|
11
|
+
import { colors } from '../constants/theme';
|
|
12
|
+
|
|
13
|
+
export default function Splash() {
|
|
14
|
+
const { user, loading } = useAuth();
|
|
15
|
+
const router = useRouter();
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (loading) return;
|
|
19
|
+
router.replace(user ? '/dashboard' : '/home');
|
|
20
|
+
}, [user, loading, router]);
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<View style={{ flex: 1, backgroundColor: colors.background, alignItems: 'center', justifyContent: 'center' }}>
|
|
24
|
+
<ActivityIndicator color={colors.accent} />
|
|
25
|
+
</View>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Signing in.
|
|
3
|
+
*
|
|
4
|
+
* The password rules come from @astratra/client and are the SAME object the
|
|
5
|
+
* server validates against — a rule duplicated with a drift is a password
|
|
6
|
+
* accepted on screen and refused on submit.
|
|
7
|
+
*/
|
|
8
|
+
import { useState } from 'react';
|
|
9
|
+
import { ActivityIndicator, Pressable, Text, TextInput, View } from 'react-native';
|
|
10
|
+
import { useTranslation } from 'react-i18next';
|
|
11
|
+
import { useRouter } from 'expo-router';
|
|
12
|
+
import { createPasswordRules } from '@astratra/client';
|
|
13
|
+
import { useAuth } from '../context/AuthContext';
|
|
14
|
+
import { AnimatedPressable } from '../components/AnimatedPressable';
|
|
15
|
+
import { GlassPanel } from '../components/GlassPanel';
|
|
16
|
+
import { KeyboardScreen } from '../components/KeyboardScreen';
|
|
17
|
+
import GridBackground from '../components/GridBackground';
|
|
18
|
+
import PasswordEyeIcon from '../components/PasswordEyeIcon';
|
|
19
|
+
import { colors, fontWeights, spacing } from '../constants/theme';
|
|
20
|
+
|
|
21
|
+
const rules = createPasswordRules();
|
|
22
|
+
|
|
23
|
+
export default function Login() {
|
|
24
|
+
const { t } = useTranslation();
|
|
25
|
+
const { signIn } = useAuth();
|
|
26
|
+
const router = useRouter();
|
|
27
|
+
const [email, setEmail] = useState('');
|
|
28
|
+
const [password, setPassword] = useState('');
|
|
29
|
+
const [busy, setBusy] = useState(false);
|
|
30
|
+
const [revealed, setRevealed] = useState(false);
|
|
31
|
+
const [failed, setFailed] = useState(false);
|
|
32
|
+
|
|
33
|
+
const submit = async () => {
|
|
34
|
+
setFailed(false);
|
|
35
|
+
setBusy(true);
|
|
36
|
+
try {
|
|
37
|
+
await signIn(email.trim(), password);
|
|
38
|
+
router.replace('/dashboard');
|
|
39
|
+
} catch {
|
|
40
|
+
setFailed(true);
|
|
41
|
+
} finally {
|
|
42
|
+
setBusy(false);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const input = {
|
|
47
|
+
color: colors.text,
|
|
48
|
+
backgroundColor: colors.surface,
|
|
49
|
+
borderColor: colors.border,
|
|
50
|
+
borderWidth: 1,
|
|
51
|
+
borderRadius: 14,
|
|
52
|
+
padding: spacing.md,
|
|
53
|
+
marginTop: spacing.sm
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<KeyboardScreen background={<GridBackground />} contentStyle={{ justifyContent: 'center', padding: spacing.lg }}>
|
|
58
|
+
<GlassPanel>
|
|
59
|
+
<Text style={{ color: colors.text, fontSize: 24, fontWeight: fontWeights.bold }}>{t('auth.sign_in')}</Text>
|
|
60
|
+
|
|
61
|
+
<TextInput
|
|
62
|
+
style={input}
|
|
63
|
+
placeholder={t('auth.email')}
|
|
64
|
+
placeholderTextColor={colors.muted}
|
|
65
|
+
autoCapitalize="none"
|
|
66
|
+
keyboardType="email-address"
|
|
67
|
+
value={email}
|
|
68
|
+
onChangeText={setEmail}
|
|
69
|
+
/>
|
|
70
|
+
<View>
|
|
71
|
+
<TextInput
|
|
72
|
+
style={[input, { paddingRight: spacing.xl + spacing.md }]}
|
|
73
|
+
placeholder={t('auth.password')}
|
|
74
|
+
placeholderTextColor={colors.muted}
|
|
75
|
+
secureTextEntry={!revealed}
|
|
76
|
+
value={password}
|
|
77
|
+
onChangeText={setPassword}
|
|
78
|
+
/>
|
|
79
|
+
<Pressable
|
|
80
|
+
accessibilityRole="button"
|
|
81
|
+
accessibilityLabel={t(revealed ? 'auth.hide_password' : 'auth.show_password')}
|
|
82
|
+
onPress={() => setRevealed((shown) => !shown)}
|
|
83
|
+
/* A bigger touch area than the glyph: an 18px icon is below every
|
|
84
|
+
platform's minimum target and is missed as often as it is hit. */
|
|
85
|
+
hitSlop={12}
|
|
86
|
+
style={{ position: 'absolute', right: spacing.md, top: 0, bottom: 0, justifyContent: 'center' }}
|
|
87
|
+
>
|
|
88
|
+
<PasswordEyeIcon visible={revealed} />
|
|
89
|
+
</Pressable>
|
|
90
|
+
</View>
|
|
91
|
+
|
|
92
|
+
{/* Each condition separately, so the person sees WHICH one is missing
|
|
93
|
+
while typing — not a single line they discover they failed on submit. */}
|
|
94
|
+
{password.length > 0 && rules.check(password).map((rule) => (
|
|
95
|
+
<Text key={rule.key} style={{ color: rule.met ? colors.accent : colors.muted, marginTop: spacing.xs }}>
|
|
96
|
+
{rule.met ? '✓' : '·'} {t(`password.${rule.key}`)}
|
|
97
|
+
</Text>
|
|
98
|
+
))}
|
|
99
|
+
|
|
100
|
+
{failed && <Text style={{ color: colors.danger, marginTop: spacing.sm }}>{t('auth.failed')}</Text>}
|
|
101
|
+
|
|
102
|
+
<AnimatedPressable
|
|
103
|
+
onPress={submit}
|
|
104
|
+
disabled={busy}
|
|
105
|
+
style={{ marginTop: spacing.lg, backgroundColor: colors.accent, borderRadius: 14, padding: spacing.md }}
|
|
106
|
+
>
|
|
107
|
+
{busy
|
|
108
|
+
? <ActivityIndicator color={colors.onAccent} />
|
|
109
|
+
: <Text style={{ color: colors.onAccent, textAlign: 'center', fontWeight: fontWeights.semibold }}>{t('auth.sign_in')}</Text>}
|
|
110
|
+
</AnimatedPressable>
|
|
111
|
+
|
|
112
|
+
<AnimatedPressable onPress={() => router.push('/forgot-password')} style={{ marginTop: spacing.md }}>
|
|
113
|
+
<Text style={{ color: colors.muted, textAlign: 'center' }}>{t('auth.forgot')}</Text>
|
|
114
|
+
</AnimatedPressable>
|
|
115
|
+
</GlassPanel>
|
|
116
|
+
</KeyboardScreen>
|
|
117
|
+
);
|
|
118
|
+
}
|