Compare commits
45 Commits
develop/io
...
f44539bf63
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f44539bf63 | ||
![]() |
407f622f24 | ||
![]() |
7e2844dd74 | ||
![]() |
097918340c | ||
![]() |
3620837a6a | ||
![]() |
c83e8c1b6e | ||
![]() |
af15a6bce0 | ||
![]() |
d0215cf23f | ||
![]() |
e523f80123 | ||
![]() |
7f8f8824a7 | ||
![]() |
2aa96eec62 | ||
![]() |
ecab41abbf | ||
![]() |
5a1832ca89 | ||
![]() |
160c93b83d | ||
![]() |
d4fcc1dd8f | ||
![]() |
8e3d463f78 | ||
![]() |
fbf79b040f | ||
![]() |
e34782844e | ||
![]() |
ba8e9cca69 | ||
![]() |
cc9fe057c1 | ||
![]() |
cdd95faa89 | ||
![]() |
030fc1a808 | ||
![]() |
05c69481b5 | ||
![]() |
0fcc194860 | ||
![]() |
56f0f30ffb | ||
![]() |
0aefbfaeae | ||
![]() |
628c72190b | ||
![]() |
886a314df7 | ||
![]() |
efc2d31f7c | ||
![]() |
1938e95948 | ||
![]() |
8d37fba393 | ||
![]() |
af160edd42 | ||
![]() |
d880420a28 | ||
![]() |
5bebc1f40e | ||
![]() |
f4e5f94e17 | ||
![]() |
2d022cb613 | ||
![]() |
3560ea79fc | ||
![]() |
a441e3e52d | ||
![]() |
09ded06dd2 | ||
![]() |
7ecacd0692 | ||
![]() |
8a094afdd2 | ||
![]() |
64ca29cf60 | ||
![]() |
1aa0502edc | ||
![]() |
3e1f2e1057 | ||
![]() |
9be33f641f |
15
.crossnote/config.js
Normal file
15
.crossnote/config.js
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
({
|
||||||
|
katexConfig: {
|
||||||
|
"macros": {}
|
||||||
|
},
|
||||||
|
|
||||||
|
mathjaxConfig: {
|
||||||
|
"tex": {},
|
||||||
|
"options": {},
|
||||||
|
"loader": {}
|
||||||
|
},
|
||||||
|
|
||||||
|
mermaidConfig: {
|
||||||
|
"startOnLoad": false
|
||||||
|
},
|
||||||
|
})
|
19
.crossnote/head.html
Normal file
19
.crossnote/head.html
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<!-- The content below will be included at the end of the <head> element. -->
|
||||||
|
<script type="text/javascript">
|
||||||
|
const configureMermaidIconPacks = () => {
|
||||||
|
window['mermaid'].registerIconPacks([
|
||||||
|
{
|
||||||
|
name: 'logos',
|
||||||
|
loader: () => fetch('https://unpkg.com/@iconify-json/logos/icons.json').then((res) => res.json()),
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (document.readyState !== 'loading') {
|
||||||
|
configureMermaidIconPacks();
|
||||||
|
} else {
|
||||||
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
configureMermaidIconPacks();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
12
.crossnote/parser.js
Normal file
12
.crossnote/parser.js
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
({
|
||||||
|
// Please visit the URL below for more information:
|
||||||
|
// https://shd101wyy.github.io/markdown-preview-enhanced/#/extend-parser
|
||||||
|
|
||||||
|
onWillParseMarkdown: async function(markdown) {
|
||||||
|
return markdown;
|
||||||
|
},
|
||||||
|
|
||||||
|
onDidParseMarkdown: async function(html) {
|
||||||
|
return html;
|
||||||
|
},
|
||||||
|
})
|
8
.crossnote/style.less
Normal file
8
.crossnote/style.less
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
/* Please visit the URL below for more information: */
|
||||||
|
/* https://shd101wyy.github.io/markdown-preview-enhanced/#/customize-css */
|
||||||
|
|
||||||
|
.markdown-preview.markdown-preview {
|
||||||
|
// modify your style here
|
||||||
|
// eg: background-color: blue;
|
||||||
|
}
|
6
.gitignore
vendored
6
.gitignore
vendored
@@ -1,3 +1,6 @@
|
|||||||
|
# api_ts
|
||||||
|
dist
|
||||||
|
|
||||||
.next
|
.next
|
||||||
node_modules
|
node_modules
|
||||||
005_references/
|
005_references/
|
||||||
@@ -7,7 +10,8 @@ _del
|
|||||||
*.bak
|
*.bak
|
||||||
*.log
|
*.log
|
||||||
*.del
|
*.del
|
||||||
**/_del
|
**/*del
|
||||||
|
**/*old
|
||||||
|
|
||||||
**/volumes/**
|
**/volumes/**
|
||||||
006_lab
|
006_lab
|
||||||
|
9
.vscode/extensions.json
vendored
9
.vscode/extensions.json
vendored
@@ -1,12 +1,15 @@
|
|||||||
{
|
{
|
||||||
"recommendations": [
|
"recommendations": [
|
||||||
"aflalo.dbml-formatter",
|
|
||||||
"bierner.markdown-mermaid",
|
|
||||||
"christian-kohler.path-intellisense",
|
"christian-kohler.path-intellisense",
|
||||||
"esbenp.prettier-vscode",
|
"esbenp.prettier-vscode",
|
||||||
"humao.rest-client",
|
"humao.rest-client",
|
||||||
|
//
|
||||||
"matt-meyers.vscode-dbml",
|
"matt-meyers.vscode-dbml",
|
||||||
|
"aflalo.dbml-formatter",
|
||||||
"nicolas-liger.dbml-viewer",
|
"nicolas-liger.dbml-viewer",
|
||||||
"yzhang.markdown-all-in-one"
|
//
|
||||||
|
"bierner.markdown-mermaid",
|
||||||
|
"yzhang.markdown-all-in-one",
|
||||||
|
"shd101wyy.markdown-preview-enhanced"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
6
.vscode/settings.json
vendored
6
.vscode/settings.json
vendored
@@ -15,7 +15,9 @@
|
|||||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||||
},
|
},
|
||||||
"workbench.iconTheme": "material-icon-theme",
|
"workbench.iconTheme": "material-icon-theme",
|
||||||
"workbench.colorTheme": "Default Dark Modern",
|
"workbench.colorTheme": "Mermaid Dark",
|
||||||
"editor.formatOnSave": true,
|
"editor.formatOnSave": true,
|
||||||
"git.ignoreLimitWarning": true
|
"git.ignoreLimitWarning": true,
|
||||||
|
//
|
||||||
|
"markdown.styles": ["https://use.fontawesome.com/releases/v5.7.1/css/all.css"]
|
||||||
}
|
}
|
||||||
|
@@ -28,5 +28,10 @@
|
|||||||
- `006_lab` my test (POC) of this project
|
- `006_lab` my test (POC) of this project
|
||||||
- `README.md` Readme of this project
|
- `README.md` Readme of this project
|
||||||
- `TODO.md` todo list of this project
|
- `TODO.md` todo list of this project
|
||||||
|
- `001_documentation/Requirements/REQ0019/index.md` describes updated system architecture
|
||||||
|
|
||||||
- if the directory contains `_GUIDELINES.md`, please read it before operation
|
- if the directory contains `_GUIDELINES.md`, please read it before operation
|
||||||
|
|
||||||
|
## Abbreviations
|
||||||
|
|
||||||
|
T.B.A.
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
import { faker } from "@faker-js/faker";
|
import { faker } from '@faker-js/faker';
|
||||||
|
|
||||||
const getId = (id) => id.padStart(15, "0");
|
const getId = (id) => id.padStart(15, '0');
|
||||||
|
|
||||||
const row_array = Array.from({ length: 10 }, (_, i) => [
|
const row_array = Array.from({ length: 10 }, (_, i) => [
|
||||||
getId(String(i + 1)),
|
getId(String(i + 1)),
|
||||||
faker.person.firstName(),
|
faker.person.firstName(),
|
||||||
"",
|
'',
|
||||||
faker.internet.email(),
|
faker.internet.email(),
|
||||||
faker.phone.number(),
|
faker.phone.number(),
|
||||||
faker.company.name(),
|
faker.company.name(),
|
||||||
@@ -19,13 +19,11 @@ const row_array = Array.from({ length: 10 }, (_, i) => [
|
|||||||
},
|
},
|
||||||
Math.floor(Math.random() * (100 - 0 + 1)) + 0,
|
Math.floor(Math.random() * (100 - 0 + 1)) + 0,
|
||||||
faker.location.timeZone(),
|
faker.location.timeZone(),
|
||||||
["en", "de", "es", "fr", "ja", "ko", "zh-CN"].sort(
|
['en', 'de', 'es', 'fr', 'ja', 'ko', 'zh-CN'].sort(() => Math.random() - 0.5)[0],
|
||||||
() => Math.random() - 0.5
|
|
||||||
)[0],
|
|
||||||
faker.finance.currencyCode(),
|
faker.finance.currencyCode(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
import fs from "fs";
|
import fs from 'fs';
|
||||||
const filePath = "output.json";
|
const filePath = 'output.json';
|
||||||
fs.writeFileSync(filePath, JSON.stringify(row_array, null, 2));
|
fs.writeFileSync(filePath, JSON.stringify(row_array, null, 2));
|
||||||
console.log(`Wrote ${row_array.length} records to ${filePath}`);
|
console.log(`Wrote ${row_array.length} records to ${filePath}`);
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
// Generated at: 2025-05-12T06:02:53.613Z
|
// Generated at: 2025-05-13T05:24:33.962Z
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -206,9 +206,9 @@ Table QuizLPCategories {
|
|||||||
cat_image file
|
cat_image file
|
||||||
pos integer
|
pos integer
|
||||||
init_answer text
|
init_answer text
|
||||||
|
visible text
|
||||||
created datetime
|
created datetime
|
||||||
updated datetime
|
updated datetime
|
||||||
visible text
|
|
||||||
slug text
|
slug text
|
||||||
remarks text
|
remarks text
|
||||||
description text
|
description text
|
||||||
@@ -223,8 +223,6 @@ Table QuizLPQuestions {
|
|||||||
word text
|
word text
|
||||||
sound file
|
sound file
|
||||||
cat_id integer [ref: > QuizLPCategories.id] // relation3870140739
|
cat_id integer [ref: > QuizLPCategories.id] // relation3870140739
|
||||||
created datetime
|
|
||||||
updated datetime
|
|
||||||
cat_name text
|
cat_name text
|
||||||
cat_image file
|
cat_image file
|
||||||
pos integer
|
pos integer
|
||||||
@@ -233,6 +231,8 @@ Table QuizLPQuestions {
|
|||||||
slug text
|
slug text
|
||||||
remarks text
|
remarks text
|
||||||
description text
|
description text
|
||||||
|
created datetime
|
||||||
|
updated datetime
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -258,9 +258,9 @@ Table QuizMFCategories {
|
|||||||
cat_image file
|
cat_image file
|
||||||
pos integer
|
pos integer
|
||||||
init_answer text
|
init_answer text
|
||||||
|
visible text
|
||||||
created datetime
|
created datetime
|
||||||
updated datetime
|
updated datetime
|
||||||
visible text
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -341,17 +341,23 @@ Table Teachers {
|
|||||||
// collection type: base
|
// collection type: base
|
||||||
Table UserMetas {
|
Table UserMetas {
|
||||||
id text [pk, not null]
|
id text [pk, not null]
|
||||||
helloworld text
|
address text
|
||||||
meta text
|
meta text
|
||||||
user_id integer [ref: > users.id] // relation2809058197
|
user_id integer [ref: > users.id] // relation2809058197
|
||||||
|
state text
|
||||||
created datetime
|
created datetime
|
||||||
updated datetime
|
updated datetime
|
||||||
status text
|
|
||||||
avatar file
|
avatar file
|
||||||
role text
|
role text
|
||||||
name text
|
name text
|
||||||
email text
|
email text
|
||||||
phone text
|
phone text
|
||||||
|
company text
|
||||||
|
taxId text
|
||||||
|
timezone text
|
||||||
|
language text
|
||||||
|
currency text
|
||||||
|
billingAddress integer [ref: > billingAddress.id] // relation2115670734
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@@ -1750,6 +1750,20 @@
|
|||||||
"system": false,
|
"system": false,
|
||||||
"type": "json"
|
"type": "json"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"autogeneratePattern": "",
|
||||||
|
"hidden": false,
|
||||||
|
"id": "text2058414169",
|
||||||
|
"max": 0,
|
||||||
|
"min": 0,
|
||||||
|
"name": "visible",
|
||||||
|
"pattern": "",
|
||||||
|
"presentable": false,
|
||||||
|
"primaryKey": false,
|
||||||
|
"required": false,
|
||||||
|
"system": false,
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"hidden": false,
|
"hidden": false,
|
||||||
"id": "autodate2990389176",
|
"id": "autodate2990389176",
|
||||||
@@ -1770,20 +1784,6 @@
|
|||||||
"system": false,
|
"system": false,
|
||||||
"type": "autodate"
|
"type": "autodate"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"autogeneratePattern": "",
|
|
||||||
"hidden": false,
|
|
||||||
"id": "text2058414169",
|
|
||||||
"max": 0,
|
|
||||||
"min": 0,
|
|
||||||
"name": "visible",
|
|
||||||
"pattern": "",
|
|
||||||
"presentable": false,
|
|
||||||
"primaryKey": false,
|
|
||||||
"required": false,
|
|
||||||
"system": false,
|
|
||||||
"type": "text"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"autogeneratePattern": "",
|
"autogeneratePattern": "",
|
||||||
"hidden": false,
|
"hidden": false,
|
||||||
@@ -1892,26 +1892,6 @@
|
|||||||
"system": false,
|
"system": false,
|
||||||
"type": "relation"
|
"type": "relation"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"hidden": false,
|
|
||||||
"id": "autodate2990389176",
|
|
||||||
"name": "created",
|
|
||||||
"onCreate": true,
|
|
||||||
"onUpdate": false,
|
|
||||||
"presentable": false,
|
|
||||||
"system": false,
|
|
||||||
"type": "autodate"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"hidden": false,
|
|
||||||
"id": "autodate3332085495",
|
|
||||||
"name": "updated",
|
|
||||||
"onCreate": true,
|
|
||||||
"onUpdate": true,
|
|
||||||
"presentable": false,
|
|
||||||
"system": false,
|
|
||||||
"type": "autodate"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"autogeneratePattern": "",
|
"autogeneratePattern": "",
|
||||||
"hidden": false,
|
"hidden": false,
|
||||||
@@ -2014,6 +1994,26 @@
|
|||||||
"required": false,
|
"required": false,
|
||||||
"system": false,
|
"system": false,
|
||||||
"type": "editor"
|
"type": "editor"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hidden": false,
|
||||||
|
"id": "autodate2990389176",
|
||||||
|
"name": "created",
|
||||||
|
"onCreate": true,
|
||||||
|
"onUpdate": false,
|
||||||
|
"presentable": false,
|
||||||
|
"system": false,
|
||||||
|
"type": "autodate"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hidden": false,
|
||||||
|
"id": "autodate3332085495",
|
||||||
|
"name": "updated",
|
||||||
|
"onCreate": true,
|
||||||
|
"onUpdate": true,
|
||||||
|
"presentable": false,
|
||||||
|
"system": false,
|
||||||
|
"type": "autodate"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"indexes": [],
|
"indexes": [],
|
||||||
@@ -2182,6 +2182,20 @@
|
|||||||
"system": false,
|
"system": false,
|
||||||
"type": "json"
|
"type": "json"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"autogeneratePattern": "",
|
||||||
|
"hidden": false,
|
||||||
|
"id": "text2058414169",
|
||||||
|
"max": 0,
|
||||||
|
"min": 0,
|
||||||
|
"name": "visible",
|
||||||
|
"pattern": "",
|
||||||
|
"presentable": false,
|
||||||
|
"primaryKey": false,
|
||||||
|
"required": false,
|
||||||
|
"system": false,
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"hidden": false,
|
"hidden": false,
|
||||||
"id": "autodate2990389176",
|
"id": "autodate2990389176",
|
||||||
@@ -2201,20 +2215,6 @@
|
|||||||
"presentable": false,
|
"presentable": false,
|
||||||
"system": false,
|
"system": false,
|
||||||
"type": "autodate"
|
"type": "autodate"
|
||||||
},
|
|
||||||
{
|
|
||||||
"autogeneratePattern": "",
|
|
||||||
"hidden": false,
|
|
||||||
"id": "text2058414169",
|
|
||||||
"max": 0,
|
|
||||||
"min": 0,
|
|
||||||
"name": "visible",
|
|
||||||
"pattern": "",
|
|
||||||
"presentable": false,
|
|
||||||
"primaryKey": false,
|
|
||||||
"required": false,
|
|
||||||
"system": false,
|
|
||||||
"type": "text"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"indexes": [],
|
"indexes": [],
|
||||||
@@ -2870,7 +2870,7 @@
|
|||||||
"id": "text4192936109",
|
"id": "text4192936109",
|
||||||
"max": 0,
|
"max": 0,
|
||||||
"min": 0,
|
"min": 0,
|
||||||
"name": "helloworld",
|
"name": "address",
|
||||||
"pattern": "",
|
"pattern": "",
|
||||||
"presentable": false,
|
"presentable": false,
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
@@ -2901,6 +2901,20 @@
|
|||||||
"system": false,
|
"system": false,
|
||||||
"type": "relation"
|
"type": "relation"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"autogeneratePattern": "",
|
||||||
|
"hidden": false,
|
||||||
|
"id": "text2744374011",
|
||||||
|
"max": 0,
|
||||||
|
"min": 0,
|
||||||
|
"name": "state",
|
||||||
|
"pattern": "",
|
||||||
|
"presentable": false,
|
||||||
|
"primaryKey": false,
|
||||||
|
"required": false,
|
||||||
|
"system": false,
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"hidden": false,
|
"hidden": false,
|
||||||
"id": "autodate2990389176",
|
"id": "autodate2990389176",
|
||||||
@@ -2921,20 +2935,6 @@
|
|||||||
"system": false,
|
"system": false,
|
||||||
"type": "autodate"
|
"type": "autodate"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"autogeneratePattern": "",
|
|
||||||
"hidden": false,
|
|
||||||
"id": "text2744374011",
|
|
||||||
"max": 0,
|
|
||||||
"min": 0,
|
|
||||||
"name": "status",
|
|
||||||
"pattern": "",
|
|
||||||
"presentable": false,
|
|
||||||
"primaryKey": false,
|
|
||||||
"required": false,
|
|
||||||
"system": false,
|
|
||||||
"type": "text"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"hidden": false,
|
"hidden": false,
|
||||||
"id": "file376926767",
|
"id": "file376926767",
|
||||||
@@ -3001,6 +3001,89 @@
|
|||||||
"required": false,
|
"required": false,
|
||||||
"system": false,
|
"system": false,
|
||||||
"type": "text"
|
"type": "text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"autogeneratePattern": "",
|
||||||
|
"hidden": false,
|
||||||
|
"id": "text1337919823",
|
||||||
|
"max": 0,
|
||||||
|
"min": 0,
|
||||||
|
"name": "company",
|
||||||
|
"pattern": "",
|
||||||
|
"presentable": false,
|
||||||
|
"primaryKey": false,
|
||||||
|
"required": false,
|
||||||
|
"system": false,
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"autogeneratePattern": "",
|
||||||
|
"hidden": false,
|
||||||
|
"id": "text2020362641",
|
||||||
|
"max": 0,
|
||||||
|
"min": 0,
|
||||||
|
"name": "taxId",
|
||||||
|
"pattern": "",
|
||||||
|
"presentable": false,
|
||||||
|
"primaryKey": false,
|
||||||
|
"required": false,
|
||||||
|
"system": false,
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"autogeneratePattern": "",
|
||||||
|
"hidden": false,
|
||||||
|
"id": "text922858135",
|
||||||
|
"max": 0,
|
||||||
|
"min": 0,
|
||||||
|
"name": "timezone",
|
||||||
|
"pattern": "",
|
||||||
|
"presentable": false,
|
||||||
|
"primaryKey": false,
|
||||||
|
"required": false,
|
||||||
|
"system": false,
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"autogeneratePattern": "",
|
||||||
|
"hidden": false,
|
||||||
|
"id": "text3571151285",
|
||||||
|
"max": 0,
|
||||||
|
"min": 0,
|
||||||
|
"name": "language",
|
||||||
|
"pattern": "",
|
||||||
|
"presentable": false,
|
||||||
|
"primaryKey": false,
|
||||||
|
"required": false,
|
||||||
|
"system": false,
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"autogeneratePattern": "",
|
||||||
|
"hidden": false,
|
||||||
|
"id": "text1767278655",
|
||||||
|
"max": 0,
|
||||||
|
"min": 0,
|
||||||
|
"name": "currency",
|
||||||
|
"pattern": "",
|
||||||
|
"presentable": false,
|
||||||
|
"primaryKey": false,
|
||||||
|
"required": false,
|
||||||
|
"system": false,
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cascadeDelete": false,
|
||||||
|
"collectionId": "pbc_1509025625",
|
||||||
|
"hidden": false,
|
||||||
|
"id": "relation2115670734",
|
||||||
|
"maxSelect": 999,
|
||||||
|
"minSelect": 0,
|
||||||
|
"name": "billingAddress",
|
||||||
|
"presentable": false,
|
||||||
|
"required": false,
|
||||||
|
"system": false,
|
||||||
|
"type": "relation"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"indexes": [],
|
"indexes": [],
|
||||||
@@ -3604,11 +3687,11 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "pbc_1509025625",
|
"id": "pbc_1509025625",
|
||||||
"listRule": null,
|
"listRule": "",
|
||||||
"viewRule": null,
|
"viewRule": "",
|
||||||
"createRule": null,
|
"createRule": "",
|
||||||
"updateRule": null,
|
"updateRule": "",
|
||||||
"deleteRule": null,
|
"deleteRule": "",
|
||||||
"name": "billingAddress",
|
"name": "billingAddress",
|
||||||
"type": "base",
|
"type": "base",
|
||||||
"fields": [
|
"fields": [
|
||||||
@@ -3798,11 +3881,11 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "pbc_2109205374",
|
"id": "pbc_2109205374",
|
||||||
"listRule": null,
|
"listRule": "",
|
||||||
"viewRule": null,
|
"viewRule": "",
|
||||||
"createRule": null,
|
"createRule": "",
|
||||||
"updateRule": null,
|
"updateRule": "",
|
||||||
"deleteRule": null,
|
"deleteRule": "",
|
||||||
"name": "t1",
|
"name": "t1",
|
||||||
"type": "base",
|
"type": "base",
|
||||||
"fields": [
|
"fields": [
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
tags: cms, login-flow
|
tags: cms, login-flow
|
||||||
---
|
---
|
||||||
|
|
||||||
# login flow
|
# CMS login flow
|
||||||
|
|
||||||
## description
|
## description
|
||||||
|
|
||||||
|
43
001_documentation/Requirements/REQ0019/index.md
Normal file
43
001_documentation/Requirements/REQ0019/index.md
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
---
|
||||||
|
tags: architecture,mobile, cms, db
|
||||||
|
---
|
||||||
|
|
||||||
|
# System architecture
|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
it should have a family photo of used framework
|
||||||
|
|
||||||
|
## Diagram
|
||||||
|
|
||||||
|
```mermaid {align="center"}
|
||||||
|
|
||||||
|
architecture-beta
|
||||||
|
group running_config(logos:aws-opsworks)[running_config]
|
||||||
|
service db(database)[pocketbase] in running_config
|
||||||
|
|
||||||
|
service tra1(internet)[incoming traffic 3000] in running_config
|
||||||
|
service cms(logos:nextjs)[next app] in running_config
|
||||||
|
|
||||||
|
service tra2(internet)[incoming traffic 5173] in running_config
|
||||||
|
service ionic(logos:ionic)[ionic app] in running_config
|
||||||
|
|
||||||
|
tra1:R --> L:cms
|
||||||
|
cms:R --> L:db
|
||||||
|
|
||||||
|
tra2:R --> L:ionic
|
||||||
|
ionic:R --> B:db
|
||||||
|
|
||||||
|
%% group planning(logos:aws-lambda)[planning]
|
||||||
|
%% service api_ts(logos:aws-lambda)[api_ts] in planning
|
||||||
|
%% service pg_db(logos:postgresql)[pg_db] in planning
|
||||||
|
%% ui:R --> L:api_ts
|
||||||
|
%% ionic:R --> L:api_ts
|
||||||
|
%% api_ts:B --> T:pg_db
|
||||||
|
|
||||||
|
%% service task_server(logos:aws-lambda)[task_server] in planning
|
||||||
|
%% api_ts:R --> L:task_server
|
||||||
|
%% service marketing(logos:wordpress-icon)[marketing] in planning
|
||||||
|
|
||||||
|
|
||||||
|
```
|
37
001_documentation/Requirements/REQ0020/index.md
Normal file
37
001_documentation/Requirements/REQ0020/index.md
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
---
|
||||||
|
tags: mobile, login-flow
|
||||||
|
---
|
||||||
|
|
||||||
|
# Mobile login flow
|
||||||
|
|
||||||
|
## description
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
graph TD;
|
||||||
|
Start-->A;
|
||||||
|
A-->B;
|
||||||
|
B-->C;
|
||||||
|
B-->D;
|
||||||
|
D-->E;
|
||||||
|
E-->F;
|
||||||
|
C-->G;
|
||||||
|
G-->A
|
||||||
|
|
||||||
|
F-->End;
|
||||||
|
|
||||||
|
A[greeting, asking username and password]
|
||||||
|
B[check if username and password is valid]
|
||||||
|
C[pasword failed]
|
||||||
|
D[pasword ok]
|
||||||
|
E[login success]
|
||||||
|
F[redirect to '/dashboard']
|
||||||
|
|
||||||
|
G[prompt user wrong username and password]
|
||||||
|
|
||||||
|
Start((start));
|
||||||
|
End((end))
|
||||||
|
```
|
||||||
|
|
||||||
|
### relations
|
||||||
|
|
||||||
|
[REQ0016](../REQ0016/index.md)
|
@@ -17,5 +17,8 @@
|
|||||||
- [REQ0013: cms dashboard](./REQ0013/index.md)
|
- [REQ0013: cms dashboard](./REQ0013/index.md)
|
||||||
- [REQ0014: mobile client](./REQ0014/index.md)
|
- [REQ0014: mobile client](./REQ0014/index.md)
|
||||||
- [REQ0015: pocketbase json schema to dbml converter](./REQ0015/index.md)
|
- [REQ0015: pocketbase json schema to dbml converter](./REQ0015/index.md)
|
||||||
- [REQ0016: login flow](./REQ0016/index.md)
|
- [REQ0016: CMS login flow](./REQ0016/index.md)
|
||||||
- [REQ0017: lesson page documentation](./REQ0017/index.md)
|
- [REQ0017: lesson page documentation](./REQ0017/index.md)
|
||||||
|
- [REQ0018: family photo of frameworks](./REQ0018/index.md)
|
||||||
|
- [REQ0019: System architecture](./REQ0019/index.md)
|
||||||
|
- [REQ0020: Mobile login flow](./REQ0020/index.md)
|
||||||
|
@@ -28,7 +28,10 @@ const config = {
|
|||||||
'',
|
'',
|
||||||
'^[./]',
|
'^[./]',
|
||||||
],
|
],
|
||||||
plugins: ['@ianvs/prettier-plugin-sort-imports'],
|
plugins: [
|
||||||
|
'@ianvs/prettier-plugin-sort-imports',
|
||||||
|
//
|
||||||
|
],
|
||||||
overrides: [
|
overrides: [
|
||||||
{
|
{
|
||||||
files: ['*.tsx'],
|
files: ['*.tsx'],
|
||||||
|
@@ -1,19 +1,25 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
// src/app/dashboard/students/create/page.tsx
|
||||||
|
// PURPOSE
|
||||||
|
// T.B.A.
|
||||||
|
//
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import type { Metadata } from 'next';
|
|
||||||
import RouterLink from 'next/link';
|
import RouterLink from 'next/link';
|
||||||
import Box from '@mui/material/Box';
|
import Box from '@mui/material/Box';
|
||||||
import Link from '@mui/material/Link';
|
import Link from '@mui/material/Link';
|
||||||
import Stack from '@mui/material/Stack';
|
import Stack from '@mui/material/Stack';
|
||||||
import Typography from '@mui/material/Typography';
|
import Typography from '@mui/material/Typography';
|
||||||
import { ArrowLeft as ArrowLeftIcon } from '@phosphor-icons/react/dist/ssr/ArrowLeft';
|
import { ArrowLeft as ArrowLeftIcon } from '@phosphor-icons/react/dist/ssr/ArrowLeft';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import { config } from '@/config';
|
import { config } from '@/config';
|
||||||
import { paths } from '@/paths';
|
import { paths } from '@/paths';
|
||||||
import { CustomerCreateForm } from '@/components/dashboard/student/student-create-form';
|
import { StudentCreateForm } from '@/components/dashboard/student/student-create-form';
|
||||||
|
|
||||||
export const metadata = { title: `Create | Customers | Dashboard | ${config.site.name}` } satisfies Metadata;
|
|
||||||
|
|
||||||
export default function Page(): React.JSX.Element {
|
export default function Page(): React.JSX.Element {
|
||||||
|
const { t } = useTranslation(['students']);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
@@ -29,19 +35,22 @@ export default function Page(): React.JSX.Element {
|
|||||||
<Link
|
<Link
|
||||||
color="text.primary"
|
color="text.primary"
|
||||||
component={RouterLink}
|
component={RouterLink}
|
||||||
href={paths.dashboard.customers.list}
|
href={paths.dashboard.students.list}
|
||||||
sx={{ alignItems: 'center', display: 'inline-flex', gap: 1 }}
|
sx={{ alignItems: 'center', display: 'inline-flex', gap: 1 }}
|
||||||
variant="subtitle2"
|
variant="subtitle2"
|
||||||
>
|
>
|
||||||
<ArrowLeftIcon fontSize="var(--icon-fontSize-md)" />
|
<ArrowLeftIcon fontSize="var(--icon-fontSize-md)" />
|
||||||
Customers
|
{t('students')}
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<Typography variant="h4">Create customer</Typography>
|
<Typography variant="h4">
|
||||||
|
{t('create-student')}
|
||||||
|
{/* */}
|
||||||
|
</Typography>
|
||||||
</div>
|
</div>
|
||||||
</Stack>
|
</Stack>
|
||||||
<CustomerCreateForm />
|
<StudentCreateForm />
|
||||||
</Stack>
|
</Stack>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
|
@@ -1 +0,0 @@
|
|||||||
this `tsx` file is clone from elsewhere, please understand, modify and update the content of `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/app/dashboard/students/edit/[customerId]/page.tsx.draft` to handle `Student` record thanks, modify comments/variables/paths/functions name please
|
|
@@ -0,0 +1,6 @@
|
|||||||
|
this `tsx` file is clone from elsewhere,
|
||||||
|
please understand, modify and update the content of
|
||||||
|
`/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/app/dashboard/students/edit/[customerId]/page.tsx.draft`
|
||||||
|
to handle `Student` record thanks,
|
||||||
|
|
||||||
|
modify comments/variables/paths/functions name please
|
@@ -1,6 +1,9 @@
|
|||||||
'use client';
|
'use client';
|
||||||
// src/app/dashboard/students/edit/[customerId]/page.tsx
|
|
||||||
|
|
||||||
|
// src/app/dashboard/students/edit/[id]/page.tsx
|
||||||
|
// PURPOSE
|
||||||
|
// T.B.A.
|
||||||
|
//
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import RouterLink from 'next/link';
|
import RouterLink from 'next/link';
|
||||||
import Box from '@mui/material/Box';
|
import Box from '@mui/material/Box';
|
||||||
@@ -11,7 +14,8 @@ import { ArrowLeft as ArrowLeftIcon } from '@phosphor-icons/react/dist/ssr/Arrow
|
|||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import { paths } from '@/paths';
|
import { paths } from '@/paths';
|
||||||
import { CrCategoryEditForm } from '@/components/dashboard/cr/categories/cr-category-edit-form';
|
// TODO: remove me
|
||||||
|
// import { CrCategoryEditForm } from '@/components/dashboard/cr/categories/cr-category-edit-form';
|
||||||
import { StudentEditForm } from '@/components/dashboard/student/student-edit-form';
|
import { StudentEditForm } from '@/components/dashboard/student/student-edit-form';
|
||||||
|
|
||||||
export default function Page(): React.JSX.Element {
|
export default function Page(): React.JSX.Element {
|
@@ -1,4 +1,9 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
// src/app/dashboard/teachers/create/page.tsx
|
||||||
|
// PURPOSE
|
||||||
|
// T.B.A.
|
||||||
|
//
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import RouterLink from 'next/link';
|
import RouterLink from 'next/link';
|
||||||
import Box from '@mui/material/Box';
|
import Box from '@mui/material/Box';
|
||||||
@@ -6,12 +11,15 @@ import Link from '@mui/material/Link';
|
|||||||
import Stack from '@mui/material/Stack';
|
import Stack from '@mui/material/Stack';
|
||||||
import Typography from '@mui/material/Typography';
|
import Typography from '@mui/material/Typography';
|
||||||
import { ArrowLeft as ArrowLeftIcon } from '@phosphor-icons/react/dist/ssr/ArrowLeft';
|
import { ArrowLeft as ArrowLeftIcon } from '@phosphor-icons/react/dist/ssr/ArrowLeft';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import { config } from '@/config';
|
import { config } from '@/config';
|
||||||
import { paths } from '@/paths';
|
import { paths } from '@/paths';
|
||||||
import { TeacherCreateForm } from '@/components/dashboard/teacher/teacher-create-form';
|
import { TeacherCreateForm } from '@/components/dashboard/teacher/teacher-create-form';
|
||||||
|
|
||||||
export default function Page(): React.JSX.Element {
|
export default function Page(): React.JSX.Element {
|
||||||
|
const { t } = useTranslation(['teachers']);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
@@ -32,11 +40,14 @@ export default function Page(): React.JSX.Element {
|
|||||||
variant="subtitle2"
|
variant="subtitle2"
|
||||||
>
|
>
|
||||||
<ArrowLeftIcon fontSize="var(--icon-fontSize-md)" />
|
<ArrowLeftIcon fontSize="var(--icon-fontSize-md)" />
|
||||||
Teachers
|
{t('teachers')}
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<Typography variant="h4">Create teacher</Typography>
|
<Typography variant="h4">
|
||||||
|
{t('create-teacher')}
|
||||||
|
{/* */}
|
||||||
|
</Typography>
|
||||||
</div>
|
</div>
|
||||||
</Stack>
|
</Stack>
|
||||||
<TeacherCreateForm />
|
<TeacherCreateForm />
|
||||||
|
@@ -1,5 +1,9 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
// src/app/dashboard/teachers/edit/[id]/page.tsx
|
||||||
|
// PURPOSE
|
||||||
|
// T.B.A.
|
||||||
|
//
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import RouterLink from 'next/link';
|
import RouterLink from 'next/link';
|
||||||
import Box from '@mui/material/Box';
|
import Box from '@mui/material/Box';
|
||||||
@@ -10,7 +14,8 @@ import { ArrowLeft as ArrowLeftIcon } from '@phosphor-icons/react/dist/ssr/Arrow
|
|||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import { paths } from '@/paths';
|
import { paths } from '@/paths';
|
||||||
import { CrCategoryEditForm } from '@/components/dashboard/cr/categories/cr-category-edit-form';
|
// TODO: remove me
|
||||||
|
// import { CrCategoryEditForm } from '@/components/dashboard/cr/categories/cr-category-edit-form';
|
||||||
import { TeacherEditForm } from '@/components/dashboard/teacher/teacher-edit-form';
|
import { TeacherEditForm } from '@/components/dashboard/teacher/teacher-edit-form';
|
||||||
|
|
||||||
export default function Page(): React.JSX.Element {
|
export default function Page(): React.JSX.Element {
|
||||||
|
@@ -1,216 +0,0 @@
|
|||||||
// src/app/dashboard/teachers/list/page.tsx
|
|
||||||
'use client';
|
|
||||||
|
|
||||||
// RULES:
|
|
||||||
// contains list page for teachers (Teachers)
|
|
||||||
//
|
|
||||||
import * as React from 'react';
|
|
||||||
import { useRouter } from 'next/navigation';
|
|
||||||
import { COL_USER_METAS } from '@/constants';
|
|
||||||
import { LoadingButton } from '@mui/lab';
|
|
||||||
import Box from '@mui/material/Box';
|
|
||||||
import Card from '@mui/material/Card';
|
|
||||||
import Divider from '@mui/material/Divider';
|
|
||||||
import Stack from '@mui/material/Stack';
|
|
||||||
import Typography from '@mui/material/Typography';
|
|
||||||
import { Plus as PlusIcon } from '@phosphor-icons/react/dist/ssr/Plus';
|
|
||||||
import type { ListResult, RecordModel } from 'pocketbase';
|
|
||||||
|
|
||||||
import { TeachersFilters } from '@/components/dashboard/teacher/teachers-filters';
|
|
||||||
import { TeachersPagination } from '@/components/dashboard/teacher/teachers-pagination';
|
|
||||||
import { TeachersSelectionProvider } from '@/components/dashboard/teacher/teachers-selection-context';
|
|
||||||
import { TeachersTable } from '@/components/dashboard/teacher/teachers-table';
|
|
||||||
import type { Teacher } from '@/components/dashboard/teacher/type.d';
|
|
||||||
import { useTranslation } from 'react-i18next';
|
|
||||||
|
|
||||||
import { paths } from '@/paths';
|
|
||||||
import isDevelopment from '@/lib/check-is-development';
|
|
||||||
import { logger } from '@/lib/default-logger';
|
|
||||||
import { pb } from '@/lib/pb';
|
|
||||||
import ErrorDisplay from '@/components/dashboard/error';
|
|
||||||
import { defaultTeacher } from '@/components/dashboard/teacher/_constants';
|
|
||||||
import FormLoading from '@/components/loading';
|
|
||||||
|
|
||||||
export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
|
||||||
const { t } = useTranslation(['teachers']);
|
|
||||||
const router = useRouter();
|
|
||||||
|
|
||||||
const { email, phone, sortDir, status } = searchParams;
|
|
||||||
|
|
||||||
const [teacherData, setTeacherData] = React.useState<Teacher[]>([]);
|
|
||||||
|
|
||||||
const [isLoadingAddPage, setIsLoadingAddPage] = React.useState<boolean>(false);
|
|
||||||
const [showLoading, setShowLoading] = React.useState<boolean>(true);
|
|
||||||
const [showError, setShowError] = React.useState({ show: false, detail: '' });
|
|
||||||
//
|
|
||||||
const [rowsPerPage, setRowsPerPage] = React.useState<number>(5);
|
|
||||||
//
|
|
||||||
const [f, setF] = React.useState<Teacher[]>([]);
|
|
||||||
const [currentPage, setCurrentPage] = React.useState<number>(0);
|
|
||||||
//
|
|
||||||
const [recordCount, setRecordCount] = React.useState<number>(0);
|
|
||||||
const [listOption, setListOption] = React.useState({ filter: '' });
|
|
||||||
const [listSort, setListSort] = React.useState({});
|
|
||||||
|
|
||||||
function isListOptionChanged() {
|
|
||||||
return JSON.stringify(listOption) === '{}';
|
|
||||||
}
|
|
||||||
//
|
|
||||||
const reloadRows = async (): Promise<void> => {
|
|
||||||
try {
|
|
||||||
const listOptionTeacherOnly = isListOptionChanged()
|
|
||||||
? { filter: `role = "teacher"` }
|
|
||||||
: { filter: [listOption.filter, `role = "teacher"`].join(' && ') };
|
|
||||||
|
|
||||||
const models: ListResult<RecordModel> = await pb
|
|
||||||
.collection(COL_USER_METAS)
|
|
||||||
.getList(currentPage + 1, rowsPerPage, listOptionTeacherOnly);
|
|
||||||
const { items, totalItems } = models;
|
|
||||||
const tempTeacher: Teacher[] = items.map((lt) => {
|
|
||||||
return { ...defaultTeacher, ...lt };
|
|
||||||
});
|
|
||||||
|
|
||||||
setTeacherData(tempTeacher);
|
|
||||||
setRecordCount(totalItems);
|
|
||||||
setF(tempTeacher);
|
|
||||||
} catch (error) {
|
|
||||||
logger.error(error);
|
|
||||||
setShowError({
|
|
||||||
//
|
|
||||||
show: true,
|
|
||||||
detail: JSON.stringify(error, null, 2),
|
|
||||||
});
|
|
||||||
} finally {
|
|
||||||
setShowLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const [lastListOption, setLastListOption] = React.useState({});
|
|
||||||
const isFirstRun = React.useRef(false);
|
|
||||||
React.useEffect(() => {
|
|
||||||
if (!isFirstRun.current) {
|
|
||||||
isFirstRun.current = true;
|
|
||||||
} else if (JSON.stringify(listOption) !== JSON.stringify(lastListOption)) {
|
|
||||||
// reset page number as tab changes
|
|
||||||
setLastListOption(listOption);
|
|
||||||
setCurrentPage(0);
|
|
||||||
void reloadRows();
|
|
||||||
} else {
|
|
||||||
void reloadRows();
|
|
||||||
}
|
|
||||||
}, [currentPage, rowsPerPage, listOption]);
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
|
||||||
const tempFilter = [];
|
|
||||||
let tempSortDir = '';
|
|
||||||
|
|
||||||
if (status) {
|
|
||||||
tempFilter.push(`status = "${status}"`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sortDir) {
|
|
||||||
tempSortDir = `-created`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (email) {
|
|
||||||
tempFilter.push(`email ~ "%${email}%"`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (phone) {
|
|
||||||
tempFilter.push(`phone ~ "%${phone}%"`);
|
|
||||||
}
|
|
||||||
|
|
||||||
let preFinalListOption = { filter: '' };
|
|
||||||
if (tempFilter.length > 0) {
|
|
||||||
preFinalListOption = { filter: tempFilter.join(' && ') };
|
|
||||||
}
|
|
||||||
if (tempSortDir.length > 0) {
|
|
||||||
preFinalListOption = { ...preFinalListOption, sort: tempSortDir };
|
|
||||||
}
|
|
||||||
setListOption(preFinalListOption);
|
|
||||||
}, [sortDir, email, phone, status]);
|
|
||||||
|
|
||||||
if (showLoading) return <FormLoading />;
|
|
||||||
|
|
||||||
if (showError.show)
|
|
||||||
return (
|
|
||||||
<ErrorDisplay
|
|
||||||
message={t('error.unable-to-process-request')}
|
|
||||||
code={-1}
|
|
||||||
details={showError.detail}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Box
|
|
||||||
sx={{
|
|
||||||
maxWidth: 'var(--Content-maxWidth)',
|
|
||||||
m: 'var(--Content-margin)',
|
|
||||||
p: 'var(--Content-padding)',
|
|
||||||
width: 'var(--Content-width)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Stack spacing={4}>
|
|
||||||
<Stack
|
|
||||||
direction={{ xs: 'column', sm: 'row' }}
|
|
||||||
spacing={3}
|
|
||||||
sx={{ alignItems: 'flex-start' }}
|
|
||||||
>
|
|
||||||
<Box sx={{ flex: '1 1 auto' }}>
|
|
||||||
<Typography variant="h4">{t('list.title')}</Typography>
|
|
||||||
</Box>
|
|
||||||
<Box sx={{ display: 'flex', justifyContent: 'flex-end' }}>
|
|
||||||
<LoadingButton
|
|
||||||
loading={isLoadingAddPage}
|
|
||||||
onClick={(): void => {
|
|
||||||
setIsLoadingAddPage(true);
|
|
||||||
router.push(paths.dashboard.teachers.create);
|
|
||||||
}}
|
|
||||||
startIcon={<PlusIcon />}
|
|
||||||
variant="contained"
|
|
||||||
>
|
|
||||||
{t('list.add')}
|
|
||||||
</LoadingButton>
|
|
||||||
</Box>
|
|
||||||
</Stack>
|
|
||||||
<TeachersSelectionProvider teachers={f}>
|
|
||||||
<Card>
|
|
||||||
<TeachersFilters
|
|
||||||
filters={{ email, phone, status }}
|
|
||||||
fullData={teacherData}
|
|
||||||
sortDir={sortDir}
|
|
||||||
/>
|
|
||||||
<Divider />
|
|
||||||
<Box sx={{ overflowX: 'auto' }}>
|
|
||||||
<TeachersTable
|
|
||||||
reloadRows={reloadRows}
|
|
||||||
rows={f}
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
<Divider />
|
|
||||||
<TeachersPagination
|
|
||||||
count={recordCount}
|
|
||||||
page={currentPage}
|
|
||||||
rowsPerPage={rowsPerPage}
|
|
||||||
setPage={setCurrentPage}
|
|
||||||
setRowsPerPage={setRowsPerPage}
|
|
||||||
/>
|
|
||||||
</Card>
|
|
||||||
</TeachersSelectionProvider>
|
|
||||||
</Stack>
|
|
||||||
<Box sx={{ display: isDevelopment ? 'block' : 'none' }}>
|
|
||||||
<pre>{JSON.stringify(f, null, 2)}</pre>
|
|
||||||
</Box>
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
interface PageProps {
|
|
||||||
searchParams: {
|
|
||||||
email?: string;
|
|
||||||
phone?: string;
|
|
||||||
sortDir?: 'asc' | 'desc';
|
|
||||||
status?: string;
|
|
||||||
//
|
|
||||||
};
|
|
||||||
}
|
|
@@ -1,3 +0,0 @@
|
|||||||
this `tsx` file is clone from elsewhere, please understand, modify and update the content of `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/app/dashboard/user_metas/edit/[id]/page.tsx.draft` to handle `UserMeta` record thanks, modify comments/variables/paths/functions name please
|
|
||||||
|
|
||||||
e.g. why `lessonCategories` still exist ?
|
|
@@ -1,8 +1,9 @@
|
|||||||
'use client';
|
'use client';
|
||||||
// src/app/dashboard/user_metas/edit/[id]/page.tsx
|
|
||||||
|
|
||||||
|
// src/app/dashboard/user_metas/edit/[id]/page.tsx
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import RouterLink from 'next/link';
|
import RouterLink from 'next/link';
|
||||||
|
import { useParams } from 'next/navigation';
|
||||||
import Box from '@mui/material/Box';
|
import Box from '@mui/material/Box';
|
||||||
import Link from '@mui/material/Link';
|
import Link from '@mui/material/Link';
|
||||||
import Stack from '@mui/material/Stack';
|
import Stack from '@mui/material/Stack';
|
||||||
@@ -11,11 +12,12 @@ import { ArrowLeft as ArrowLeftIcon } from '@phosphor-icons/react/dist/ssr/Arrow
|
|||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import { paths } from '@/paths';
|
import { paths } from '@/paths';
|
||||||
import { CrCategoryEditForm } from '@/components/dashboard/cr/categories/cr-category-edit-form';
|
import { UserActivationEditForm } from '@/components/dashboard/user_meta/user-activation-edit-form';
|
||||||
import { UserMetaEditForm } from '@/components/dashboard/user_meta/user-meta-edit-form';
|
import { UserMetaEditForm } from '@/components/dashboard/user_meta/user-meta-edit-form';
|
||||||
|
|
||||||
export default function Page(): React.JSX.Element {
|
export default function Page(): React.JSX.Element {
|
||||||
const { t } = useTranslation(['lp_categories']);
|
const { t } = useTranslation(['user_metas']);
|
||||||
|
const { id: userId } = useParams<{ id: string }>();
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
// console.log('helloworld');
|
// console.log('helloworld');
|
||||||
@@ -49,6 +51,7 @@ export default function Page(): React.JSX.Element {
|
|||||||
</div>
|
</div>
|
||||||
</Stack>
|
</Stack>
|
||||||
<UserMetaEditForm />
|
<UserMetaEditForm />
|
||||||
|
<UserActivationEditForm userId={userId} />
|
||||||
</Stack>
|
</Stack>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
|
@@ -15,12 +15,6 @@ import Stack from '@mui/material/Stack';
|
|||||||
import Typography from '@mui/material/Typography';
|
import Typography from '@mui/material/Typography';
|
||||||
import { Plus as PlusIcon } from '@phosphor-icons/react/dist/ssr/Plus';
|
import { Plus as PlusIcon } from '@phosphor-icons/react/dist/ssr/Plus';
|
||||||
import type { ListResult, RecordModel } from 'pocketbase';
|
import type { ListResult, RecordModel } from 'pocketbase';
|
||||||
|
|
||||||
import { UserMetasFilters } from '@/components/dashboard/user_meta/user-metas-filters';
|
|
||||||
import { UserMetasPagination } from '@/components/dashboard/user_meta/user-metas-pagination';
|
|
||||||
import { UserMetasSelectionProvider } from '@/components/dashboard/user_meta/user-metas-selection-context';
|
|
||||||
import { UserMetasTable } from '@/components/dashboard/user_meta/user-metas-table';
|
|
||||||
import type { UserMeta } from '@/components/dashboard/user_meta/type.d';
|
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import { paths } from '@/paths';
|
import { paths } from '@/paths';
|
||||||
@@ -29,10 +23,15 @@ import { logger } from '@/lib/default-logger';
|
|||||||
import { pb } from '@/lib/pb';
|
import { pb } from '@/lib/pb';
|
||||||
import ErrorDisplay from '@/components/dashboard/error';
|
import ErrorDisplay from '@/components/dashboard/error';
|
||||||
import { defaultUserMeta } from '@/components/dashboard/user_meta/_constants';
|
import { defaultUserMeta } from '@/components/dashboard/user_meta/_constants';
|
||||||
|
import type { UserMeta } from '@/components/dashboard/user_meta/type.d';
|
||||||
|
import { UserMetasFilters } from '@/components/dashboard/user_meta/user-metas-filters';
|
||||||
|
import { UserMetasPagination } from '@/components/dashboard/user_meta/user-metas-pagination';
|
||||||
|
import { UserMetasSelectionProvider } from '@/components/dashboard/user_meta/user-metas-selection-context';
|
||||||
|
import { UserMetasTable } from '@/components/dashboard/user_meta/user-metas-table';
|
||||||
import FormLoading from '@/components/loading';
|
import FormLoading from '@/components/loading';
|
||||||
|
|
||||||
export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||||
const { t } = useTranslation(['teachers']);
|
const { t } = useTranslation(['user_metas']);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const { email, phone, sortDir, status } = searchParams;
|
const { email, phone, sortDir, status } = searchParams;
|
||||||
|
@@ -14,7 +14,7 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { PropertyItem } from '@/components/core/property-item';
|
import { PropertyItem } from '@/components/core/property-item';
|
||||||
import { PropertyList } from '@/components/core/property-list';
|
import { PropertyList } from '@/components/core/property-list';
|
||||||
// import { CrCategory } from '@/components/dashboard/cr/categories/type';
|
// import { CrCategory } from '@/components/dashboard/cr/categories/type';
|
||||||
import type { UserMeta } from '@/components/dashboard/user_meta/type.d';
|
import type { UserMeta } from '@/components/dashboard/user_meta/type_move.d';
|
||||||
|
|
||||||
export default function BasicDetailCard({
|
export default function BasicDetailCard({
|
||||||
userMeta,
|
userMeta,
|
||||||
|
@@ -1,5 +1,9 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
// src/app/dashboard/user_metas/view/[id]/page.tsx
|
||||||
|
// PURPOSE
|
||||||
|
// T.B.A.
|
||||||
|
//
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import RouterLink from 'next/link';
|
import RouterLink from 'next/link';
|
||||||
import { useParams, useRouter } from 'next/navigation';
|
import { useParams, useRouter } from 'next/navigation';
|
||||||
@@ -7,7 +11,7 @@ import SampleAddressCard from '@/app/dashboard/Sample/AddressCard';
|
|||||||
import { SampleNotifications } from '@/app/dashboard/Sample/Notifications';
|
import { SampleNotifications } from '@/app/dashboard/Sample/Notifications';
|
||||||
import SamplePaymentCard from '@/app/dashboard/Sample/PaymentCard';
|
import SamplePaymentCard from '@/app/dashboard/Sample/PaymentCard';
|
||||||
import SampleSecurityCard from '@/app/dashboard/Sample/SecurityCard';
|
import SampleSecurityCard from '@/app/dashboard/Sample/SecurityCard';
|
||||||
|
import { COL_USER_METAS } from '@/constants';
|
||||||
import Box from '@mui/material/Box';
|
import Box from '@mui/material/Box';
|
||||||
import Link from '@mui/material/Link';
|
import Link from '@mui/material/Link';
|
||||||
import Stack from '@mui/material/Stack';
|
import Stack from '@mui/material/Stack';
|
||||||
@@ -21,16 +25,14 @@ import { paths } from '@/paths';
|
|||||||
import { logger } from '@/lib/default-logger';
|
import { logger } from '@/lib/default-logger';
|
||||||
import { pb } from '@/lib/pb';
|
import { pb } from '@/lib/pb';
|
||||||
import { toast } from '@/components/core/toaster';
|
import { toast } from '@/components/core/toaster';
|
||||||
|
|
||||||
import ErrorDisplay from '@/components/dashboard/error';
|
import ErrorDisplay from '@/components/dashboard/error';
|
||||||
|
import { defaultUserMeta } from '@/components/dashboard/user_meta/_constants';
|
||||||
import { Notifications } from '@/components/dashboard/user_meta/notifications';
|
import { Notifications } from '@/components/dashboard/user_meta/notifications';
|
||||||
|
import type { UserMeta } from '@/components/dashboard/user_meta/type_move.d';
|
||||||
import FormLoading from '@/components/loading';
|
import FormLoading from '@/components/loading';
|
||||||
|
|
||||||
import BasicDetailCard from './BasicDetailCard';
|
import BasicDetailCard from './BasicDetailCard';
|
||||||
import TitleCard from './TitleCard';
|
import TitleCard from './TitleCard';
|
||||||
import { defaultUserMeta } from '@/components/dashboard/user_meta/_constants';
|
|
||||||
import type { UserMeta } from '@/components/dashboard/user_meta/type.d';
|
|
||||||
import { COL_USER_METAS } from '@/constants';
|
|
||||||
|
|
||||||
export default function Page(): React.JSX.Element {
|
export default function Page(): React.JSX.Element {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
@@ -1,3 +1,6 @@
|
|||||||
|
// PURPOSE
|
||||||
|
// T.B.A.
|
||||||
|
//
|
||||||
const helloworld = 'helloworld';
|
const helloworld = 'helloworld';
|
||||||
|
|
||||||
export { helloworld };
|
export { helloworld };
|
||||||
|
@@ -1,9 +1,16 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
// src/components/dashboard/student/student-create-form.tsx
|
||||||
|
// PURPOSE
|
||||||
|
// T.B.A.
|
||||||
|
//
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import RouterLink from 'next/link';
|
import RouterLink from 'next/link';
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { createStudent } from '@/db/Students/Create';
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
|
import { LoadingButton } from '@mui/lab';
|
||||||
|
//
|
||||||
import Avatar from '@mui/material/Avatar';
|
import Avatar from '@mui/material/Avatar';
|
||||||
import Box from '@mui/material/Box';
|
import Box from '@mui/material/Box';
|
||||||
import Button from '@mui/material/Button';
|
import Button from '@mui/material/Button';
|
||||||
@@ -16,41 +23,34 @@ import FormControl from '@mui/material/FormControl';
|
|||||||
import FormControlLabel from '@mui/material/FormControlLabel';
|
import FormControlLabel from '@mui/material/FormControlLabel';
|
||||||
import FormHelperText from '@mui/material/FormHelperText';
|
import FormHelperText from '@mui/material/FormHelperText';
|
||||||
import InputLabel from '@mui/material/InputLabel';
|
import InputLabel from '@mui/material/InputLabel';
|
||||||
|
import MenuItem from '@mui/material/MenuItem';
|
||||||
import OutlinedInput from '@mui/material/OutlinedInput';
|
import OutlinedInput from '@mui/material/OutlinedInput';
|
||||||
import Select from '@mui/material/Select';
|
import Select from '@mui/material/Select';
|
||||||
import Stack from '@mui/material/Stack';
|
import Stack from '@mui/material/Stack';
|
||||||
import Typography from '@mui/material/Typography';
|
import Typography from '@mui/material/Typography';
|
||||||
import Grid from '@mui/material/Unstable_Grid2';
|
import Grid from '@mui/material/Unstable_Grid2';
|
||||||
|
//
|
||||||
import { Camera as CameraIcon } from '@phosphor-icons/react/dist/ssr/Camera';
|
import { Camera as CameraIcon } from '@phosphor-icons/react/dist/ssr/Camera';
|
||||||
|
//
|
||||||
import { Controller, useForm } from 'react-hook-form';
|
import { Controller, useForm } from 'react-hook-form';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
import { z as zod } from 'zod';
|
import { z as zod } from 'zod';
|
||||||
|
|
||||||
import { paths } from '@/paths';
|
import { paths } from '@/paths';
|
||||||
import { logger } from '@/lib/default-logger';
|
|
||||||
import { Option } from '@/components/core/option';
|
|
||||||
import { toast } from '@/components/core/toaster';
|
|
||||||
import { createCustomer } from '@/db/Customers/Create';
|
|
||||||
import isDevelopment from '@/lib/check-is-development';
|
import isDevelopment from '@/lib/check-is-development';
|
||||||
|
import { logger } from '@/lib/default-logger';
|
||||||
|
import { base64ToFile, fileToBase64 } from '@/lib/file-to-base64';
|
||||||
|
import { toast } from '@/components/core/toaster';
|
||||||
|
|
||||||
function fileToBase64(file: Blob): Promise<string> {
|
// import ErrorDisplay from '../../error';
|
||||||
return new Promise((resolve, reject) => {
|
import { CreateFormProps } from './type.d';
|
||||||
const reader = new FileReader();
|
|
||||||
reader.readAsDataURL(file);
|
|
||||||
reader.onload = () => {
|
|
||||||
resolve(reader.result as string);
|
|
||||||
};
|
|
||||||
reader.onerror = () => {
|
|
||||||
reject(new Error('Error converting file to base64'));
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// TODO: review schema
|
||||||
const schema = zod.object({
|
const schema = zod.object({
|
||||||
avatar: zod.string().optional(),
|
|
||||||
name: zod.string().min(1, 'Name is required').max(255),
|
name: zod.string().min(1, 'Name is required').max(255),
|
||||||
email: zod.string().email('Must be a valid email').min(1, 'Email is required').max(255),
|
email: zod.string().email('Must be a valid email').min(1, 'Email is required').max(255),
|
||||||
phone: zod.string().min(1, 'Phone is required').max(15),
|
phone: zod.string().min(1, 'Phone is required').max(25),
|
||||||
company: zod.string().max(255),
|
company: zod.string().max(255).optional(),
|
||||||
billingAddress: zod.object({
|
billingAddress: zod.object({
|
||||||
country: zod.string().min(1, 'Country is required').max(255),
|
country: zod.string().min(1, 'Country is required').max(255),
|
||||||
state: zod.string().min(1, 'State is required').max(255),
|
state: zod.string().min(1, 'State is required').max(255),
|
||||||
@@ -63,12 +63,12 @@ const schema = zod.object({
|
|||||||
timezone: zod.string().min(1, 'Timezone is required').max(255),
|
timezone: zod.string().min(1, 'Timezone is required').max(255),
|
||||||
language: zod.string().min(1, 'Language is required').max(255),
|
language: zod.string().min(1, 'Language is required').max(255),
|
||||||
currency: zod.string().min(1, 'Currency is required').max(255),
|
currency: zod.string().min(1, 'Currency is required').max(255),
|
||||||
|
avatar: zod.string().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
type Values = zod.infer<typeof schema>;
|
type Values = zod.infer<typeof schema>;
|
||||||
|
|
||||||
const defaultValues = {
|
const defaultValues = {
|
||||||
avatar: '',
|
|
||||||
name: 'new name',
|
name: 'new name',
|
||||||
email: '123@123.com',
|
email: '123@123.com',
|
||||||
phone: '91234567',
|
phone: '91234567',
|
||||||
@@ -85,10 +85,18 @@ const defaultValues = {
|
|||||||
timezone: 'new_york',
|
timezone: 'new_york',
|
||||||
language: 'en',
|
language: 'en',
|
||||||
currency: 'USD',
|
currency: 'USD',
|
||||||
|
avatar: '',
|
||||||
} satisfies Values;
|
} satisfies Values;
|
||||||
|
|
||||||
export function CustomerCreateForm(): React.JSX.Element {
|
export function StudentCreateForm(): React.JSX.Element {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const { t } = useTranslation(['students']);
|
||||||
|
|
||||||
|
//
|
||||||
|
const [isUpdating, setIsUpdating] = React.useState<boolean>(false);
|
||||||
|
const [showLoading, setShowLoading] = React.useState<boolean>(false);
|
||||||
|
//
|
||||||
|
const [showError, setShowError] = React.useState({ show: false, detail: '' });
|
||||||
|
|
||||||
const {
|
const {
|
||||||
control,
|
control,
|
||||||
@@ -100,14 +108,35 @@ export function CustomerCreateForm(): React.JSX.Element {
|
|||||||
|
|
||||||
const onSubmit = React.useCallback(
|
const onSubmit = React.useCallback(
|
||||||
async (values: Values): Promise<void> => {
|
async (values: Values): Promise<void> => {
|
||||||
try {
|
|
||||||
// Use standard create method from db/Customers/Create
|
// Use standard create method from db/Customers/Create
|
||||||
const record = await createCustomer(values);
|
const tempCreate: CreateFormProps = {
|
||||||
toast.success('Customer created');
|
avatar: values.avatar ? await base64ToFile(values.avatar) : null,
|
||||||
|
//
|
||||||
|
name: values.name,
|
||||||
|
email: values.email,
|
||||||
|
phone: values.phone,
|
||||||
|
company: values.company,
|
||||||
|
timezone: values.timezone,
|
||||||
|
language: values.language,
|
||||||
|
currency: values.currency,
|
||||||
|
taxId: values.taxId,
|
||||||
|
state: 'pending',
|
||||||
|
meta: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
// if (billingAddressId) {
|
||||||
|
// await UpdateBillingAddressById(billingAddressId, values.billingAddress);
|
||||||
|
// }
|
||||||
|
|
||||||
|
const record = await createStudent(tempCreate);
|
||||||
|
toast.success('student-created');
|
||||||
router.push(paths.dashboard.students.view(record.id));
|
router.push(paths.dashboard.students.view(record.id));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
toast.error('Failed to create customer');
|
toast.error('failed-to-create-student');
|
||||||
|
} finally {
|
||||||
|
setIsUpdating(false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[router]
|
[router]
|
||||||
@@ -137,7 +166,7 @@ export function CustomerCreateForm(): React.JSX.Element {
|
|||||||
spacing={4}
|
spacing={4}
|
||||||
>
|
>
|
||||||
<Stack spacing={3}>
|
<Stack spacing={3}>
|
||||||
<Typography variant="h6">Account information</Typography>
|
<Typography variant="h6">{t('create.basic-info')}</Typography>
|
||||||
<Grid
|
<Grid
|
||||||
container
|
container
|
||||||
spacing={3}
|
spacing={3}
|
||||||
@@ -151,12 +180,13 @@ export function CustomerCreateForm(): React.JSX.Element {
|
|||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
border: '1px dashed var(--mui-palette-divider)',
|
border: '1px dashed var(--mui-palette-divider)',
|
||||||
borderRadius: '50%',
|
borderRadius: '5%',
|
||||||
display: 'inline-flex',
|
display: 'inline-flex',
|
||||||
p: '4px',
|
p: '4px',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Avatar
|
<Avatar
|
||||||
|
variant="rounded"
|
||||||
src={avatar}
|
src={avatar}
|
||||||
sx={{
|
sx={{
|
||||||
'--Avatar-size': '100px',
|
'--Avatar-size': '100px',
|
||||||
@@ -175,8 +205,8 @@ export function CustomerCreateForm(): React.JSX.Element {
|
|||||||
spacing={1}
|
spacing={1}
|
||||||
sx={{ alignItems: 'flex-start' }}
|
sx={{ alignItems: 'flex-start' }}
|
||||||
>
|
>
|
||||||
<Typography variant="subtitle1">Avatar</Typography>
|
<Typography variant="subtitle1">{t('create.avatar')}</Typography>
|
||||||
<Typography variant="caption">Min 400x400px, PNG or JPEG</Typography>
|
<Typography variant="caption">{t('create.avatarRequirements')}</Typography>
|
||||||
<Button
|
<Button
|
||||||
color="secondary"
|
color="secondary"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
@@ -184,7 +214,7 @@ export function CustomerCreateForm(): React.JSX.Element {
|
|||||||
}}
|
}}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
>
|
>
|
||||||
Select
|
{t('create.avatar_select')}
|
||||||
</Button>
|
</Button>
|
||||||
<input
|
<input
|
||||||
hidden
|
hidden
|
||||||
@@ -226,7 +256,7 @@ export function CustomerCreateForm(): React.JSX.Element {
|
|||||||
error={Boolean(errors.email)}
|
error={Boolean(errors.email)}
|
||||||
fullWidth
|
fullWidth
|
||||||
>
|
>
|
||||||
<InputLabel required>Email address</InputLabel>
|
<InputLabel required>{t('create.email-address')}</InputLabel>
|
||||||
<OutlinedInput
|
<OutlinedInput
|
||||||
{...field}
|
{...field}
|
||||||
type="email"
|
type="email"
|
||||||
@@ -248,7 +278,7 @@ export function CustomerCreateForm(): React.JSX.Element {
|
|||||||
error={Boolean(errors.phone)}
|
error={Boolean(errors.phone)}
|
||||||
fullWidth
|
fullWidth
|
||||||
>
|
>
|
||||||
<InputLabel required>Phone number</InputLabel>
|
<InputLabel required>{t('create.phone-number')}</InputLabel>
|
||||||
<OutlinedInput {...field} />
|
<OutlinedInput {...field} />
|
||||||
{errors.phone ? <FormHelperText>{errors.phone.message}</FormHelperText> : null}
|
{errors.phone ? <FormHelperText>{errors.phone.message}</FormHelperText> : null}
|
||||||
</FormControl>
|
</FormControl>
|
||||||
@@ -268,7 +298,10 @@ export function CustomerCreateForm(): React.JSX.Element {
|
|||||||
fullWidth
|
fullWidth
|
||||||
>
|
>
|
||||||
<InputLabel>Company</InputLabel>
|
<InputLabel>Company</InputLabel>
|
||||||
<OutlinedInput {...field} />
|
<OutlinedInput
|
||||||
|
{...field}
|
||||||
|
placeholder="no company name"
|
||||||
|
/>
|
||||||
{errors.company ? <FormHelperText>{errors.company.message}</FormHelperText> : null}
|
{errors.company ? <FormHelperText>{errors.company.message}</FormHelperText> : null}
|
||||||
</FormControl>
|
</FormControl>
|
||||||
)}
|
)}
|
||||||
@@ -276,8 +309,9 @@ export function CustomerCreateForm(): React.JSX.Element {
|
|||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
{/* */}
|
||||||
<Stack spacing={3}>
|
<Stack spacing={3}>
|
||||||
<Typography variant="h6">Billing information</Typography>
|
<Typography variant="h6">{t('create.billing-information')}</Typography>
|
||||||
<Grid
|
<Grid
|
||||||
container
|
container
|
||||||
spacing={3}
|
spacing={3}
|
||||||
@@ -296,10 +330,12 @@ export function CustomerCreateForm(): React.JSX.Element {
|
|||||||
>
|
>
|
||||||
<InputLabel required>Country</InputLabel>
|
<InputLabel required>Country</InputLabel>
|
||||||
<Select {...field}>
|
<Select {...field}>
|
||||||
<Option value="">Choose a country</Option>
|
<MenuItem value="">Choose a country</MenuItem>
|
||||||
<Option value="us">United States</Option>
|
<MenuItem value="US">United States</MenuItem>
|
||||||
<Option value="de">Germany</Option>
|
<MenuItem value="UK">United Kingdom</MenuItem>
|
||||||
<Option value="es">Spain</Option>
|
<MenuItem value="CA">Canada</MenuItem>
|
||||||
|
<MenuItem value="DE">Germany</MenuItem>
|
||||||
|
<MenuItem value="ES">Spain</MenuItem>
|
||||||
</Select>
|
</Select>
|
||||||
{errors.billingAddress?.country ? (
|
{errors.billingAddress?.country ? (
|
||||||
<FormHelperText>{errors.billingAddress?.country?.message}</FormHelperText>
|
<FormHelperText>{errors.billingAddress?.country?.message}</FormHelperText>
|
||||||
@@ -362,7 +398,7 @@ export function CustomerCreateForm(): React.JSX.Element {
|
|||||||
error={Boolean(errors.billingAddress?.zipCode)}
|
error={Boolean(errors.billingAddress?.zipCode)}
|
||||||
fullWidth
|
fullWidth
|
||||||
>
|
>
|
||||||
<InputLabel required>Zip code</InputLabel>
|
<InputLabel required>{t('create.zip-code')}</InputLabel>
|
||||||
<OutlinedInput {...field} />
|
<OutlinedInput {...field} />
|
||||||
{errors.billingAddress?.zipCode ? (
|
{errors.billingAddress?.zipCode ? (
|
||||||
<FormHelperText>{errors.billingAddress?.zipCode?.message}</FormHelperText>
|
<FormHelperText>{errors.billingAddress?.zipCode?.message}</FormHelperText>
|
||||||
@@ -383,7 +419,7 @@ export function CustomerCreateForm(): React.JSX.Element {
|
|||||||
error={Boolean(errors.billingAddress?.line1)}
|
error={Boolean(errors.billingAddress?.line1)}
|
||||||
fullWidth
|
fullWidth
|
||||||
>
|
>
|
||||||
<InputLabel required>Address</InputLabel>
|
<InputLabel required>{t('create.address-line-1')}</InputLabel>
|
||||||
<OutlinedInput {...field} />
|
<OutlinedInput {...field} />
|
||||||
{errors.billingAddress?.line1 ? (
|
{errors.billingAddress?.line1 ? (
|
||||||
<FormHelperText>{errors.billingAddress?.line1?.message}</FormHelperText>
|
<FormHelperText>{errors.billingAddress?.line1?.message}</FormHelperText>
|
||||||
@@ -424,7 +460,7 @@ export function CustomerCreateForm(): React.JSX.Element {
|
|||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Stack spacing={3}>
|
<Stack spacing={3}>
|
||||||
<Typography variant="h6">Additional information</Typography>
|
<Typography variant="h6">{t('create.additional-information')}</Typography>
|
||||||
<Grid
|
<Grid
|
||||||
container
|
container
|
||||||
spacing={3}
|
spacing={3}
|
||||||
@@ -443,10 +479,14 @@ export function CustomerCreateForm(): React.JSX.Element {
|
|||||||
>
|
>
|
||||||
<InputLabel required>Timezone</InputLabel>
|
<InputLabel required>Timezone</InputLabel>
|
||||||
<Select {...field}>
|
<Select {...field}>
|
||||||
<Option value="">Select a timezone</Option>
|
<MenuItem value="">Select a timezone</MenuItem>
|
||||||
<Option value="new_york">US - New York</Option>
|
<MenuItem value="Europe/London">London</MenuItem>
|
||||||
<Option value="california">US - California</Option>
|
<MenuItem value="Asia/Tokyo">Tokyo</MenuItem>
|
||||||
<Option value="london">UK - London</Option>
|
<MenuItem value="America/Boa_Vista">Boa Vista</MenuItem>
|
||||||
|
<MenuItem value="America/Grand_Turk">Grand Turk</MenuItem>
|
||||||
|
<MenuItem value="Asia/Manila">Manila</MenuItem>
|
||||||
|
<MenuItem value="Asia/Urumqi">Urumqi</MenuItem>
|
||||||
|
<MenuItem value="Africa/Tunis">Tunis</MenuItem>
|
||||||
</Select>
|
</Select>
|
||||||
{errors.timezone ? <FormHelperText>{errors.timezone.message}</FormHelperText> : null}
|
{errors.timezone ? <FormHelperText>{errors.timezone.message}</FormHelperText> : null}
|
||||||
</FormControl>
|
</FormControl>
|
||||||
@@ -467,10 +507,11 @@ export function CustomerCreateForm(): React.JSX.Element {
|
|||||||
>
|
>
|
||||||
<InputLabel required>Language</InputLabel>
|
<InputLabel required>Language</InputLabel>
|
||||||
<Select {...field}>
|
<Select {...field}>
|
||||||
<Option value="">Select a language</Option>
|
<MenuItem value="">Select a language</MenuItem>
|
||||||
<Option value="en">English</Option>
|
<MenuItem value="en">English</MenuItem>
|
||||||
<Option value="es">Spanish</Option>
|
<MenuItem value="es">Spanish</MenuItem>
|
||||||
<Option value="de">German</Option>
|
<MenuItem value="de">German</MenuItem>
|
||||||
|
<MenuItem value="fr">French</MenuItem>
|
||||||
</Select>
|
</Select>
|
||||||
{errors.language ? <FormHelperText>{errors.language.message}</FormHelperText> : null}
|
{errors.language ? <FormHelperText>{errors.language.message}</FormHelperText> : null}
|
||||||
</FormControl>
|
</FormControl>
|
||||||
@@ -489,12 +530,12 @@ export function CustomerCreateForm(): React.JSX.Element {
|
|||||||
error={Boolean(errors.currency)}
|
error={Boolean(errors.currency)}
|
||||||
fullWidth
|
fullWidth
|
||||||
>
|
>
|
||||||
<InputLabel>Currency</InputLabel>
|
<InputLabel required>{t('create.currency')}</InputLabel>
|
||||||
<Select {...field}>
|
<Select {...field}>
|
||||||
<Option value="">Select a currency</Option>
|
<MenuItem value="">no currency selected</MenuItem>
|
||||||
<Option value="USD">USD</Option>
|
<MenuItem value="USD">USD</MenuItem>
|
||||||
<Option value="EUR">EUR</Option>
|
<MenuItem value="EUR">EUR</MenuItem>
|
||||||
<Option value="RON">RON</Option>
|
<MenuItem value="GBP">GBP</MenuItem>
|
||||||
</Select>
|
</Select>
|
||||||
{errors.currency ? <FormHelperText>{errors.currency.message}</FormHelperText> : null}
|
{errors.currency ? <FormHelperText>{errors.currency.message}</FormHelperText> : null}
|
||||||
</FormControl>
|
</FormControl>
|
||||||
@@ -511,14 +552,17 @@ export function CustomerCreateForm(): React.JSX.Element {
|
|||||||
component={RouterLink}
|
component={RouterLink}
|
||||||
href={paths.dashboard.students.list}
|
href={paths.dashboard.students.list}
|
||||||
>
|
>
|
||||||
Cancel
|
{t('create.cancelButton')}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
|
||||||
|
<LoadingButton
|
||||||
|
disabled={isUpdating}
|
||||||
|
loading={isUpdating}
|
||||||
type="submit"
|
type="submit"
|
||||||
variant="contained"
|
variant="contained"
|
||||||
>
|
>
|
||||||
Create customer
|
{t('create.updateButton')}
|
||||||
</Button>
|
</LoadingButton>
|
||||||
</CardActions>
|
</CardActions>
|
||||||
</Card>
|
</Card>
|
||||||
<Box sx={{ display: isDevelopment ? 'block' : 'none' }}>
|
<Box sx={{ display: isDevelopment ? 'block' : 'none' }}>
|
||||||
|
@@ -1,10 +1,16 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
// src/components/dashboard/student/student-edit-form.tsx
|
||||||
|
// PURPOSE:
|
||||||
|
// handle change details for student collection
|
||||||
|
//
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import RouterLink from 'next/link';
|
import RouterLink from 'next/link';
|
||||||
import { useParams, useRouter } from 'next/navigation';
|
import { useParams, useRouter } from 'next/navigation';
|
||||||
//
|
//
|
||||||
import { COL_CUSTOMERS } from '@/constants';
|
import { UpdateBillingAddressById } from '@/db/billingAddress/UpdateById';
|
||||||
|
import { getStudentById } from '@/db/Students/GetById';
|
||||||
|
import { UpdateStudentById } from '@/db/Students/UpdateById';
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { LoadingButton } from '@mui/lab';
|
import { LoadingButton } from '@mui/lab';
|
||||||
//
|
//
|
||||||
@@ -35,12 +41,13 @@ import { paths } from '@/paths';
|
|||||||
import isDevelopment from '@/lib/check-is-development';
|
import isDevelopment from '@/lib/check-is-development';
|
||||||
import { logger } from '@/lib/default-logger';
|
import { logger } from '@/lib/default-logger';
|
||||||
import { base64ToFile, fileToBase64 } from '@/lib/file-to-base64';
|
import { base64ToFile, fileToBase64 } from '@/lib/file-to-base64';
|
||||||
import { pb } from '@/lib/pb';
|
import getImageUrlFromFile from '@/lib/get-image-url-from-file.ts';
|
||||||
import { toast } from '@/components/core/toaster';
|
import { toast } from '@/components/core/toaster';
|
||||||
import FormLoading from '@/components/loading';
|
import FormLoading from '@/components/loading';
|
||||||
|
|
||||||
// import ErrorDisplay from '../../error';
|
// import ErrorDisplay from '../../error';
|
||||||
import ErrorDisplay from '../error';
|
import ErrorDisplay from '../error';
|
||||||
|
import type { Student } from './type.d';
|
||||||
|
|
||||||
// TODO: review schema
|
// TODO: review schema
|
||||||
const schema = zod.object({
|
const schema = zod.object({
|
||||||
@@ -87,14 +94,15 @@ const defaultValues = {
|
|||||||
|
|
||||||
export function StudentEditForm(): React.JSX.Element {
|
export function StudentEditForm(): React.JSX.Element {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { t } = useTranslation(['lp_categories']);
|
const { t } = useTranslation(['students']);
|
||||||
|
|
||||||
const { customerId } = useParams<{ customerId: string }>();
|
const { id: studentId } = useParams<{ id: string }>();
|
||||||
//
|
//
|
||||||
const [isUpdating, setIsUpdating] = React.useState<boolean>(false);
|
const [isUpdating, setIsUpdating] = React.useState<boolean>(false);
|
||||||
const [showLoading, setShowLoading] = React.useState<boolean>(false);
|
const [showLoading, setShowLoading] = React.useState<boolean>(false);
|
||||||
//
|
//
|
||||||
const [showError, setShowError] = React.useState({ show: false, detail: '' });
|
const [showError, setShowError] = React.useState({ show: false, detail: '' });
|
||||||
|
const [billingAddressId, setBillingAddressId] = React.useState<string | null>(null);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
control,
|
control,
|
||||||
@@ -114,7 +122,9 @@ export function StudentEditForm(): React.JSX.Element {
|
|||||||
email: values.email,
|
email: values.email,
|
||||||
phone: values.phone,
|
phone: values.phone,
|
||||||
company: values.company,
|
company: values.company,
|
||||||
billingAddress: values.billingAddress,
|
//
|
||||||
|
// billingAddress: values.billingAddress,
|
||||||
|
//
|
||||||
taxId: values.taxId,
|
taxId: values.taxId,
|
||||||
timezone: values.timezone,
|
timezone: values.timezone,
|
||||||
language: values.language,
|
language: values.language,
|
||||||
@@ -123,17 +133,22 @@ export function StudentEditForm(): React.JSX.Element {
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await pb.collection(COL_CUSTOMERS).update(customerId, updateData);
|
await UpdateStudentById(studentId, updateData);
|
||||||
toast.success('Customer updated successfully');
|
//
|
||||||
|
toast.success(t('student-updated-successfully'));
|
||||||
router.push(paths.dashboard.students.list);
|
router.push(paths.dashboard.students.list);
|
||||||
|
|
||||||
|
if (billingAddressId) {
|
||||||
|
await UpdateBillingAddressById(billingAddressId, values.billingAddress);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
toast.error('Failed to update customer');
|
toast.error(t('failed-to-update-student'));
|
||||||
} finally {
|
} finally {
|
||||||
setIsUpdating(false);
|
setIsUpdating(false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[customerId, router]
|
[studentId, router]
|
||||||
);
|
);
|
||||||
|
|
||||||
const avatarInputRef = React.useRef<HTMLInputElement>(null);
|
const avatarInputRef = React.useRef<HTMLInputElement>(null);
|
||||||
@@ -162,21 +177,21 @@ export function StudentEditForm(): React.JSX.Element {
|
|||||||
setShowLoading(true);
|
setShowLoading(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await pb.collection(COL_CUSTOMERS).getOne(id);
|
const result = (await getStudentById(id)) as unknown as Student;
|
||||||
|
//
|
||||||
reset({ ...defaultValues, ...result });
|
reset({ ...defaultValues, ...result });
|
||||||
console.log({ result });
|
|
||||||
|
|
||||||
if (result.avatar_file) {
|
setBillingAddressId(result.billingAddress.id);
|
||||||
const fetchResult = await fetch(
|
|
||||||
`http://127.0.0.1:8090/api/files/${result.collectionId}/${result.id}/${result.avatar_file}`
|
if (result.avatar) {
|
||||||
);
|
const fetchResult = await fetch(getImageUrlFromFile(result.collectionId, result.id, result.avatar));
|
||||||
const blob = await fetchResult.blob();
|
const blob = await fetchResult.blob();
|
||||||
const url = await fileToBase64(blob);
|
const url = await fileToBase64(blob);
|
||||||
setValue('avatar', url);
|
setValue('avatar', url);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
toast.error('Failed to load customer data');
|
toast.error(t('failed-to-load-student-data'));
|
||||||
setShowError({ show: true, detail: JSON.stringify(error, null, 2) });
|
setShowError({ show: true, detail: JSON.stringify(error, null, 2) });
|
||||||
} finally {
|
} finally {
|
||||||
setShowLoading(false);
|
setShowLoading(false);
|
||||||
@@ -186,9 +201,9 @@ export function StudentEditForm(): React.JSX.Element {
|
|||||||
);
|
);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
void loadExistingData(customerId);
|
void loadExistingData(studentId);
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [customerId]);
|
}, [studentId]);
|
||||||
|
|
||||||
if (showLoading) return <FormLoading />;
|
if (showLoading) return <FormLoading />;
|
||||||
if (showError.show)
|
if (showError.show)
|
||||||
@@ -299,7 +314,7 @@ export function StudentEditForm(): React.JSX.Element {
|
|||||||
error={Boolean(errors.email)}
|
error={Boolean(errors.email)}
|
||||||
fullWidth
|
fullWidth
|
||||||
>
|
>
|
||||||
<InputLabel required>Email</InputLabel>
|
<InputLabel required>{t('edit.email-address')}</InputLabel>
|
||||||
<OutlinedInput
|
<OutlinedInput
|
||||||
{...field}
|
{...field}
|
||||||
type="email"
|
type="email"
|
||||||
@@ -321,7 +336,7 @@ export function StudentEditForm(): React.JSX.Element {
|
|||||||
error={Boolean(errors.phone)}
|
error={Boolean(errors.phone)}
|
||||||
fullWidth
|
fullWidth
|
||||||
>
|
>
|
||||||
<InputLabel required>Phone</InputLabel>
|
<InputLabel required>{t('edit.phone-number')}</InputLabel>
|
||||||
<OutlinedInput {...field} />
|
<OutlinedInput {...field} />
|
||||||
{errors.phone ? <FormHelperText>{errors.phone.message}</FormHelperText> : null}
|
{errors.phone ? <FormHelperText>{errors.phone.message}</FormHelperText> : null}
|
||||||
</FormControl>
|
</FormControl>
|
||||||
@@ -350,11 +365,12 @@ export function StudentEditForm(): React.JSX.Element {
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
{/* */}
|
||||||
</Grid>
|
</Grid>
|
||||||
</Stack>
|
</Stack>
|
||||||
{/* */}
|
{/* */}
|
||||||
<Stack spacing={3}>
|
<Stack spacing={3}>
|
||||||
<Typography variant="h6">Billing Information</Typography>
|
<Typography variant="h6">{t('edit.billing-information')}</Typography>
|
||||||
<Grid
|
<Grid
|
||||||
container
|
container
|
||||||
spacing={3}
|
spacing={3}
|
||||||
@@ -373,9 +389,12 @@ export function StudentEditForm(): React.JSX.Element {
|
|||||||
>
|
>
|
||||||
<InputLabel required>Country</InputLabel>
|
<InputLabel required>Country</InputLabel>
|
||||||
<Select {...field}>
|
<Select {...field}>
|
||||||
|
<MenuItem value="">No Country selected</MenuItem>
|
||||||
<MenuItem value="US">United States</MenuItem>
|
<MenuItem value="US">United States</MenuItem>
|
||||||
<MenuItem value="UK">United Kingdom</MenuItem>
|
<MenuItem value="UK">United Kingdom</MenuItem>
|
||||||
<MenuItem value="CA">Canada</MenuItem>
|
<MenuItem value="CA">Canada</MenuItem>
|
||||||
|
<MenuItem value="DE">Germany</MenuItem>
|
||||||
|
<MenuItem value="ES">Spain</MenuItem>
|
||||||
</Select>
|
</Select>
|
||||||
{errors.billingAddress?.country ? (
|
{errors.billingAddress?.country ? (
|
||||||
<FormHelperText>{errors.billingAddress.country.message}</FormHelperText>
|
<FormHelperText>{errors.billingAddress.country.message}</FormHelperText>
|
||||||
@@ -438,7 +457,7 @@ export function StudentEditForm(): React.JSX.Element {
|
|||||||
error={Boolean(errors.billingAddress?.zipCode)}
|
error={Boolean(errors.billingAddress?.zipCode)}
|
||||||
fullWidth
|
fullWidth
|
||||||
>
|
>
|
||||||
<InputLabel required>Zip Code</InputLabel>
|
<InputLabel required>{t('edit.zip-code')}</InputLabel>
|
||||||
<OutlinedInput {...field} />
|
<OutlinedInput {...field} />
|
||||||
{errors.billingAddress?.zipCode ? (
|
{errors.billingAddress?.zipCode ? (
|
||||||
<FormHelperText>{errors.billingAddress.zipCode.message}</FormHelperText>
|
<FormHelperText>{errors.billingAddress.zipCode.message}</FormHelperText>
|
||||||
@@ -459,7 +478,7 @@ export function StudentEditForm(): React.JSX.Element {
|
|||||||
error={Boolean(errors.billingAddress?.line1)}
|
error={Boolean(errors.billingAddress?.line1)}
|
||||||
fullWidth
|
fullWidth
|
||||||
>
|
>
|
||||||
<InputLabel required>Address Line 1</InputLabel>
|
<InputLabel required>{t('edit.address-line-1')}</InputLabel>
|
||||||
<OutlinedInput {...field} />
|
<OutlinedInput {...field} />
|
||||||
{errors.billingAddress?.line1 ? (
|
{errors.billingAddress?.line1 ? (
|
||||||
<FormHelperText>{errors.billingAddress.line1.message}</FormHelperText>
|
<FormHelperText>{errors.billingAddress.line1.message}</FormHelperText>
|
||||||
@@ -494,7 +513,7 @@ export function StudentEditForm(): React.JSX.Element {
|
|||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
<Stack spacing={3}>
|
<Stack spacing={3}>
|
||||||
<Typography variant="h6">Additional Information</Typography>
|
<Typography variant="h6">{t('edit.additional-information')}</Typography>
|
||||||
<Grid
|
<Grid
|
||||||
container
|
container
|
||||||
spacing={3}
|
spacing={3}
|
||||||
@@ -541,8 +560,10 @@ export function StudentEditForm(): React.JSX.Element {
|
|||||||
>
|
>
|
||||||
<InputLabel required>Language</InputLabel>
|
<InputLabel required>Language</InputLabel>
|
||||||
<Select {...field}>
|
<Select {...field}>
|
||||||
|
<MenuItem value="">no language selected</MenuItem>
|
||||||
<MenuItem value="en">English</MenuItem>
|
<MenuItem value="en">English</MenuItem>
|
||||||
<MenuItem value="es">Spanish</MenuItem>
|
<MenuItem value="es">Spanish</MenuItem>
|
||||||
|
<MenuItem value="de">German</MenuItem>
|
||||||
<MenuItem value="fr">French</MenuItem>
|
<MenuItem value="fr">French</MenuItem>
|
||||||
</Select>
|
</Select>
|
||||||
{errors.language ? <FormHelperText>{errors.language.message}</FormHelperText> : null}
|
{errors.language ? <FormHelperText>{errors.language.message}</FormHelperText> : null}
|
||||||
@@ -562,8 +583,9 @@ export function StudentEditForm(): React.JSX.Element {
|
|||||||
error={Boolean(errors.currency)}
|
error={Boolean(errors.currency)}
|
||||||
fullWidth
|
fullWidth
|
||||||
>
|
>
|
||||||
<InputLabel required>Currency</InputLabel>
|
<InputLabel required>{t('edit.currency')}</InputLabel>
|
||||||
<Select {...field}>
|
<Select {...field}>
|
||||||
|
<MenuItem value="">no currency selected</MenuItem>
|
||||||
<MenuItem value="USD">USD</MenuItem>
|
<MenuItem value="USD">USD</MenuItem>
|
||||||
<MenuItem value="EUR">EUR</MenuItem>
|
<MenuItem value="EUR">EUR</MenuItem>
|
||||||
<MenuItem value="GBP">GBP</MenuItem>
|
<MenuItem value="GBP">GBP</MenuItem>
|
||||||
|
@@ -1,20 +1,67 @@
|
|||||||
'use client';
|
// src/components/dashboard/student/type.d.tsx
|
||||||
|
|
||||||
// RULES: sorting direction for student lists
|
// RULES: sorting direction for student lists
|
||||||
|
import type { BillingAddress } from '@/db/billingAddress/type';
|
||||||
|
|
||||||
|
// RULES: sorting direction for teacher lists
|
||||||
export type SortDir = 'asc' | 'desc';
|
export type SortDir = 'asc' | 'desc';
|
||||||
|
|
||||||
|
export interface DBStudent {
|
||||||
|
name: string;
|
||||||
|
//
|
||||||
|
// NOTE: obslete "avatar" and use "avatar_file"
|
||||||
|
avatar?: string;
|
||||||
|
avatar_file?: string;
|
||||||
|
//
|
||||||
|
email: string;
|
||||||
|
phone: string;
|
||||||
|
quota: number;
|
||||||
|
company: string;
|
||||||
|
//
|
||||||
|
// billingAddress: BillingAddress[] | [];
|
||||||
|
expand: { billingAddress?: BillingAddress[] };
|
||||||
|
|
||||||
|
// status is obsoleted, replace by state
|
||||||
|
status: 'pending' | 'active' | 'blocked';
|
||||||
|
state: 'pending' | 'active' | 'blocked';
|
||||||
|
//
|
||||||
|
timezone: string;
|
||||||
|
language: string;
|
||||||
|
currency: string;
|
||||||
|
//
|
||||||
|
id: string;
|
||||||
|
created: string;
|
||||||
|
updated?: string;
|
||||||
|
collectionId: string;
|
||||||
|
}
|
||||||
|
|
||||||
// RULES: core student data structure
|
// RULES: core student data structure
|
||||||
export interface Student {
|
export interface Student {
|
||||||
id: string;
|
|
||||||
collectionId: string;
|
|
||||||
name: string;
|
name: string;
|
||||||
|
//
|
||||||
|
// NOTE: obslete "avatar" and use "avatar_file"
|
||||||
avatar?: string;
|
avatar?: string;
|
||||||
|
avatar_file?: string;
|
||||||
|
//
|
||||||
email: string;
|
email: string;
|
||||||
phone?: string;
|
phone?: string;
|
||||||
quota: number;
|
quota: number;
|
||||||
|
company?: string;
|
||||||
|
//
|
||||||
|
billingAddress: BillingAddress | Record<string, never>;
|
||||||
|
|
||||||
|
// status is obsoleted, replace by state
|
||||||
status: 'pending' | 'active' | 'blocked';
|
status: 'pending' | 'active' | 'blocked';
|
||||||
|
state: 'pending' | 'active' | 'blocked';
|
||||||
|
//
|
||||||
|
timezone: string;
|
||||||
|
language: string;
|
||||||
|
currency: string;
|
||||||
|
//
|
||||||
|
id: string;
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
updatedAt?: Date;
|
updatedAt?: Date;
|
||||||
|
collectionId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// RULES: form data structure for creating new student
|
// RULES: form data structure for creating new student
|
||||||
@@ -23,21 +70,25 @@ export interface CreateFormProps {
|
|||||||
email: string;
|
email: string;
|
||||||
phone?: string;
|
phone?: string;
|
||||||
company?: string;
|
company?: string;
|
||||||
billingAddress?: {
|
//
|
||||||
country: string;
|
// handle seperately
|
||||||
state: string;
|
// billingAddress?: {
|
||||||
city: string;
|
// country: string;
|
||||||
zipCode: string;
|
// state: string;
|
||||||
line1: string;
|
// city: string;
|
||||||
line2?: string;
|
// zipCode: string;
|
||||||
};
|
// line1: string;
|
||||||
|
// line2?: string;
|
||||||
|
// };
|
||||||
|
//
|
||||||
taxId?: string;
|
taxId?: string;
|
||||||
timezone: string;
|
timezone: string;
|
||||||
language: string;
|
language: string;
|
||||||
currency: string;
|
currency: string;
|
||||||
avatar?: string;
|
avatar?: File | null;
|
||||||
// quota?: number;
|
// quota?: number;
|
||||||
// status?: 'pending' | 'active' | 'blocked';
|
state?: 'pending' | 'active' | 'blocked';
|
||||||
|
meta: Record<string, null>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// RULES: form data structure for editing existing student
|
// RULES: form data structure for editing existing student
|
||||||
@@ -62,6 +113,7 @@ export interface EditFormProps {
|
|||||||
// quota?: number;
|
// quota?: number;
|
||||||
// status?: 'pending' | 'active' | 'blocked';
|
// status?: 'pending' | 'active' | 'blocked';
|
||||||
}
|
}
|
||||||
|
|
||||||
// RULES: filter props for student search and filtering
|
// RULES: filter props for student search and filtering
|
||||||
export interface CustomersFiltersProps {
|
export interface CustomersFiltersProps {
|
||||||
filters?: Filters;
|
filters?: Filters;
|
@@ -1,9 +1,19 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
// src/components/dashboard/teacher/teacher-create-form.tsx
|
||||||
|
// PURPOSE
|
||||||
|
// T.B.A.
|
||||||
|
//
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import RouterLink from 'next/link';
|
import RouterLink from 'next/link';
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { UpdateBillingAddressById } from '@/db/billingAddress/UpdateById';
|
||||||
|
import { createTeacher } from '@/db/Teachers/Create';
|
||||||
|
import { getTeacherById } from '@/db/Teachers/GetById';
|
||||||
|
import { UpdateTeacherById } from '@/db/Teachers/UpdateById';
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
|
import { LoadingButton } from '@mui/lab';
|
||||||
|
//
|
||||||
import Avatar from '@mui/material/Avatar';
|
import Avatar from '@mui/material/Avatar';
|
||||||
import Box from '@mui/material/Box';
|
import Box from '@mui/material/Box';
|
||||||
import Button from '@mui/material/Button';
|
import Button from '@mui/material/Button';
|
||||||
@@ -16,41 +26,38 @@ import FormControl from '@mui/material/FormControl';
|
|||||||
import FormControlLabel from '@mui/material/FormControlLabel';
|
import FormControlLabel from '@mui/material/FormControlLabel';
|
||||||
import FormHelperText from '@mui/material/FormHelperText';
|
import FormHelperText from '@mui/material/FormHelperText';
|
||||||
import InputLabel from '@mui/material/InputLabel';
|
import InputLabel from '@mui/material/InputLabel';
|
||||||
|
import MenuItem from '@mui/material/MenuItem';
|
||||||
import OutlinedInput from '@mui/material/OutlinedInput';
|
import OutlinedInput from '@mui/material/OutlinedInput';
|
||||||
import Select from '@mui/material/Select';
|
import Select from '@mui/material/Select';
|
||||||
import Stack from '@mui/material/Stack';
|
import Stack from '@mui/material/Stack';
|
||||||
import Typography from '@mui/material/Typography';
|
import Typography from '@mui/material/Typography';
|
||||||
import Grid from '@mui/material/Unstable_Grid2';
|
import Grid from '@mui/material/Unstable_Grid2';
|
||||||
|
//
|
||||||
import { Camera as CameraIcon } from '@phosphor-icons/react/dist/ssr/Camera';
|
import { Camera as CameraIcon } from '@phosphor-icons/react/dist/ssr/Camera';
|
||||||
|
//
|
||||||
import { Controller, useForm } from 'react-hook-form';
|
import { Controller, useForm } from 'react-hook-form';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
import { z as zod } from 'zod';
|
import { z as zod } from 'zod';
|
||||||
|
|
||||||
import { paths } from '@/paths';
|
import { paths } from '@/paths';
|
||||||
|
import isDevelopment from '@/lib/check-is-development';
|
||||||
import { logger } from '@/lib/default-logger';
|
import { logger } from '@/lib/default-logger';
|
||||||
|
import { base64ToFile, fileToBase64 } from '@/lib/file-to-base64';
|
||||||
|
import { pb } from '@/lib/pb';
|
||||||
import { Option } from '@/components/core/option';
|
import { Option } from '@/components/core/option';
|
||||||
import { toast } from '@/components/core/toaster';
|
import { toast } from '@/components/core/toaster';
|
||||||
import { createTeacher } from '@/db/Teachers/Create';
|
import FormLoading from '@/components/loading';
|
||||||
import isDevelopment from '@/lib/check-is-development';
|
|
||||||
|
|
||||||
function fileToBase64(file: Blob): Promise<string> {
|
// import ErrorDisplay from '../../error';
|
||||||
return new Promise((resolve, reject) => {
|
import ErrorDisplay from '../error';
|
||||||
const reader = new FileReader();
|
import { CreateFormProps } from './type.d';
|
||||||
reader.readAsDataURL(file);
|
|
||||||
reader.onload = () => {
|
|
||||||
resolve(reader.result as string);
|
|
||||||
};
|
|
||||||
reader.onerror = () => {
|
|
||||||
reject(new Error('Error converting file to base64'));
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// TODO: review schema
|
||||||
const schema = zod.object({
|
const schema = zod.object({
|
||||||
avatar: zod.string().optional(),
|
|
||||||
name: zod.string().min(1, 'Name is required').max(255),
|
name: zod.string().min(1, 'Name is required').max(255),
|
||||||
email: zod.string().email('Must be a valid email').min(1, 'Email is required').max(255),
|
email: zod.string().email('Must be a valid email').min(1, 'Email is required').max(255),
|
||||||
phone: zod.string().min(1, 'Phone is required').max(15),
|
phone: zod.string().min(1, 'Phone is required').max(25),
|
||||||
company: zod.string().max(255),
|
company: zod.string().max(255).optional(),
|
||||||
billingAddress: zod.object({
|
billingAddress: zod.object({
|
||||||
country: zod.string().min(1, 'Country is required').max(255),
|
country: zod.string().min(1, 'Country is required').max(255),
|
||||||
state: zod.string().min(1, 'State is required').max(255),
|
state: zod.string().min(1, 'State is required').max(255),
|
||||||
@@ -63,12 +70,12 @@ const schema = zod.object({
|
|||||||
timezone: zod.string().min(1, 'Timezone is required').max(255),
|
timezone: zod.string().min(1, 'Timezone is required').max(255),
|
||||||
language: zod.string().min(1, 'Language is required').max(255),
|
language: zod.string().min(1, 'Language is required').max(255),
|
||||||
currency: zod.string().min(1, 'Currency is required').max(255),
|
currency: zod.string().min(1, 'Currency is required').max(255),
|
||||||
|
avatar: zod.string().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
type Values = zod.infer<typeof schema>;
|
type Values = zod.infer<typeof schema>;
|
||||||
|
|
||||||
const defaultValues = {
|
const defaultValues = {
|
||||||
avatar: '',
|
|
||||||
name: 'new name',
|
name: 'new name',
|
||||||
email: '123@123.com',
|
email: '123@123.com',
|
||||||
phone: '91234567',
|
phone: '91234567',
|
||||||
@@ -85,10 +92,18 @@ const defaultValues = {
|
|||||||
timezone: 'new_york',
|
timezone: 'new_york',
|
||||||
language: 'en',
|
language: 'en',
|
||||||
currency: 'USD',
|
currency: 'USD',
|
||||||
|
avatar: '',
|
||||||
} satisfies Values;
|
} satisfies Values;
|
||||||
|
|
||||||
export function TeacherCreateForm(): React.JSX.Element {
|
export function TeacherCreateForm(): React.JSX.Element {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const { t } = useTranslation(['students']);
|
||||||
|
|
||||||
|
//
|
||||||
|
const [isUpdating, setIsUpdating] = React.useState<boolean>(false);
|
||||||
|
const [showLoading, setShowLoading] = React.useState<boolean>(false);
|
||||||
|
//
|
||||||
|
const [showError, setShowError] = React.useState({ show: false, detail: '' });
|
||||||
|
|
||||||
const {
|
const {
|
||||||
control,
|
control,
|
||||||
@@ -100,14 +115,31 @@ export function TeacherCreateForm(): React.JSX.Element {
|
|||||||
|
|
||||||
const onSubmit = React.useCallback(
|
const onSubmit = React.useCallback(
|
||||||
async (values: Values): Promise<void> => {
|
async (values: Values): Promise<void> => {
|
||||||
try {
|
|
||||||
// Use standard create method from db/Customers/Create
|
// Use standard create method from db/Customers/Create
|
||||||
const record = await createTeacher(values);
|
const tempCreate: CreateFormProps = {
|
||||||
toast.success('Customer created');
|
avatar: values.avatar ? await base64ToFile(values.avatar) : null,
|
||||||
|
//
|
||||||
|
name: values.name,
|
||||||
|
email: values.email,
|
||||||
|
phone: values.phone,
|
||||||
|
company: values.company,
|
||||||
|
timezone: values.timezone,
|
||||||
|
language: values.language,
|
||||||
|
currency: values.currency,
|
||||||
|
taxId: values.taxId,
|
||||||
|
state: 'pending',
|
||||||
|
meta: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const record = await createTeacher(tempCreate);
|
||||||
|
toast.success('teacher-created');
|
||||||
router.push(paths.dashboard.teachers.details(record.id));
|
router.push(paths.dashboard.teachers.details(record.id));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
toast.error('Failed to create customer');
|
toast.error('failed-to-create-teacher');
|
||||||
|
} finally {
|
||||||
|
setIsUpdating(false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[router]
|
[router]
|
||||||
@@ -137,7 +169,7 @@ export function TeacherCreateForm(): React.JSX.Element {
|
|||||||
spacing={4}
|
spacing={4}
|
||||||
>
|
>
|
||||||
<Stack spacing={3}>
|
<Stack spacing={3}>
|
||||||
<Typography variant="h6">Account information</Typography>
|
<Typography variant="h6">{t('create.basic-info')}</Typography>
|
||||||
<Grid
|
<Grid
|
||||||
container
|
container
|
||||||
spacing={3}
|
spacing={3}
|
||||||
@@ -151,12 +183,13 @@ export function TeacherCreateForm(): React.JSX.Element {
|
|||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
border: '1px dashed var(--mui-palette-divider)',
|
border: '1px dashed var(--mui-palette-divider)',
|
||||||
borderRadius: '50%',
|
borderRadius: '5%',
|
||||||
display: 'inline-flex',
|
display: 'inline-flex',
|
||||||
p: '4px',
|
p: '4px',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Avatar
|
<Avatar
|
||||||
|
variant="rounded"
|
||||||
src={avatar}
|
src={avatar}
|
||||||
sx={{
|
sx={{
|
||||||
'--Avatar-size': '100px',
|
'--Avatar-size': '100px',
|
||||||
@@ -175,8 +208,8 @@ export function TeacherCreateForm(): React.JSX.Element {
|
|||||||
spacing={1}
|
spacing={1}
|
||||||
sx={{ alignItems: 'flex-start' }}
|
sx={{ alignItems: 'flex-start' }}
|
||||||
>
|
>
|
||||||
<Typography variant="subtitle1">Avatar</Typography>
|
<Typography variant="subtitle1">{t('create.avatar')}</Typography>
|
||||||
<Typography variant="caption">Min 400x400px, PNG or JPEG</Typography>
|
<Typography variant="caption">{t('create.avatarRequirements')}</Typography>
|
||||||
<Button
|
<Button
|
||||||
color="secondary"
|
color="secondary"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
@@ -184,7 +217,7 @@ export function TeacherCreateForm(): React.JSX.Element {
|
|||||||
}}
|
}}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
>
|
>
|
||||||
Select
|
{t('create.avatar_select')}
|
||||||
</Button>
|
</Button>
|
||||||
<input
|
<input
|
||||||
hidden
|
hidden
|
||||||
@@ -226,7 +259,7 @@ export function TeacherCreateForm(): React.JSX.Element {
|
|||||||
error={Boolean(errors.email)}
|
error={Boolean(errors.email)}
|
||||||
fullWidth
|
fullWidth
|
||||||
>
|
>
|
||||||
<InputLabel required>Email address</InputLabel>
|
<InputLabel required>{t('create.email-address')}</InputLabel>
|
||||||
<OutlinedInput
|
<OutlinedInput
|
||||||
{...field}
|
{...field}
|
||||||
type="email"
|
type="email"
|
||||||
@@ -248,7 +281,7 @@ export function TeacherCreateForm(): React.JSX.Element {
|
|||||||
error={Boolean(errors.phone)}
|
error={Boolean(errors.phone)}
|
||||||
fullWidth
|
fullWidth
|
||||||
>
|
>
|
||||||
<InputLabel required>Phone number</InputLabel>
|
<InputLabel required>{t('create.phone-number')}</InputLabel>
|
||||||
<OutlinedInput {...field} />
|
<OutlinedInput {...field} />
|
||||||
{errors.phone ? <FormHelperText>{errors.phone.message}</FormHelperText> : null}
|
{errors.phone ? <FormHelperText>{errors.phone.message}</FormHelperText> : null}
|
||||||
</FormControl>
|
</FormControl>
|
||||||
@@ -268,7 +301,10 @@ export function TeacherCreateForm(): React.JSX.Element {
|
|||||||
fullWidth
|
fullWidth
|
||||||
>
|
>
|
||||||
<InputLabel>Company</InputLabel>
|
<InputLabel>Company</InputLabel>
|
||||||
<OutlinedInput {...field} />
|
<OutlinedInput
|
||||||
|
{...field}
|
||||||
|
placeholder="no company name"
|
||||||
|
/>
|
||||||
{errors.company ? <FormHelperText>{errors.company.message}</FormHelperText> : null}
|
{errors.company ? <FormHelperText>{errors.company.message}</FormHelperText> : null}
|
||||||
</FormControl>
|
</FormControl>
|
||||||
)}
|
)}
|
||||||
@@ -276,8 +312,9 @@ export function TeacherCreateForm(): React.JSX.Element {
|
|||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
{/* */}
|
||||||
<Stack spacing={3}>
|
<Stack spacing={3}>
|
||||||
<Typography variant="h6">Billing information</Typography>
|
<Typography variant="h6">{t('create.billing-information')}</Typography>
|
||||||
<Grid
|
<Grid
|
||||||
container
|
container
|
||||||
spacing={3}
|
spacing={3}
|
||||||
@@ -296,10 +333,12 @@ export function TeacherCreateForm(): React.JSX.Element {
|
|||||||
>
|
>
|
||||||
<InputLabel required>Country</InputLabel>
|
<InputLabel required>Country</InputLabel>
|
||||||
<Select {...field}>
|
<Select {...field}>
|
||||||
<Option value="">Choose a country</Option>
|
<MenuItem value="">Choose a country</MenuItem>
|
||||||
<Option value="us">United States</Option>
|
<MenuItem value="US">United States</MenuItem>
|
||||||
<Option value="de">Germany</Option>
|
<MenuItem value="UK">United Kingdom</MenuItem>
|
||||||
<Option value="es">Spain</Option>
|
<MenuItem value="CA">Canada</MenuItem>
|
||||||
|
<MenuItem value="DE">Germany</MenuItem>
|
||||||
|
<MenuItem value="ES">Spain</MenuItem>
|
||||||
</Select>
|
</Select>
|
||||||
{errors.billingAddress?.country ? (
|
{errors.billingAddress?.country ? (
|
||||||
<FormHelperText>{errors.billingAddress?.country?.message}</FormHelperText>
|
<FormHelperText>{errors.billingAddress?.country?.message}</FormHelperText>
|
||||||
@@ -362,7 +401,7 @@ export function TeacherCreateForm(): React.JSX.Element {
|
|||||||
error={Boolean(errors.billingAddress?.zipCode)}
|
error={Boolean(errors.billingAddress?.zipCode)}
|
||||||
fullWidth
|
fullWidth
|
||||||
>
|
>
|
||||||
<InputLabel required>Zip code</InputLabel>
|
<InputLabel required>{t('create.zip-code')}</InputLabel>
|
||||||
<OutlinedInput {...field} />
|
<OutlinedInput {...field} />
|
||||||
{errors.billingAddress?.zipCode ? (
|
{errors.billingAddress?.zipCode ? (
|
||||||
<FormHelperText>{errors.billingAddress?.zipCode?.message}</FormHelperText>
|
<FormHelperText>{errors.billingAddress?.zipCode?.message}</FormHelperText>
|
||||||
@@ -383,7 +422,7 @@ export function TeacherCreateForm(): React.JSX.Element {
|
|||||||
error={Boolean(errors.billingAddress?.line1)}
|
error={Boolean(errors.billingAddress?.line1)}
|
||||||
fullWidth
|
fullWidth
|
||||||
>
|
>
|
||||||
<InputLabel required>Address</InputLabel>
|
<InputLabel required>{t('create.address-line-1')}</InputLabel>
|
||||||
<OutlinedInput {...field} />
|
<OutlinedInput {...field} />
|
||||||
{errors.billingAddress?.line1 ? (
|
{errors.billingAddress?.line1 ? (
|
||||||
<FormHelperText>{errors.billingAddress?.line1?.message}</FormHelperText>
|
<FormHelperText>{errors.billingAddress?.line1?.message}</FormHelperText>
|
||||||
@@ -424,7 +463,7 @@ export function TeacherCreateForm(): React.JSX.Element {
|
|||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Stack spacing={3}>
|
<Stack spacing={3}>
|
||||||
<Typography variant="h6">Additional information</Typography>
|
<Typography variant="h6">{t('create.additional-information')}</Typography>
|
||||||
<Grid
|
<Grid
|
||||||
container
|
container
|
||||||
spacing={3}
|
spacing={3}
|
||||||
@@ -443,10 +482,14 @@ export function TeacherCreateForm(): React.JSX.Element {
|
|||||||
>
|
>
|
||||||
<InputLabel required>Timezone</InputLabel>
|
<InputLabel required>Timezone</InputLabel>
|
||||||
<Select {...field}>
|
<Select {...field}>
|
||||||
<Option value="">Select a timezone</Option>
|
<MenuItem value="">Select a timezone</MenuItem>
|
||||||
<Option value="new_york">US - New York</Option>
|
<MenuItem value="Europe/London">London</MenuItem>
|
||||||
<Option value="california">US - California</Option>
|
<MenuItem value="Asia/Tokyo">Tokyo</MenuItem>
|
||||||
<Option value="london">UK - London</Option>
|
<MenuItem value="America/Boa_Vista">Boa Vista</MenuItem>
|
||||||
|
<MenuItem value="America/Grand_Turk">Grand Turk</MenuItem>
|
||||||
|
<MenuItem value="Asia/Manila">Manila</MenuItem>
|
||||||
|
<MenuItem value="Asia/Urumqi">Urumqi</MenuItem>
|
||||||
|
<MenuItem value="Africa/Tunis">Tunis</MenuItem>
|
||||||
</Select>
|
</Select>
|
||||||
{errors.timezone ? <FormHelperText>{errors.timezone.message}</FormHelperText> : null}
|
{errors.timezone ? <FormHelperText>{errors.timezone.message}</FormHelperText> : null}
|
||||||
</FormControl>
|
</FormControl>
|
||||||
@@ -467,10 +510,11 @@ export function TeacherCreateForm(): React.JSX.Element {
|
|||||||
>
|
>
|
||||||
<InputLabel required>Language</InputLabel>
|
<InputLabel required>Language</InputLabel>
|
||||||
<Select {...field}>
|
<Select {...field}>
|
||||||
<Option value="">Select a language</Option>
|
<MenuItem value="">Select a language</MenuItem>
|
||||||
<Option value="en">English</Option>
|
<MenuItem value="en">English</MenuItem>
|
||||||
<Option value="es">Spanish</Option>
|
<MenuItem value="es">Spanish</MenuItem>
|
||||||
<Option value="de">German</Option>
|
<MenuItem value="de">German</MenuItem>
|
||||||
|
<MenuItem value="fr">French</MenuItem>
|
||||||
</Select>
|
</Select>
|
||||||
{errors.language ? <FormHelperText>{errors.language.message}</FormHelperText> : null}
|
{errors.language ? <FormHelperText>{errors.language.message}</FormHelperText> : null}
|
||||||
</FormControl>
|
</FormControl>
|
||||||
@@ -489,12 +533,12 @@ export function TeacherCreateForm(): React.JSX.Element {
|
|||||||
error={Boolean(errors.currency)}
|
error={Boolean(errors.currency)}
|
||||||
fullWidth
|
fullWidth
|
||||||
>
|
>
|
||||||
<InputLabel>Currency</InputLabel>
|
<InputLabel required>{t('create.currency')}</InputLabel>
|
||||||
<Select {...field}>
|
<Select {...field}>
|
||||||
<Option value="">Select a currency</Option>
|
<MenuItem value="">no currency selected</MenuItem>
|
||||||
<Option value="USD">USD</Option>
|
<MenuItem value="USD">USD</MenuItem>
|
||||||
<Option value="EUR">EUR</Option>
|
<MenuItem value="EUR">EUR</MenuItem>
|
||||||
<Option value="RON">RON</Option>
|
<MenuItem value="GBP">GBP</MenuItem>
|
||||||
</Select>
|
</Select>
|
||||||
{errors.currency ? <FormHelperText>{errors.currency.message}</FormHelperText> : null}
|
{errors.currency ? <FormHelperText>{errors.currency.message}</FormHelperText> : null}
|
||||||
</FormControl>
|
</FormControl>
|
||||||
@@ -511,14 +555,17 @@ export function TeacherCreateForm(): React.JSX.Element {
|
|||||||
component={RouterLink}
|
component={RouterLink}
|
||||||
href={paths.dashboard.teachers.list}
|
href={paths.dashboard.teachers.list}
|
||||||
>
|
>
|
||||||
Cancel
|
{t('create.cancelButton')}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
|
||||||
|
<LoadingButton
|
||||||
|
disabled={isUpdating}
|
||||||
|
loading={isUpdating}
|
||||||
type="submit"
|
type="submit"
|
||||||
variant="contained"
|
variant="contained"
|
||||||
>
|
>
|
||||||
Create teacher
|
{t('create.updateButton')}
|
||||||
</Button>
|
</LoadingButton>
|
||||||
</CardActions>
|
</CardActions>
|
||||||
</Card>
|
</Card>
|
||||||
<Box sx={{ display: isDevelopment ? 'block' : 'none' }}>
|
<Box sx={{ display: isDevelopment ? 'block' : 'none' }}>
|
||||||
|
@@ -1,10 +1,16 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
// src/components/dashboard/teacher/teacher-edit-form.tsx
|
||||||
|
// PURPOSE:
|
||||||
|
// handle change details for teachers collection
|
||||||
|
//
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import RouterLink from 'next/link';
|
import RouterLink from 'next/link';
|
||||||
import { useParams, useRouter } from 'next/navigation';
|
import { useParams, useRouter } from 'next/navigation';
|
||||||
//
|
//
|
||||||
import { COL_TEACHERS, COL_USER_METAS } from '@/constants';
|
import { UpdateBillingAddressById } from '@/db/billingAddress/UpdateById';
|
||||||
|
import { getTeacherById } from '@/db/Teachers/GetById';
|
||||||
|
import { UpdateTeacherById } from '@/db/Teachers/UpdateById';
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { LoadingButton } from '@mui/lab';
|
import { LoadingButton } from '@mui/lab';
|
||||||
//
|
//
|
||||||
@@ -32,17 +38,18 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { z as zod } from 'zod';
|
import { z as zod } from 'zod';
|
||||||
|
|
||||||
import { paths } from '@/paths';
|
import { paths } from '@/paths';
|
||||||
|
import isDevelopment from '@/lib/check-is-development';
|
||||||
import { logger } from '@/lib/default-logger';
|
import { logger } from '@/lib/default-logger';
|
||||||
import { base64ToFile, fileToBase64 } from '@/lib/file-to-base64';
|
import { base64ToFile, fileToBase64 } from '@/lib/file-to-base64';
|
||||||
import { pb } from '@/lib/pb';
|
import getImageUrlFromFile from '@/lib/get-image-url-from-file.ts';
|
||||||
import { toast } from '@/components/core/toaster';
|
import { toast } from '@/components/core/toaster';
|
||||||
import FormLoading from '@/components/loading';
|
import FormLoading from '@/components/loading';
|
||||||
|
|
||||||
// import ErrorDisplay from '../../error';
|
// import ErrorDisplay from '../../error';
|
||||||
import ErrorDisplay from '../error';
|
import ErrorDisplay from '../error';
|
||||||
import isDevelopment from '@/lib/check-is-development';
|
import type { Teacher } from './type.d';
|
||||||
|
|
||||||
// TODO: review this
|
// TODO: review schema
|
||||||
const schema = zod.object({
|
const schema = zod.object({
|
||||||
name: zod.string().min(1, 'Name is required').max(255),
|
name: zod.string().min(1, 'Name is required').max(255),
|
||||||
email: zod.string().email('Must be a valid email').min(1, 'Email is required').max(255),
|
email: zod.string().email('Must be a valid email').min(1, 'Email is required').max(255),
|
||||||
@@ -87,7 +94,7 @@ const defaultValues = {
|
|||||||
|
|
||||||
export function TeacherEditForm(): React.JSX.Element {
|
export function TeacherEditForm(): React.JSX.Element {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { t } = useTranslation(['lp_categories']);
|
const { t } = useTranslation(['teachers']);
|
||||||
|
|
||||||
const { id: teacherId } = useParams<{ id: string }>();
|
const { id: teacherId } = useParams<{ id: string }>();
|
||||||
//
|
//
|
||||||
@@ -95,6 +102,7 @@ export function TeacherEditForm(): React.JSX.Element {
|
|||||||
const [showLoading, setShowLoading] = React.useState<boolean>(false);
|
const [showLoading, setShowLoading] = React.useState<boolean>(false);
|
||||||
//
|
//
|
||||||
const [showError, setShowError] = React.useState({ show: false, detail: '' });
|
const [showError, setShowError] = React.useState({ show: false, detail: '' });
|
||||||
|
const [billingAddressId, setBillingAddressId] = React.useState<string | null>(null);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
control,
|
control,
|
||||||
@@ -114,7 +122,9 @@ export function TeacherEditForm(): React.JSX.Element {
|
|||||||
email: values.email,
|
email: values.email,
|
||||||
phone: values.phone,
|
phone: values.phone,
|
||||||
company: values.company,
|
company: values.company,
|
||||||
billingAddress: values.billingAddress,
|
//
|
||||||
|
// billingAddress: values.billingAddress,
|
||||||
|
//
|
||||||
taxId: values.taxId,
|
taxId: values.taxId,
|
||||||
timezone: values.timezone,
|
timezone: values.timezone,
|
||||||
language: values.language,
|
language: values.language,
|
||||||
@@ -123,12 +133,17 @@ export function TeacherEditForm(): React.JSX.Element {
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await pb.collection(COL_USER_METAS).update(teacherId, updateData);
|
await UpdateTeacherById(teacherId, updateData);
|
||||||
toast.success('Teacher updated successfully');
|
//
|
||||||
|
toast.success(t('teacher-updated-successfully'));
|
||||||
router.push(paths.dashboard.teachers.list);
|
router.push(paths.dashboard.teachers.list);
|
||||||
|
|
||||||
|
if (billingAddressId) {
|
||||||
|
await UpdateBillingAddressById(billingAddressId, values.billingAddress);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
toast.error('Failed to update teacher');
|
toast.error(t('failed-to-update-teacher'));
|
||||||
} finally {
|
} finally {
|
||||||
setIsUpdating(false);
|
setIsUpdating(false);
|
||||||
}
|
}
|
||||||
@@ -162,21 +177,21 @@ export function TeacherEditForm(): React.JSX.Element {
|
|||||||
setShowLoading(true);
|
setShowLoading(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await pb.collection(COL_USER_METAS).getOne(id);
|
const result = (await getTeacherById(id)) as unknown as Teacher;
|
||||||
|
//
|
||||||
reset({ ...defaultValues, ...result });
|
reset({ ...defaultValues, ...result });
|
||||||
console.log({ result });
|
|
||||||
|
setBillingAddressId(result.billingAddress.id);
|
||||||
|
|
||||||
if (result.avatar) {
|
if (result.avatar) {
|
||||||
const fetchResult = await fetch(
|
const fetchResult = await fetch(getImageUrlFromFile(result.collectionId, result.id, result.avatar));
|
||||||
`http://127.0.0.1:8090/api/files/${result.collectionId}/${result.id}/${result.avatar}`
|
|
||||||
);
|
|
||||||
const blob = await fetchResult.blob();
|
const blob = await fetchResult.blob();
|
||||||
const url = await fileToBase64(blob);
|
const url = await fileToBase64(blob);
|
||||||
setValue('avatar', url);
|
setValue('avatar', url);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
toast.error('Failed to load teacher data');
|
toast.error(t('failed-to-load-teacher-data'));
|
||||||
setShowError({ show: true, detail: JSON.stringify(error, null, 2) });
|
setShowError({ show: true, detail: JSON.stringify(error, null, 2) });
|
||||||
} finally {
|
} finally {
|
||||||
setShowLoading(false);
|
setShowLoading(false);
|
||||||
@@ -299,7 +314,7 @@ export function TeacherEditForm(): React.JSX.Element {
|
|||||||
error={Boolean(errors.email)}
|
error={Boolean(errors.email)}
|
||||||
fullWidth
|
fullWidth
|
||||||
>
|
>
|
||||||
<InputLabel required>Email</InputLabel>
|
<InputLabel required>{t('edit.email-address')}</InputLabel>
|
||||||
<OutlinedInput
|
<OutlinedInput
|
||||||
{...field}
|
{...field}
|
||||||
type="email"
|
type="email"
|
||||||
@@ -321,7 +336,7 @@ export function TeacherEditForm(): React.JSX.Element {
|
|||||||
error={Boolean(errors.phone)}
|
error={Boolean(errors.phone)}
|
||||||
fullWidth
|
fullWidth
|
||||||
>
|
>
|
||||||
<InputLabel required>Phone</InputLabel>
|
<InputLabel required>{t('edit.phone-number')}</InputLabel>
|
||||||
<OutlinedInput {...field} />
|
<OutlinedInput {...field} />
|
||||||
{errors.phone ? <FormHelperText>{errors.phone.message}</FormHelperText> : null}
|
{errors.phone ? <FormHelperText>{errors.phone.message}</FormHelperText> : null}
|
||||||
</FormControl>
|
</FormControl>
|
||||||
@@ -350,11 +365,12 @@ export function TeacherEditForm(): React.JSX.Element {
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
{/* */}
|
||||||
</Grid>
|
</Grid>
|
||||||
</Stack>
|
</Stack>
|
||||||
{/* */}
|
{/* */}
|
||||||
<Stack spacing={3}>
|
<Stack spacing={3}>
|
||||||
<Typography variant="h6">Billing Information</Typography>
|
<Typography variant="h6">{t('edit.billing-information')}</Typography>
|
||||||
<Grid
|
<Grid
|
||||||
container
|
container
|
||||||
spacing={3}
|
spacing={3}
|
||||||
@@ -373,9 +389,12 @@ export function TeacherEditForm(): React.JSX.Element {
|
|||||||
>
|
>
|
||||||
<InputLabel required>Country</InputLabel>
|
<InputLabel required>Country</InputLabel>
|
||||||
<Select {...field}>
|
<Select {...field}>
|
||||||
|
<MenuItem value="">No Country selected</MenuItem>
|
||||||
<MenuItem value="US">United States</MenuItem>
|
<MenuItem value="US">United States</MenuItem>
|
||||||
<MenuItem value="UK">United Kingdom</MenuItem>
|
<MenuItem value="UK">United Kingdom</MenuItem>
|
||||||
<MenuItem value="CA">Canada</MenuItem>
|
<MenuItem value="CA">Canada</MenuItem>
|
||||||
|
<MenuItem value="DE">Germany</MenuItem>
|
||||||
|
<MenuItem value="ES">Spain</MenuItem>
|
||||||
</Select>
|
</Select>
|
||||||
{errors.billingAddress?.country ? (
|
{errors.billingAddress?.country ? (
|
||||||
<FormHelperText>{errors.billingAddress.country.message}</FormHelperText>
|
<FormHelperText>{errors.billingAddress.country.message}</FormHelperText>
|
||||||
@@ -438,7 +457,7 @@ export function TeacherEditForm(): React.JSX.Element {
|
|||||||
error={Boolean(errors.billingAddress?.zipCode)}
|
error={Boolean(errors.billingAddress?.zipCode)}
|
||||||
fullWidth
|
fullWidth
|
||||||
>
|
>
|
||||||
<InputLabel required>Zip Code</InputLabel>
|
<InputLabel required>{t('edit.zip-code')}</InputLabel>
|
||||||
<OutlinedInput {...field} />
|
<OutlinedInput {...field} />
|
||||||
{errors.billingAddress?.zipCode ? (
|
{errors.billingAddress?.zipCode ? (
|
||||||
<FormHelperText>{errors.billingAddress.zipCode.message}</FormHelperText>
|
<FormHelperText>{errors.billingAddress.zipCode.message}</FormHelperText>
|
||||||
@@ -459,7 +478,7 @@ export function TeacherEditForm(): React.JSX.Element {
|
|||||||
error={Boolean(errors.billingAddress?.line1)}
|
error={Boolean(errors.billingAddress?.line1)}
|
||||||
fullWidth
|
fullWidth
|
||||||
>
|
>
|
||||||
<InputLabel required>Address Line 1</InputLabel>
|
<InputLabel required>{t('edit.address-line-1')}</InputLabel>
|
||||||
<OutlinedInput {...field} />
|
<OutlinedInput {...field} />
|
||||||
{errors.billingAddress?.line1 ? (
|
{errors.billingAddress?.line1 ? (
|
||||||
<FormHelperText>{errors.billingAddress.line1.message}</FormHelperText>
|
<FormHelperText>{errors.billingAddress.line1.message}</FormHelperText>
|
||||||
@@ -494,7 +513,7 @@ export function TeacherEditForm(): React.JSX.Element {
|
|||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
<Stack spacing={3}>
|
<Stack spacing={3}>
|
||||||
<Typography variant="h6">Additional Information</Typography>
|
<Typography variant="h6">{t('edit.additional-information')}</Typography>
|
||||||
<Grid
|
<Grid
|
||||||
container
|
container
|
||||||
spacing={3}
|
spacing={3}
|
||||||
@@ -541,8 +560,10 @@ export function TeacherEditForm(): React.JSX.Element {
|
|||||||
>
|
>
|
||||||
<InputLabel required>Language</InputLabel>
|
<InputLabel required>Language</InputLabel>
|
||||||
<Select {...field}>
|
<Select {...field}>
|
||||||
|
<MenuItem value="">no language selected</MenuItem>
|
||||||
<MenuItem value="en">English</MenuItem>
|
<MenuItem value="en">English</MenuItem>
|
||||||
<MenuItem value="es">Spanish</MenuItem>
|
<MenuItem value="es">Spanish</MenuItem>
|
||||||
|
<MenuItem value="de">German</MenuItem>
|
||||||
<MenuItem value="fr">French</MenuItem>
|
<MenuItem value="fr">French</MenuItem>
|
||||||
</Select>
|
</Select>
|
||||||
{errors.language ? <FormHelperText>{errors.language.message}</FormHelperText> : null}
|
{errors.language ? <FormHelperText>{errors.language.message}</FormHelperText> : null}
|
||||||
@@ -562,8 +583,9 @@ export function TeacherEditForm(): React.JSX.Element {
|
|||||||
error={Boolean(errors.currency)}
|
error={Boolean(errors.currency)}
|
||||||
fullWidth
|
fullWidth
|
||||||
>
|
>
|
||||||
<InputLabel required>Currency</InputLabel>
|
<InputLabel required>{t('edit.currency')}</InputLabel>
|
||||||
<Select {...field}>
|
<Select {...field}>
|
||||||
|
<MenuItem value="">no currency selected</MenuItem>
|
||||||
<MenuItem value="USD">USD</MenuItem>
|
<MenuItem value="USD">USD</MenuItem>
|
||||||
<MenuItem value="EUR">EUR</MenuItem>
|
<MenuItem value="EUR">EUR</MenuItem>
|
||||||
<MenuItem value="GBP">GBP</MenuItem>
|
<MenuItem value="GBP">GBP</MenuItem>
|
||||||
|
@@ -1,5 +1,9 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
// src/components/dashboard/teacher/teachers-table.tsx
|
||||||
|
// PURPOSE:
|
||||||
|
// handle change details for teachers collection
|
||||||
|
//
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import RouterLink from 'next/link';
|
import RouterLink from 'next/link';
|
||||||
import { LoadingButton } from '@mui/lab';
|
import { LoadingButton } from '@mui/lab';
|
||||||
@@ -213,7 +217,6 @@ export function TeachersTable({ rows, reloadRows }: TeachersTableProps): React.J
|
|||||||
sx={{ textAlign: 'center' }}
|
sx={{ textAlign: 'center' }}
|
||||||
variant="body2"
|
variant="body2"
|
||||||
>
|
>
|
||||||
{/* TODO: update this */}
|
|
||||||
{t('no-teachers-found')}
|
{t('no-teachers-found')}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
|
@@ -31,21 +31,23 @@ export interface CreateFormProps {
|
|||||||
email: string;
|
email: string;
|
||||||
phone?: string;
|
phone?: string;
|
||||||
company?: string;
|
company?: string;
|
||||||
billingAddress?: {
|
// handle seperately
|
||||||
country: string;
|
// billingAddress?: {
|
||||||
state: string;
|
// country: string;
|
||||||
city: string;
|
// state: string;
|
||||||
zipCode: string;
|
// city: string;
|
||||||
line1: string;
|
// zipCode: string;
|
||||||
line2?: string;
|
// line1: string;
|
||||||
};
|
// line2?: string;
|
||||||
|
// };
|
||||||
taxId?: string;
|
taxId?: string;
|
||||||
timezone: string;
|
timezone: string;
|
||||||
language: string;
|
language: string;
|
||||||
currency: string;
|
currency: string;
|
||||||
avatar?: string;
|
avatar?: File | null;
|
||||||
// quota?: number;
|
// quota?: number;
|
||||||
// status?: 'pending' | 'active' | 'blocked';
|
state?: 'pending' | 'active' | 'blocked';
|
||||||
|
meta: Record<string, null>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// RULES: form data structure for editing existing teacher
|
// RULES: form data structure for editing existing teacher
|
||||||
@@ -77,6 +79,8 @@ export interface TeachersFiltersProps {
|
|||||||
sortDir?: SortDir;
|
sortDir?: SortDir;
|
||||||
fullData: Teacher[];
|
fullData: Teacher[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RULES: available filter options for student data
|
||||||
export interface Filters {
|
export interface Filters {
|
||||||
email?: string;
|
email?: string;
|
||||||
phone?: string;
|
phone?: string;
|
||||||
|
@@ -32,6 +32,7 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { z as zod } from 'zod';
|
import { z as zod } from 'zod';
|
||||||
|
|
||||||
import { paths } from '@/paths';
|
import { paths } from '@/paths';
|
||||||
|
import isDevelopment from '@/lib/check-is-development';
|
||||||
import { logger } from '@/lib/default-logger';
|
import { logger } from '@/lib/default-logger';
|
||||||
import { base64ToFile, fileToBase64 } from '@/lib/file-to-base64';
|
import { base64ToFile, fileToBase64 } from '@/lib/file-to-base64';
|
||||||
import { pb } from '@/lib/pb';
|
import { pb } from '@/lib/pb';
|
||||||
@@ -40,7 +41,6 @@ import FormLoading from '@/components/loading';
|
|||||||
|
|
||||||
// import ErrorDisplay from '../../error';
|
// import ErrorDisplay from '../../error';
|
||||||
import ErrorDisplay from '../error';
|
import ErrorDisplay from '../error';
|
||||||
import isDevelopment from '@/lib/check-is-development';
|
|
||||||
|
|
||||||
// TODO: review this
|
// TODO: review this
|
||||||
const schema = zod.object({
|
const schema = zod.object({
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
// empty valur for customer
|
// empty valur for customer
|
||||||
|
|
||||||
import { dayjs } from '@/lib/dayjs';
|
import { dayjs } from '@/lib/dayjs';
|
||||||
|
|
||||||
import type { UserMeta } from './type.d';
|
import type { UserMeta } from './type.d';
|
||||||
|
|
||||||
export const defaultUserMeta: UserMeta = {
|
export const defaultUserMeta: UserMeta = {
|
||||||
|
@@ -1,9 +1,41 @@
|
|||||||
'use client';
|
// src/components/dashboard/user_meta/type.d.tsx
|
||||||
|
|
||||||
|
// RULES: sorting direction for user meta lists
|
||||||
|
import type { BillingAddress } from '@/db/billingAddress/type';
|
||||||
|
|
||||||
// RULES: sorting direction for teacher lists
|
// RULES: sorting direction for teacher lists
|
||||||
export type SortDir = 'asc' | 'desc';
|
export type SortDir = 'asc' | 'desc';
|
||||||
|
|
||||||
// RULES: core teacher data structure
|
export interface DBUserMeta {
|
||||||
|
name: string;
|
||||||
|
//
|
||||||
|
// NOTE: obslete "avatar" and use "avatar_file"
|
||||||
|
avatar?: string;
|
||||||
|
avatar_file?: string;
|
||||||
|
//
|
||||||
|
email: string;
|
||||||
|
phone: string;
|
||||||
|
quota: number;
|
||||||
|
company: string;
|
||||||
|
//
|
||||||
|
// billingAddress: BillingAddress[] | [];
|
||||||
|
expand: { billingAddress?: BillingAddress[] };
|
||||||
|
|
||||||
|
// status is obsoleted, replace by state
|
||||||
|
status: 'pending' | 'active' | 'blocked';
|
||||||
|
state: 'pending' | 'active' | 'blocked';
|
||||||
|
//
|
||||||
|
timezone: string;
|
||||||
|
language: string;
|
||||||
|
currency: string;
|
||||||
|
//
|
||||||
|
id: string;
|
||||||
|
created: string;
|
||||||
|
updated?: string;
|
||||||
|
collectionId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// RULES: core user meta data structure
|
||||||
export interface UserMeta {
|
export interface UserMeta {
|
||||||
name: string;
|
name: string;
|
||||||
//
|
//
|
||||||
@@ -14,23 +46,32 @@ export interface UserMeta {
|
|||||||
email: string;
|
email: string;
|
||||||
phone?: string;
|
phone?: string;
|
||||||
quota: number;
|
quota: number;
|
||||||
|
company?: string;
|
||||||
|
//
|
||||||
|
billingAddress: BillingAddress | Record<string, never>;
|
||||||
|
|
||||||
// status is obsoleted, replace by state
|
// status is obsoleted, replace by state
|
||||||
status: 'pending' | 'active' | 'blocked';
|
status: 'pending' | 'active' | 'blocked';
|
||||||
state: 'pending' | 'active' | 'blocked';
|
state: 'pending' | 'active' | 'blocked';
|
||||||
//
|
//
|
||||||
|
timezone: string;
|
||||||
|
language: string;
|
||||||
|
currency: string;
|
||||||
|
//
|
||||||
id: string;
|
id: string;
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
updatedAt?: Date;
|
updatedAt?: Date;
|
||||||
collectionId: string;
|
collectionId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// RULES: form data structure for creating new teacher
|
// RULES: form data structure for creating new user meta
|
||||||
export interface CreateFormProps {
|
export interface CreateFormProps {
|
||||||
name: string;
|
name: string;
|
||||||
email: string;
|
email: string;
|
||||||
phone?: string;
|
phone?: string;
|
||||||
company?: string;
|
company?: string;
|
||||||
|
//
|
||||||
|
// handle seperately ?
|
||||||
billingAddress?: {
|
billingAddress?: {
|
||||||
country: string;
|
country: string;
|
||||||
state: string;
|
state: string;
|
||||||
@@ -39,6 +80,7 @@ export interface CreateFormProps {
|
|||||||
line1: string;
|
line1: string;
|
||||||
line2?: string;
|
line2?: string;
|
||||||
};
|
};
|
||||||
|
//
|
||||||
taxId?: string;
|
taxId?: string;
|
||||||
timezone: string;
|
timezone: string;
|
||||||
language: string;
|
language: string;
|
||||||
@@ -48,7 +90,7 @@ export interface CreateFormProps {
|
|||||||
// status?: 'pending' | 'active' | 'blocked';
|
// status?: 'pending' | 'active' | 'blocked';
|
||||||
}
|
}
|
||||||
|
|
||||||
// RULES: form data structure for editing existing teacher
|
// RULES: form data structure for editing existing user meta
|
||||||
export interface EditFormProps {
|
export interface EditFormProps {
|
||||||
name: string;
|
name: string;
|
||||||
email: string;
|
email: string;
|
||||||
@@ -71,12 +113,13 @@ export interface EditFormProps {
|
|||||||
// status?: 'pending' | 'active' | 'blocked';
|
// status?: 'pending' | 'active' | 'blocked';
|
||||||
}
|
}
|
||||||
|
|
||||||
// RULES: filter props for teacher search and filtering
|
// RULES: filter props for user meta search and filtering
|
||||||
export interface UserMetasFiltersProps {
|
export interface UserMetasFiltersProps {
|
||||||
filters?: Filters;
|
filters?: Filters;
|
||||||
sortDir?: SortDir;
|
sortDir?: SortDir;
|
||||||
fullData: UserMeta[];
|
fullData: UserMeta[];
|
||||||
}
|
}
|
||||||
|
// RULES: available filter options for user meta data
|
||||||
export interface Filters {
|
export interface Filters {
|
||||||
email?: string;
|
email?: string;
|
||||||
phone?: string;
|
phone?: string;
|
@@ -0,0 +1,193 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
//
|
||||||
|
// src/components/dashboard/user_meta/user-activation-edit-form.tsx
|
||||||
|
// RULES
|
||||||
|
// handle user change activation of other users
|
||||||
|
//
|
||||||
|
import * as React from 'react';
|
||||||
|
import RouterLink from 'next/link';
|
||||||
|
import { useParams, useRouter } from 'next/navigation';
|
||||||
|
//
|
||||||
|
import { COL_USERS } from '@/constants';
|
||||||
|
import { getUserById } from '@/db/Users/GetById';
|
||||||
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
|
import { LoadingButton } from '@mui/lab';
|
||||||
|
//
|
||||||
|
import Box from '@mui/material/Box';
|
||||||
|
import Button from '@mui/material/Button';
|
||||||
|
import Card from '@mui/material/Card';
|
||||||
|
import CardActions from '@mui/material/CardActions';
|
||||||
|
import CardContent from '@mui/material/CardContent';
|
||||||
|
import Divider from '@mui/material/Divider';
|
||||||
|
import FormControl from '@mui/material/FormControl';
|
||||||
|
import FormHelperText from '@mui/material/FormHelperText';
|
||||||
|
import InputLabel from '@mui/material/InputLabel';
|
||||||
|
import MenuItem from '@mui/material/MenuItem';
|
||||||
|
import Select from '@mui/material/Select';
|
||||||
|
import Stack from '@mui/material/Stack';
|
||||||
|
//
|
||||||
|
//
|
||||||
|
import { Controller, useForm } from 'react-hook-form';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { z as zod } from 'zod';
|
||||||
|
|
||||||
|
import { paths } from '@/paths';
|
||||||
|
import isDevelopment from '@/lib/check-is-development';
|
||||||
|
import { logger } from '@/lib/default-logger';
|
||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
import { toast } from '@/components/core/toaster';
|
||||||
|
import FormLoading from '@/components/loading';
|
||||||
|
|
||||||
|
// import ErrorDisplay from '../../error';
|
||||||
|
import ErrorDisplay from '../error';
|
||||||
|
|
||||||
|
// TODO: review this
|
||||||
|
const schema = zod.object({
|
||||||
|
verified: zod.string(),
|
||||||
|
});
|
||||||
|
|
||||||
|
type Values = zod.infer<typeof schema>;
|
||||||
|
|
||||||
|
const defaultValues = {
|
||||||
|
verified: 'false',
|
||||||
|
} satisfies Values;
|
||||||
|
|
||||||
|
export function UserActivationEditForm({ userId }: { userId: string }): React.JSX.Element {
|
||||||
|
const router = useRouter();
|
||||||
|
const { t } = useTranslation(['user_metas']);
|
||||||
|
|
||||||
|
const { id: userMetaId } = useParams<{ id: string }>();
|
||||||
|
//
|
||||||
|
const [isUpdating, setIsUpdating] = React.useState<boolean>(false);
|
||||||
|
const [showLoading, setShowLoading] = React.useState<boolean>(false);
|
||||||
|
//
|
||||||
|
const [showError, setShowError] = React.useState({ show: false, detail: '' });
|
||||||
|
|
||||||
|
const {
|
||||||
|
control,
|
||||||
|
handleSubmit,
|
||||||
|
formState: { errors },
|
||||||
|
setValue,
|
||||||
|
reset,
|
||||||
|
watch,
|
||||||
|
} = useForm<Values>({ defaultValues, resolver: zodResolver(schema) });
|
||||||
|
|
||||||
|
const onSubmit = React.useCallback(
|
||||||
|
async (values: Values): Promise<void> => {
|
||||||
|
setIsUpdating(true);
|
||||||
|
|
||||||
|
const updateData = {
|
||||||
|
verified: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
await pb.collection(COL_USERS).update(userId, updateData);
|
||||||
|
|
||||||
|
toast.success(t('user-updated-successfully'));
|
||||||
|
// router.push(paths.dashboard.user_metas.list);
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
toast.error(t('failed-to-update-user-meta'));
|
||||||
|
} finally {
|
||||||
|
setIsUpdating(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[userMetaId, router]
|
||||||
|
);
|
||||||
|
|
||||||
|
// TODO: need to align with save form
|
||||||
|
// use trycatch
|
||||||
|
const [textDescription, setTextDescription] = React.useState<string>('');
|
||||||
|
const [textRemarks, setTextRemarks] = React.useState<string>('');
|
||||||
|
|
||||||
|
// load existing data when user arrive
|
||||||
|
const loadExistingData = React.useCallback(
|
||||||
|
async (id: string) => {
|
||||||
|
try {
|
||||||
|
const result = await getUserById(userId);
|
||||||
|
reset({ verified: result.verified.toString() });
|
||||||
|
|
||||||
|
setShowLoading(false);
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
toast.error('failed-to-load-user-meta-data');
|
||||||
|
setShowError({ show: true, detail: JSON.stringify(error, null, 2) });
|
||||||
|
} finally {
|
||||||
|
setShowLoading(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[reset, setValue]
|
||||||
|
);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
void loadExistingData(userId);
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [userId]);
|
||||||
|
|
||||||
|
if (showLoading) return <FormLoading />;
|
||||||
|
if (showError.show)
|
||||||
|
return (
|
||||||
|
<ErrorDisplay
|
||||||
|
message={t('error.unable-to-process-request')}
|
||||||
|
code="500"
|
||||||
|
details={showError.detail}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form onSubmit={handleSubmit(onSubmit)}>
|
||||||
|
<Card>
|
||||||
|
<CardContent>
|
||||||
|
<Stack
|
||||||
|
divider={<Divider />}
|
||||||
|
spacing={4}
|
||||||
|
>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="verified"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormControl
|
||||||
|
error={Boolean(errors.verified)}
|
||||||
|
fullWidth
|
||||||
|
>
|
||||||
|
<InputLabel required>
|
||||||
|
{t('user-activation')} {t('optional')}
|
||||||
|
</InputLabel>
|
||||||
|
<Select {...field}>
|
||||||
|
<MenuItem value="true">{t('activated')}</MenuItem>
|
||||||
|
<MenuItem value="false">{t('not-actviate')}</MenuItem>
|
||||||
|
</Select>
|
||||||
|
{errors.verified ? <FormHelperText>{errors.verified.message}</FormHelperText> : null}
|
||||||
|
</FormControl>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
</CardContent>
|
||||||
|
<CardActions sx={{ justifyContent: 'flex-end' }}>
|
||||||
|
<div>
|
||||||
|
<Button
|
||||||
|
color="secondary"
|
||||||
|
component={RouterLink}
|
||||||
|
href={paths.dashboard.user_metas.list}
|
||||||
|
>
|
||||||
|
{t('edit.cancelButton')}
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<LoadingButton
|
||||||
|
disabled={isUpdating}
|
||||||
|
loading={isUpdating}
|
||||||
|
type="submit"
|
||||||
|
variant="contained"
|
||||||
|
>
|
||||||
|
{t('edit.updateButton')}
|
||||||
|
</LoadingButton>
|
||||||
|
</div>
|
||||||
|
</CardActions>
|
||||||
|
</Card>
|
||||||
|
<Box sx={{ display: isDevelopment ? 'block' : 'none' }}>
|
||||||
|
<pre>{JSON.stringify({ errors }, null, 2)}</pre>
|
||||||
|
</Box>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
}
|
@@ -1,10 +1,16 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
// src/components/dashboard/user_meta/user-meta-edit-form.tsx
|
||||||
|
// PURPOSE:
|
||||||
|
// handle change details for user meta collection
|
||||||
|
//
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import RouterLink from 'next/link';
|
import RouterLink from 'next/link';
|
||||||
import { useParams, useRouter } from 'next/navigation';
|
import { useParams, useRouter } from 'next/navigation';
|
||||||
//
|
//
|
||||||
import { COL_TEACHERS, COL_USER_METAS } from '@/constants';
|
import { UpdateBillingAddressById } from '@/db/billingAddress/UpdateById';
|
||||||
|
import { getUserMetaById } from '@/db/UserMetas/GetById';
|
||||||
|
import { UpdateUserMetaById } from '@/db/UserMetas/UpdateById';
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { LoadingButton } from '@mui/lab';
|
import { LoadingButton } from '@mui/lab';
|
||||||
//
|
//
|
||||||
@@ -32,17 +38,18 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { z as zod } from 'zod';
|
import { z as zod } from 'zod';
|
||||||
|
|
||||||
import { paths } from '@/paths';
|
import { paths } from '@/paths';
|
||||||
|
import isDevelopment from '@/lib/check-is-development';
|
||||||
import { logger } from '@/lib/default-logger';
|
import { logger } from '@/lib/default-logger';
|
||||||
import { base64ToFile, fileToBase64 } from '@/lib/file-to-base64';
|
import { base64ToFile, fileToBase64 } from '@/lib/file-to-base64';
|
||||||
import { pb } from '@/lib/pb';
|
import getImageUrlFromFile from '@/lib/get-image-url-from-file.ts';
|
||||||
import { toast } from '@/components/core/toaster';
|
import { toast } from '@/components/core/toaster';
|
||||||
import FormLoading from '@/components/loading';
|
import FormLoading from '@/components/loading';
|
||||||
|
|
||||||
// import ErrorDisplay from '../../error';
|
// import ErrorDisplay from '../../error';
|
||||||
import ErrorDisplay from '../error';
|
import ErrorDisplay from '../error';
|
||||||
import isDevelopment from '@/lib/check-is-development';
|
import type { UserMeta } from './type.d';
|
||||||
|
|
||||||
// TODO: review this
|
// TODO: review schema
|
||||||
const schema = zod.object({
|
const schema = zod.object({
|
||||||
name: zod.string().min(1, 'Name is required').max(255),
|
name: zod.string().min(1, 'Name is required').max(255),
|
||||||
email: zod.string().email('Must be a valid email').min(1, 'Email is required').max(255),
|
email: zod.string().email('Must be a valid email').min(1, 'Email is required').max(255),
|
||||||
@@ -87,14 +94,15 @@ const defaultValues = {
|
|||||||
|
|
||||||
export function UserMetaEditForm(): React.JSX.Element {
|
export function UserMetaEditForm(): React.JSX.Element {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { t } = useTranslation(['lp_categories']);
|
const { t } = useTranslation(['user_metas']);
|
||||||
|
|
||||||
const { id: teacherId } = useParams<{ id: string }>();
|
const { id: userMetaId } = useParams<{ id: string }>();
|
||||||
//
|
//
|
||||||
const [isUpdating, setIsUpdating] = React.useState<boolean>(false);
|
const [isUpdating, setIsUpdating] = React.useState<boolean>(false);
|
||||||
const [showLoading, setShowLoading] = React.useState<boolean>(false);
|
const [showLoading, setShowLoading] = React.useState<boolean>(false);
|
||||||
//
|
//
|
||||||
const [showError, setShowError] = React.useState({ show: false, detail: '' });
|
const [showError, setShowError] = React.useState({ show: false, detail: '' });
|
||||||
|
const [billingAddressId, setBillingAddressId] = React.useState<string | null>(null);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
control,
|
control,
|
||||||
@@ -114,7 +122,9 @@ export function UserMetaEditForm(): React.JSX.Element {
|
|||||||
email: values.email,
|
email: values.email,
|
||||||
phone: values.phone,
|
phone: values.phone,
|
||||||
company: values.company,
|
company: values.company,
|
||||||
billingAddress: values.billingAddress,
|
//
|
||||||
|
// billingAddress: values.billingAddress,
|
||||||
|
//
|
||||||
taxId: values.taxId,
|
taxId: values.taxId,
|
||||||
timezone: values.timezone,
|
timezone: values.timezone,
|
||||||
language: values.language,
|
language: values.language,
|
||||||
@@ -123,17 +133,22 @@ export function UserMetaEditForm(): React.JSX.Element {
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await pb.collection(COL_USER_METAS).update(teacherId, updateData);
|
await UpdateUserMetaById(userMetaId, updateData);
|
||||||
toast.success('Teacher updated successfully');
|
//
|
||||||
router.push(paths.dashboard.teachers.list);
|
toast.success(t('user-updated-successfully'));
|
||||||
|
router.push(paths.dashboard.user_metas.list);
|
||||||
|
|
||||||
|
if (billingAddressId) {
|
||||||
|
await UpdateBillingAddressById(billingAddressId, values.billingAddress);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
toast.error('Failed to update teacher');
|
toast.error(t('failed-to-update-user-meta'));
|
||||||
} finally {
|
} finally {
|
||||||
setIsUpdating(false);
|
setIsUpdating(false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[teacherId, router]
|
[userMetaId, router]
|
||||||
);
|
);
|
||||||
|
|
||||||
const avatarInputRef = React.useRef<HTMLInputElement>(null);
|
const avatarInputRef = React.useRef<HTMLInputElement>(null);
|
||||||
@@ -162,21 +177,21 @@ export function UserMetaEditForm(): React.JSX.Element {
|
|||||||
setShowLoading(true);
|
setShowLoading(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await pb.collection(COL_USER_METAS).getOne(id);
|
const result = (await getUserMetaById(id)) as unknown as UserMeta;
|
||||||
|
//
|
||||||
reset({ ...defaultValues, ...result });
|
reset({ ...defaultValues, ...result });
|
||||||
console.log({ result });
|
|
||||||
|
setBillingAddressId(result.billingAddress.id);
|
||||||
|
|
||||||
if (result.avatar) {
|
if (result.avatar) {
|
||||||
const fetchResult = await fetch(
|
const fetchResult = await fetch(getImageUrlFromFile(result.collectionId, result.id, result.avatar));
|
||||||
`http://127.0.0.1:8090/api/files/${result.collectionId}/${result.id}/${result.avatar}`
|
|
||||||
);
|
|
||||||
const blob = await fetchResult.blob();
|
const blob = await fetchResult.blob();
|
||||||
const url = await fileToBase64(blob);
|
const url = await fileToBase64(blob);
|
||||||
setValue('avatar', url);
|
setValue('avatar', url);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
toast.error('Failed to load teacher data');
|
toast.error(t('failed-to-load-user-meta-data'));
|
||||||
setShowError({ show: true, detail: JSON.stringify(error, null, 2) });
|
setShowError({ show: true, detail: JSON.stringify(error, null, 2) });
|
||||||
} finally {
|
} finally {
|
||||||
setShowLoading(false);
|
setShowLoading(false);
|
||||||
@@ -186,9 +201,9 @@ export function UserMetaEditForm(): React.JSX.Element {
|
|||||||
);
|
);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
void loadExistingData(teacherId);
|
void loadExistingData(userMetaId);
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [teacherId]);
|
}, [userMetaId]);
|
||||||
|
|
||||||
if (showLoading) return <FormLoading />;
|
if (showLoading) return <FormLoading />;
|
||||||
if (showError.show)
|
if (showError.show)
|
||||||
@@ -299,7 +314,7 @@ export function UserMetaEditForm(): React.JSX.Element {
|
|||||||
error={Boolean(errors.email)}
|
error={Boolean(errors.email)}
|
||||||
fullWidth
|
fullWidth
|
||||||
>
|
>
|
||||||
<InputLabel required>Email</InputLabel>
|
<InputLabel required>{t('edit.email-address')}</InputLabel>
|
||||||
<OutlinedInput
|
<OutlinedInput
|
||||||
{...field}
|
{...field}
|
||||||
type="email"
|
type="email"
|
||||||
@@ -321,7 +336,7 @@ export function UserMetaEditForm(): React.JSX.Element {
|
|||||||
error={Boolean(errors.phone)}
|
error={Boolean(errors.phone)}
|
||||||
fullWidth
|
fullWidth
|
||||||
>
|
>
|
||||||
<InputLabel required>Phone</InputLabel>
|
<InputLabel required>{t('edit.phone-number')}</InputLabel>
|
||||||
<OutlinedInput {...field} />
|
<OutlinedInput {...field} />
|
||||||
{errors.phone ? <FormHelperText>{errors.phone.message}</FormHelperText> : null}
|
{errors.phone ? <FormHelperText>{errors.phone.message}</FormHelperText> : null}
|
||||||
</FormControl>
|
</FormControl>
|
||||||
@@ -350,11 +365,12 @@ export function UserMetaEditForm(): React.JSX.Element {
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
{/* */}
|
||||||
</Grid>
|
</Grid>
|
||||||
</Stack>
|
</Stack>
|
||||||
{/* */}
|
{/* */}
|
||||||
<Stack spacing={3}>
|
<Stack spacing={3}>
|
||||||
<Typography variant="h6">Billing Information</Typography>
|
<Typography variant="h6">{t('edit.billing-information')}</Typography>
|
||||||
<Grid
|
<Grid
|
||||||
container
|
container
|
||||||
spacing={3}
|
spacing={3}
|
||||||
@@ -373,9 +389,12 @@ export function UserMetaEditForm(): React.JSX.Element {
|
|||||||
>
|
>
|
||||||
<InputLabel required>Country</InputLabel>
|
<InputLabel required>Country</InputLabel>
|
||||||
<Select {...field}>
|
<Select {...field}>
|
||||||
|
<MenuItem value="">No Country selected</MenuItem>
|
||||||
<MenuItem value="US">United States</MenuItem>
|
<MenuItem value="US">United States</MenuItem>
|
||||||
<MenuItem value="UK">United Kingdom</MenuItem>
|
<MenuItem value="UK">United Kingdom</MenuItem>
|
||||||
<MenuItem value="CA">Canada</MenuItem>
|
<MenuItem value="CA">Canada</MenuItem>
|
||||||
|
<MenuItem value="DE">Germany</MenuItem>
|
||||||
|
<MenuItem value="ES">Spain</MenuItem>
|
||||||
</Select>
|
</Select>
|
||||||
{errors.billingAddress?.country ? (
|
{errors.billingAddress?.country ? (
|
||||||
<FormHelperText>{errors.billingAddress.country.message}</FormHelperText>
|
<FormHelperText>{errors.billingAddress.country.message}</FormHelperText>
|
||||||
@@ -438,7 +457,7 @@ export function UserMetaEditForm(): React.JSX.Element {
|
|||||||
error={Boolean(errors.billingAddress?.zipCode)}
|
error={Boolean(errors.billingAddress?.zipCode)}
|
||||||
fullWidth
|
fullWidth
|
||||||
>
|
>
|
||||||
<InputLabel required>Zip Code</InputLabel>
|
<InputLabel required>{t('edit.zip-code')}</InputLabel>
|
||||||
<OutlinedInput {...field} />
|
<OutlinedInput {...field} />
|
||||||
{errors.billingAddress?.zipCode ? (
|
{errors.billingAddress?.zipCode ? (
|
||||||
<FormHelperText>{errors.billingAddress.zipCode.message}</FormHelperText>
|
<FormHelperText>{errors.billingAddress.zipCode.message}</FormHelperText>
|
||||||
@@ -459,7 +478,7 @@ export function UserMetaEditForm(): React.JSX.Element {
|
|||||||
error={Boolean(errors.billingAddress?.line1)}
|
error={Boolean(errors.billingAddress?.line1)}
|
||||||
fullWidth
|
fullWidth
|
||||||
>
|
>
|
||||||
<InputLabel required>Address Line 1</InputLabel>
|
<InputLabel required>{t('edit.address-line-1')}</InputLabel>
|
||||||
<OutlinedInput {...field} />
|
<OutlinedInput {...field} />
|
||||||
{errors.billingAddress?.line1 ? (
|
{errors.billingAddress?.line1 ? (
|
||||||
<FormHelperText>{errors.billingAddress.line1.message}</FormHelperText>
|
<FormHelperText>{errors.billingAddress.line1.message}</FormHelperText>
|
||||||
@@ -494,7 +513,7 @@ export function UserMetaEditForm(): React.JSX.Element {
|
|||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
<Stack spacing={3}>
|
<Stack spacing={3}>
|
||||||
<Typography variant="h6">Additional Information</Typography>
|
<Typography variant="h6">{t('edit.additional-information')}</Typography>
|
||||||
<Grid
|
<Grid
|
||||||
container
|
container
|
||||||
spacing={3}
|
spacing={3}
|
||||||
@@ -541,8 +560,10 @@ export function UserMetaEditForm(): React.JSX.Element {
|
|||||||
>
|
>
|
||||||
<InputLabel required>Language</InputLabel>
|
<InputLabel required>Language</InputLabel>
|
||||||
<Select {...field}>
|
<Select {...field}>
|
||||||
|
<MenuItem value="">no language selected</MenuItem>
|
||||||
<MenuItem value="en">English</MenuItem>
|
<MenuItem value="en">English</MenuItem>
|
||||||
<MenuItem value="es">Spanish</MenuItem>
|
<MenuItem value="es">Spanish</MenuItem>
|
||||||
|
<MenuItem value="de">German</MenuItem>
|
||||||
<MenuItem value="fr">French</MenuItem>
|
<MenuItem value="fr">French</MenuItem>
|
||||||
</Select>
|
</Select>
|
||||||
{errors.language ? <FormHelperText>{errors.language.message}</FormHelperText> : null}
|
{errors.language ? <FormHelperText>{errors.language.message}</FormHelperText> : null}
|
||||||
@@ -562,8 +583,9 @@ export function UserMetaEditForm(): React.JSX.Element {
|
|||||||
error={Boolean(errors.currency)}
|
error={Boolean(errors.currency)}
|
||||||
fullWidth
|
fullWidth
|
||||||
>
|
>
|
||||||
<InputLabel required>Currency</InputLabel>
|
<InputLabel required>{t('edit.currency')}</InputLabel>
|
||||||
<Select {...field}>
|
<Select {...field}>
|
||||||
|
<MenuItem value="">no currency selected</MenuItem>
|
||||||
<MenuItem value="USD">USD</MenuItem>
|
<MenuItem value="USD">USD</MenuItem>
|
||||||
<MenuItem value="EUR">EUR</MenuItem>
|
<MenuItem value="EUR">EUR</MenuItem>
|
||||||
<MenuItem value="GBP">GBP</MenuItem>
|
<MenuItem value="GBP">GBP</MenuItem>
|
||||||
@@ -581,7 +603,7 @@ export function UserMetaEditForm(): React.JSX.Element {
|
|||||||
<Button
|
<Button
|
||||||
color="secondary"
|
color="secondary"
|
||||||
component={RouterLink}
|
component={RouterLink}
|
||||||
href={paths.dashboard.teachers.list}
|
href={paths.dashboard.user_metas.list}
|
||||||
>
|
>
|
||||||
{t('edit.cancelButton')}
|
{t('edit.cancelButton')}
|
||||||
</Button>
|
</Button>
|
||||||
|
@@ -1,11 +1,15 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
// src/components/dashboard/user_meta/user-metas-filters.tsx
|
||||||
// RULES:
|
// RULES:
|
||||||
// T.B.A.
|
// T.B.A.
|
||||||
//
|
//
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
|
import GetActiveCount from '@/db/UserMetas/GetActiveCount';
|
||||||
import getAllUserMetasCount from '@/db/UserMetas/GetAllCount';
|
import getAllUserMetasCount from '@/db/UserMetas/GetAllCount';
|
||||||
|
import GetBlockedCount from '@/db/UserMetas/GetBlockedCount';
|
||||||
|
import GetPendingCount from '@/db/UserMetas/GetPendingCount';
|
||||||
import Button from '@mui/material/Button';
|
import Button from '@mui/material/Button';
|
||||||
import Chip from '@mui/material/Chip';
|
import Chip from '@mui/material/Chip';
|
||||||
import Divider from '@mui/material/Divider';
|
import Divider from '@mui/material/Divider';
|
||||||
@@ -18,17 +22,14 @@ import Typography from '@mui/material/Typography';
|
|||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import { paths } from '@/paths';
|
import { paths } from '@/paths';
|
||||||
|
import { logger } from '@/lib/default-logger';
|
||||||
import { FilterButton } from '@/components/core/filter-button';
|
import { FilterButton } from '@/components/core/filter-button';
|
||||||
import { Option } from '@/components/core/option';
|
import { Option } from '@/components/core/option';
|
||||||
|
|
||||||
import { useUserMetasSelection } from './user-metas-selection-context';
|
|
||||||
import GetBlockedCount from '@/db/UserMetas/GetBlockedCount';
|
|
||||||
import GetPendingCount from '@/db/UserMetas/GetPendingCount';
|
|
||||||
import GetActiveCount from '@/db/UserMetas/GetActiveCount';
|
|
||||||
import PhoneFilterPopover from './phone-filter-popover';
|
|
||||||
import EmailFilterPopover from './email-filter-popover';
|
import EmailFilterPopover from './email-filter-popover';
|
||||||
import type { UserMetasFiltersProps, Filters, SortDir } from './type.d';
|
import PhoneFilterPopover from './phone-filter-popover';
|
||||||
import { logger } from '@/lib/default-logger';
|
import type { Filters, SortDir, UserMetasFiltersProps } from './type.d';
|
||||||
|
import { useUserMetasSelection } from './user-metas-selection-context';
|
||||||
|
|
||||||
export function UserMetasFilters({
|
export function UserMetasFilters({
|
||||||
filters = {},
|
filters = {},
|
||||||
|
@@ -1,5 +1,9 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
// src/components/dashboard/user_meta/user-metas-table.tsx
|
||||||
|
// RULES:
|
||||||
|
// T.B.A.
|
||||||
|
//
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import RouterLink from 'next/link';
|
import RouterLink from 'next/link';
|
||||||
import { LoadingButton } from '@mui/lab';
|
import { LoadingButton } from '@mui/lab';
|
||||||
@@ -18,14 +22,16 @@ import { Images as ImagesIcon } from '@phosphor-icons/react/dist/ssr/Images';
|
|||||||
import { Minus as MinusIcon } from '@phosphor-icons/react/dist/ssr/Minus';
|
import { Minus as MinusIcon } from '@phosphor-icons/react/dist/ssr/Minus';
|
||||||
import { PencilSimple as PencilSimpleIcon } from '@phosphor-icons/react/dist/ssr/PencilSimple';
|
import { PencilSimple as PencilSimpleIcon } from '@phosphor-icons/react/dist/ssr/PencilSimple';
|
||||||
import { TrashSimple as TrashSimpleIcon } from '@phosphor-icons/react/dist/ssr/TrashSimple';
|
import { TrashSimple as TrashSimpleIcon } from '@phosphor-icons/react/dist/ssr/TrashSimple';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import { paths } from '@/paths';
|
import { paths } from '@/paths';
|
||||||
import { dayjs } from '@/lib/dayjs';
|
import { dayjs } from '@/lib/dayjs';
|
||||||
import { DataTable } from '@/components/core/data-table';
|
import { DataTable } from '@/components/core/data-table';
|
||||||
import type { ColumnDef } from '@/components/core/data-table';
|
import type { ColumnDef } from '@/components/core/data-table';
|
||||||
|
|
||||||
import ConfirmDeleteModal from './confirm-delete-modal';
|
import ConfirmDeleteModal from './confirm-delete-modal';
|
||||||
import { useUserMetasSelection } from './user-metas-selection-context';
|
|
||||||
import type { UserMeta } from './type.d';
|
import type { UserMeta } from './type.d';
|
||||||
|
import { useUserMetasSelection } from './user-metas-selection-context';
|
||||||
|
|
||||||
function columns(handleDeleteClick: (userMetaId: string) => void): ColumnDef<UserMeta>[] {
|
function columns(handleDeleteClick: (userMetaId: string) => void): ColumnDef<UserMeta>[] {
|
||||||
return [
|
return [
|
||||||
@@ -168,6 +174,7 @@ export interface UserMetasTableProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function UserMetasTable({ rows, reloadRows }: UserMetasTableProps): React.JSX.Element {
|
export function UserMetasTable({ rows, reloadRows }: UserMetasTableProps): React.JSX.Element {
|
||||||
|
const { t } = useTranslation(['user_metas']);
|
||||||
const { deselectAll, deselectOne, selectAll, selectOne, selected } = useUserMetasSelection();
|
const { deselectAll, deselectOne, selectAll, selectOne, selected } = useUserMetasSelection();
|
||||||
|
|
||||||
const [idToDelete, setIdToDelete] = React.useState('');
|
const [idToDelete, setIdToDelete] = React.useState('');
|
||||||
@@ -207,7 +214,7 @@ export function UserMetasTable({ rows, reloadRows }: UserMetasTableProps): React
|
|||||||
sx={{ textAlign: 'center' }}
|
sx={{ textAlign: 'center' }}
|
||||||
variant="body2"
|
variant="body2"
|
||||||
>
|
>
|
||||||
No user metadata found
|
{t('no-user-meta-found')}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
) : null}
|
) : null}
|
||||||
|
@@ -5,6 +5,7 @@ const COL_LESSON_TYPES = 'LessonsTypes';
|
|||||||
const COL_LESSON_CATEGORIES = 'LessonsCategories';
|
const COL_LESSON_CATEGORIES = 'LessonsCategories';
|
||||||
const COL_USERS = 'users';
|
const COL_USERS = 'users';
|
||||||
const COL_USER_METAS = 'UserMetas';
|
const COL_USER_METAS = 'UserMetas';
|
||||||
|
const COL_BILLING_ADDRESS = 'billingAddress';
|
||||||
|
|
||||||
// RULES:
|
// RULES:
|
||||||
// do not use LP_CATEGORIES anymore
|
// do not use LP_CATEGORIES anymore
|
||||||
@@ -56,4 +57,5 @@ export {
|
|||||||
COL_VOCABULARIES,
|
COL_VOCABULARIES,
|
||||||
NS_VOCABULARY,
|
NS_VOCABULARY,
|
||||||
//
|
//
|
||||||
|
COL_BILLING_ADDRESS,
|
||||||
};
|
};
|
||||||
|
@@ -1,11 +1,12 @@
|
|||||||
// api method for crate student record
|
// api method for crate student record
|
||||||
// RULES:
|
// RULES:
|
||||||
// TBA
|
// TBA
|
||||||
import { pb } from '@/lib/pb';
|
import { COL_USER_METAS } from '@/constants';
|
||||||
import { COL_STUDENTS } from '@/constants';
|
|
||||||
import type { CreateFormProps } from '@/components/dashboard/student/type.d';
|
|
||||||
import type { RecordModel } from 'pocketbase';
|
import type { RecordModel } from 'pocketbase';
|
||||||
|
|
||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
import type { CreateFormProps } from '@/components/dashboard/student/type.d';
|
||||||
|
|
||||||
export async function createStudent(data: CreateFormProps): Promise<RecordModel> {
|
export async function createStudent(data: CreateFormProps): Promise<RecordModel> {
|
||||||
return pb.collection(COL_STUDENTS).create(data);
|
return pb.collection(COL_USER_METAS).create({ ...data, role: 'student' });
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,32 @@
|
|||||||
import { pb } from '@/lib/pb';
|
// src/db/Students/GetById.tsx
|
||||||
import { COL_STUDENTS } from '@/constants';
|
//
|
||||||
import { RecordModel } from 'pocketbase';
|
import { COL_USER_METAS } from '@/constants';
|
||||||
|
|
||||||
export async function getStudentById(id: string): Promise<RecordModel> {
|
import { pb } from '@/lib/pb';
|
||||||
return pb.collection(COL_STUDENTS).getOne(id);
|
import type { DBStudent, Student } from '@/components/dashboard/student/type';
|
||||||
|
|
||||||
|
export async function getStudentById(id: string): Promise<Student> {
|
||||||
|
const record = await pb
|
||||||
|
.collection(COL_USER_METAS)
|
||||||
|
.getOne<DBStudent>(id, { expand: 'billingAddress, helloworld', requestKey: null });
|
||||||
|
|
||||||
|
const temp: Student = {
|
||||||
|
id: record.id,
|
||||||
|
name: record.name,
|
||||||
|
email: record.email,
|
||||||
|
quota: record.quota,
|
||||||
|
billingAddress: record.expand.billingAddress ? record.expand.billingAddress[0] : {},
|
||||||
|
status: record.status,
|
||||||
|
state: record.state,
|
||||||
|
createdAt: new Date(record.created),
|
||||||
|
collectionId: record.collectionId,
|
||||||
|
avatar: record.avatar,
|
||||||
|
phone: record.phone,
|
||||||
|
company: record.company,
|
||||||
|
timezone: record.timezone,
|
||||||
|
language: record.language,
|
||||||
|
currency: record.currency,
|
||||||
|
};
|
||||||
|
|
||||||
|
return temp;
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,7 @@
|
|||||||
|
// src/db/Students/Helloworld.tsx
|
||||||
|
// RULES:
|
||||||
|
// T.B.A.
|
||||||
|
//
|
||||||
export function helloCustomer() {
|
export function helloCustomer() {
|
||||||
return 'Hello from Customers module!';
|
return 'Hello from Customers module!';
|
||||||
}
|
}
|
||||||
|
10
002_source/cms/src/db/Students/UpdateById.tsx
Normal file
10
002_source/cms/src/db/Students/UpdateById.tsx
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { COL_USER_METAS } from '@/constants';
|
||||||
|
import type { RecordModel } from 'pocketbase';
|
||||||
|
|
||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
|
||||||
|
import type { UpdateStudent } from './type';
|
||||||
|
|
||||||
|
export async function UpdateStudentById(id: string, data: Partial<UpdateStudent>): Promise<RecordModel> {
|
||||||
|
return pb.collection(COL_USER_METAS).update(id, data);
|
||||||
|
}
|
95
002_source/cms/src/db/Students/type.d.ts
vendored
95
002_source/cms/src/db/Students/type.d.ts
vendored
@@ -1,11 +1,96 @@
|
|||||||
|
// src/db/Students/type.d.ts
|
||||||
|
//
|
||||||
|
// PURPOSE
|
||||||
|
// type for student record
|
||||||
|
//
|
||||||
|
// RULES: sorting direction for user meta lists
|
||||||
|
import type { BillingAddress } from '../billingAddress/type';
|
||||||
|
|
||||||
// Student type definitions
|
// Student type definitions
|
||||||
export interface Student {
|
|
||||||
id: string;
|
export interface DBStudentOld {
|
||||||
|
//
|
||||||
name: string;
|
name: string;
|
||||||
avatar: string;
|
//
|
||||||
|
// NOTE: obslete "avatar" and use "avatar_file"
|
||||||
|
avatar?: string;
|
||||||
|
avatar_file?: string;
|
||||||
|
//
|
||||||
email: string;
|
email: string;
|
||||||
phone: string;
|
phone: string;
|
||||||
quota: number;
|
quota: number;
|
||||||
status: 'active' | 'blocked' | 'pending';
|
company: string;
|
||||||
createdAt: Date;
|
//
|
||||||
|
// billingAddress: BillingAddress[] | [];
|
||||||
|
expand: { billingAddress?: BillingAddress[] };
|
||||||
|
|
||||||
|
// status is obsoleted, replace by state
|
||||||
|
status: 'pending' | 'active' | 'blocked';
|
||||||
|
state: 'pending' | 'active' | 'blocked';
|
||||||
|
//
|
||||||
|
timezone: string;
|
||||||
|
language: string;
|
||||||
|
currency: string;
|
||||||
|
//
|
||||||
|
id: string;
|
||||||
|
created: string;
|
||||||
|
updated?: string;
|
||||||
|
collectionId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// RULES: core user meta data structure
|
||||||
|
export interface Student {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
//
|
||||||
|
// NOTE: obslete "avatar" and use "avatar_file"
|
||||||
|
avatar?: string;
|
||||||
|
avatar_file?: string;
|
||||||
|
//
|
||||||
|
email: string;
|
||||||
|
phone?: string;
|
||||||
|
quota: number;
|
||||||
|
company?: string;
|
||||||
|
//
|
||||||
|
billingAddress: BillingAddress | Record<string, never>;
|
||||||
|
|
||||||
|
// status is obsoleted, replace by state
|
||||||
|
status: 'pending' | 'active' | 'blocked';
|
||||||
|
state: 'pending' | 'active' | 'blocked';
|
||||||
|
//
|
||||||
|
timezone: string;
|
||||||
|
language: string;
|
||||||
|
currency: string;
|
||||||
|
//
|
||||||
|
id: string;
|
||||||
|
createdAt: Date;
|
||||||
|
updatedAt?: Date;
|
||||||
|
collectionId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UpdateStudent {
|
||||||
|
name?: string;
|
||||||
|
//
|
||||||
|
// NOTE: obslete "avatar" and use "avatar_file"
|
||||||
|
// avatar_file?: string;
|
||||||
|
avatar: File | null;
|
||||||
|
//
|
||||||
|
email?: string;
|
||||||
|
phone?: string;
|
||||||
|
quota?: number;
|
||||||
|
company?: string;
|
||||||
|
//
|
||||||
|
// relation handle seperately
|
||||||
|
// billingAddress: BillingAddress | Record<string, never>;
|
||||||
|
|
||||||
|
// status is obsoleted, replace by state
|
||||||
|
// status: 'pending' | 'active' | 'blocked';
|
||||||
|
state?: 'pending' | 'active' | 'blocked';
|
||||||
|
//
|
||||||
|
timezone?: string;
|
||||||
|
language?: string;
|
||||||
|
currency?: string;
|
||||||
|
|
||||||
|
//
|
||||||
|
taxId?: string;
|
||||||
}
|
}
|
||||||
|
@@ -1,11 +1,12 @@
|
|||||||
// api method for crate teacher record
|
// api method for crate teacher record
|
||||||
// RULES:
|
// RULES:
|
||||||
// TBA
|
// TBA
|
||||||
import { pb } from '@/lib/pb';
|
import { COL_USER_METAS } from '@/constants';
|
||||||
import { COL_TEACHERS } from '@/constants';
|
|
||||||
import type { CreateFormProps } from '@/components/dashboard/teacher/type.d';
|
|
||||||
import type { RecordModel } from 'pocketbase';
|
import type { RecordModel } from 'pocketbase';
|
||||||
|
|
||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
import type { CreateFormProps } from '@/components/dashboard/teacher/type.d';
|
||||||
|
|
||||||
export async function createTeacher(data: CreateFormProps): Promise<RecordModel> {
|
export async function createTeacher(data: CreateFormProps): Promise<RecordModel> {
|
||||||
return pb.collection(COL_TEACHERS).create(data);
|
return pb.collection(COL_USER_METAS).create({ ...data, role: 'teacher' });
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,8 @@
|
|||||||
import { pb } from '@/lib/pb';
|
|
||||||
import { COL_TEACHERS } from '@/constants';
|
import { COL_TEACHERS } from '@/constants';
|
||||||
import { RecordModel } from 'pocketbase';
|
import { RecordModel } from 'pocketbase';
|
||||||
|
|
||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
|
||||||
export async function getAllTeachers(options = {}): Promise<RecordModel[]> {
|
export async function getAllTeachers(options = {}): Promise<RecordModel[]> {
|
||||||
return pb.collection(COL_TEACHERS).getFullList(options);
|
return pb.collection(COL_TEACHERS).getFullList(options);
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,30 @@
|
|||||||
import { pb } from '@/lib/pb';
|
// src/db/Teachers/GetById.tsx
|
||||||
import { COL_TEACHERS } from '@/constants';
|
//
|
||||||
import { RecordModel } from 'pocketbase';
|
import { COL_USER_METAS } from '@/constants';
|
||||||
|
|
||||||
export async function getTeacherById(id: string): Promise<RecordModel> {
|
import { pb } from '@/lib/pb';
|
||||||
return pb.collection(COL_TEACHERS).getOne(id);
|
import type { DBUserMeta, UserMeta } from '@/components/dashboard/user_meta/type.d';
|
||||||
|
|
||||||
|
export async function getTeacherById(id: string): Promise<UserMeta> {
|
||||||
|
const record = await pb.collection(COL_USER_METAS).getOne<DBUserMeta>(id, { expand: 'billingAddress, helloworld' });
|
||||||
|
|
||||||
|
const temp: UserMeta = {
|
||||||
|
id: record.id,
|
||||||
|
name: record.name,
|
||||||
|
email: record.email,
|
||||||
|
quota: record.quota,
|
||||||
|
billingAddress: record.expand.billingAddress ? record.expand.billingAddress[0] : {},
|
||||||
|
status: record.status,
|
||||||
|
state: record.state,
|
||||||
|
createdAt: new Date(record.created),
|
||||||
|
collectionId: record.collectionId,
|
||||||
|
avatar: record.avatar,
|
||||||
|
phone: record.phone,
|
||||||
|
company: record.company,
|
||||||
|
timezone: record.timezone,
|
||||||
|
language: record.language,
|
||||||
|
currency: record.currency,
|
||||||
|
};
|
||||||
|
|
||||||
|
return temp;
|
||||||
}
|
}
|
||||||
|
10
002_source/cms/src/db/Teachers/UpdateById.tsx
Normal file
10
002_source/cms/src/db/Teachers/UpdateById.tsx
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { COL_USER_METAS } from '@/constants';
|
||||||
|
import type { RecordModel } from 'pocketbase';
|
||||||
|
|
||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
|
||||||
|
import type { UpdateTeacher } from './type';
|
||||||
|
|
||||||
|
export async function UpdateTeacherById(id: string, data: Partial<UpdateTeacher>): Promise<RecordModel> {
|
||||||
|
return pb.collection(COL_USER_METAS).update(id, data);
|
||||||
|
}
|
41
002_source/cms/src/db/Teachers/type.d.ts
vendored
Normal file
41
002_source/cms/src/db/Teachers/type.d.ts
vendored
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
//
|
||||||
|
// RULES
|
||||||
|
// type for teacher record
|
||||||
|
|
||||||
|
// Teacher type definitions
|
||||||
|
export interface Teacher {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
avatar: string;
|
||||||
|
email: string;
|
||||||
|
phone: string;
|
||||||
|
quota: number;
|
||||||
|
status: 'active' | 'blocked' | 'pending';
|
||||||
|
createdAt: Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UpdateTeacher {
|
||||||
|
name?: string;
|
||||||
|
//
|
||||||
|
// NOTE: obslete "avatar" and use "avatar_file"
|
||||||
|
// avatar_file?: string;
|
||||||
|
avatar: File | null;
|
||||||
|
//
|
||||||
|
email?: string;
|
||||||
|
phone?: string;
|
||||||
|
quota?: number;
|
||||||
|
company?: string;
|
||||||
|
//
|
||||||
|
// relation handle seperately
|
||||||
|
// billingAddress: BillingAddress | Record<string, never>;
|
||||||
|
|
||||||
|
// status is obsoleted, replace by state
|
||||||
|
// status: 'pending' | 'active' | 'blocked';
|
||||||
|
state?: 'pending' | 'active' | 'blocked';
|
||||||
|
//
|
||||||
|
timezone?: string;
|
||||||
|
language?: string;
|
||||||
|
currency?: string;
|
||||||
|
//
|
||||||
|
taxId?: string;
|
||||||
|
}
|
@@ -1,11 +1,14 @@
|
|||||||
// api method for crate customer record
|
// src/db/UserMetas/Create.tsx
|
||||||
// RULES:
|
//
|
||||||
// TBA
|
// PURPOSE:
|
||||||
import { pb } from '@/lib/pb';
|
// create user meta
|
||||||
|
//
|
||||||
import { COL_USER_METAS } from '@/constants';
|
import { COL_USER_METAS } from '@/constants';
|
||||||
import type { CreateFormProps } from '@/components/dashboard/user_meta/type.d';
|
|
||||||
import type { RecordModel } from 'pocketbase';
|
import type { RecordModel } from 'pocketbase';
|
||||||
|
|
||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
import type { CreateFormProps } from '@/components/dashboard/user_meta/type.d';
|
||||||
|
|
||||||
export async function createUserMeta(data: CreateFormProps): Promise<RecordModel> {
|
export async function createUserMeta(data: CreateFormProps): Promise<RecordModel> {
|
||||||
return pb.collection(COL_USER_METAS).create(data);
|
return pb.collection(COL_USER_METAS).create(data);
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,32 @@
|
|||||||
import { pb } from '@/lib/pb';
|
// src/db/UserMetas/GetById.tsx
|
||||||
|
//
|
||||||
import { COL_USER_METAS } from '@/constants';
|
import { COL_USER_METAS } from '@/constants';
|
||||||
import { RecordModel } from 'pocketbase';
|
|
||||||
|
|
||||||
export async function getUserMetaById(id: string): Promise<RecordModel> {
|
import { pb } from '@/lib/pb';
|
||||||
return pb.collection(COL_USER_METAS).getOne(id);
|
import type { DBUserMeta, UserMeta } from '@/components/dashboard/user_meta/type';
|
||||||
|
|
||||||
|
export async function getUserMetaById(id: string): Promise<UserMeta> {
|
||||||
|
const record = await pb
|
||||||
|
.collection(COL_USER_METAS)
|
||||||
|
.getOne<DBUserMeta>(id, { expand: 'billingAddress, helloworld', requestKey: null });
|
||||||
|
|
||||||
|
const temp: UserMeta = {
|
||||||
|
id: record.id,
|
||||||
|
name: record.name,
|
||||||
|
email: record.email,
|
||||||
|
quota: record.quota,
|
||||||
|
billingAddress: record.expand.billingAddress ? record.expand.billingAddress[0] : {},
|
||||||
|
status: record.status,
|
||||||
|
state: record.state,
|
||||||
|
createdAt: new Date(record.created),
|
||||||
|
collectionId: record.collectionId,
|
||||||
|
avatar: record.avatar,
|
||||||
|
phone: record.phone,
|
||||||
|
company: record.company,
|
||||||
|
timezone: record.timezone,
|
||||||
|
language: record.language,
|
||||||
|
currency: record.currency,
|
||||||
|
};
|
||||||
|
|
||||||
|
return temp;
|
||||||
}
|
}
|
||||||
|
10
002_source/cms/src/db/UserMetas/UpdateById.tsx
Normal file
10
002_source/cms/src/db/UserMetas/UpdateById.tsx
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { COL_USER_METAS } from '@/constants';
|
||||||
|
import type { RecordModel } from 'pocketbase';
|
||||||
|
|
||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
|
||||||
|
import type { UpdateUserMeta } from './type';
|
||||||
|
|
||||||
|
export async function UpdateUserMetaById(id: string, data: Partial<UpdateUserMeta>): Promise<RecordModel> {
|
||||||
|
return pb.collection(COL_USER_METAS).update(id, data);
|
||||||
|
}
|
72
002_source/cms/src/db/UserMetas/type.d.ts
vendored
Normal file
72
002_source/cms/src/db/UserMetas/type.d.ts
vendored
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
// src/db/UserMetas/type.d.ts
|
||||||
|
//
|
||||||
|
// RULES: sorting direction for user meta lists
|
||||||
|
|
||||||
|
import type { BillingAddress } from '@/components/dashboard/user_meta/type.d';
|
||||||
|
|
||||||
|
export interface DBUserMeta {
|
||||||
|
name: string;
|
||||||
|
//
|
||||||
|
// NOTE: obslete "avatar" and use "avatar_file"
|
||||||
|
avatar?: string;
|
||||||
|
avatar_file?: string;
|
||||||
|
//
|
||||||
|
email: string;
|
||||||
|
phone: string;
|
||||||
|
quota: number;
|
||||||
|
company: string;
|
||||||
|
//
|
||||||
|
// billingAddress: BillingAddress[] | [];
|
||||||
|
expand: { billingAddress?: BillingAddress[] };
|
||||||
|
|
||||||
|
// status is obsoleted, replace by state
|
||||||
|
status: 'pending' | 'active' | 'blocked';
|
||||||
|
state: 'pending' | 'active' | 'blocked';
|
||||||
|
//
|
||||||
|
timezone: string;
|
||||||
|
language: string;
|
||||||
|
currency: string;
|
||||||
|
//
|
||||||
|
id: string;
|
||||||
|
created: string;
|
||||||
|
updated?: string;
|
||||||
|
collectionId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserMeta type definitions
|
||||||
|
export interface UserMeta {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
avatar: string;
|
||||||
|
email: string;
|
||||||
|
phone: string;
|
||||||
|
quota: number;
|
||||||
|
status: 'active' | 'blocked' | 'pending';
|
||||||
|
createdAt: Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UpdateUserMeta {
|
||||||
|
name?: string;
|
||||||
|
//
|
||||||
|
// NOTE: obslete "avatar" and use "avatar_file"
|
||||||
|
// avatar_file?: string;
|
||||||
|
avatar: File | null;
|
||||||
|
//
|
||||||
|
email?: string;
|
||||||
|
phone?: string;
|
||||||
|
quota?: number;
|
||||||
|
company?: string;
|
||||||
|
//
|
||||||
|
// relation handle seperately
|
||||||
|
// billingAddress: BillingAddress | Record<string, never>;
|
||||||
|
|
||||||
|
// status is obsoleted, replace by state
|
||||||
|
// status: 'pending' | 'active' | 'blocked';
|
||||||
|
state?: 'pending' | 'active' | 'blocked';
|
||||||
|
//
|
||||||
|
timezone?: string;
|
||||||
|
language?: string;
|
||||||
|
currency?: string;
|
||||||
|
//
|
||||||
|
taxId?: string;
|
||||||
|
}
|
@@ -1,15 +0,0 @@
|
|||||||
// REQ0006
|
|
||||||
import { COL_USERS } from '@/constants';
|
|
||||||
|
|
||||||
import { pb } from '@/lib/pb';
|
|
||||||
|
|
||||||
export default async function GetAllCount(): Promise<number> {
|
|
||||||
try {
|
|
||||||
const result = await pb.collection(`users`).getList(1, 9999, { filter: 'email != ""' });
|
|
||||||
const { totalItems: count } = result;
|
|
||||||
return count;
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
return -99;
|
|
||||||
}
|
|
||||||
}
|
|
0
002_source/cms/src/db/Users/ChangeUserState.tsx
Normal file
0
002_source/cms/src/db/Users/ChangeUserState.tsx
Normal file
@@ -1,15 +1,9 @@
|
|||||||
import { pb } from '@/lib/pb';
|
|
||||||
import { COL_USERS } from '@/constants';
|
import { COL_USERS } from '@/constants';
|
||||||
import type { User } from '@/types/user';
|
|
||||||
|
|
||||||
export async function getUserById(id: string): Promise<User> {
|
import { pb } from '@/lib/pb';
|
||||||
try {
|
|
||||||
const user = await pb.collection(COL_USERS).getOne<User>(id);
|
import type { User } from './type.d';
|
||||||
return user;
|
|
||||||
} catch (err) {
|
export function getUserById(id: string): Promise<User> {
|
||||||
if (err instanceof Error && err.message.includes('404')) {
|
return pb.collection(COL_USERS).getOne<User>(id);
|
||||||
throw new Error(`User with ID ${id} not found`);
|
|
||||||
}
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
10
002_source/cms/src/db/Users/UpdateById.tsx
Normal file
10
002_source/cms/src/db/Users/UpdateById.tsx
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { COL_USERS } from '@/constants';
|
||||||
|
import type { RecordModel } from 'pocketbase';
|
||||||
|
|
||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
|
||||||
|
import type { UpdateUser } from './type.d';
|
||||||
|
|
||||||
|
export async function UpdateUserById(id: string, data: Partial<UpdateUser>): Promise<RecordModel> {
|
||||||
|
return pb.collection(COL_USERS).update(id, data);
|
||||||
|
}
|
@@ -21,9 +21,12 @@ the `@` sign refer to `/home/logic/_wsl_workspace/001_github_ws/lettersoup-onlin
|
|||||||
simple template:
|
simple template:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { pb } from '@/lib/pb';
|
|
||||||
import { COL_USERS } from '@/constants';
|
import { COL_USERS } from '@/constants';
|
||||||
|
|
||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
|
||||||
|
import type { User } from './type.d';
|
||||||
|
|
||||||
export async function createUser(data: CreateFormProps) {
|
export async function createUser(data: CreateFormProps) {
|
||||||
// ...content
|
// ...content
|
||||||
// use direct return of pb.collection (e.g. return pb.collection(xxx))
|
// use direct return of pb.collection (e.g. return pb.collection(xxx))
|
||||||
|
15
002_source/cms/src/db/Users/type.d.ts
vendored
Normal file
15
002_source/cms/src/db/Users/type.d.ts
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
//
|
||||||
|
// RULES
|
||||||
|
// pocketbase Users collection schema
|
||||||
|
//
|
||||||
|
// User type definitions
|
||||||
|
export interface User {
|
||||||
|
verified: boolean;
|
||||||
|
//
|
||||||
|
id: string;
|
||||||
|
createdAt: Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UpdateUser {
|
||||||
|
verified?: boolean;
|
||||||
|
}
|
11
002_source/cms/src/db/billingAddress/Create.tsx
Normal file
11
002_source/cms/src/db/billingAddress/Create.tsx
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
// api method for crate student record
|
||||||
|
// RULES:
|
||||||
|
// TBA
|
||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
import { COL_STUDENTS } from '@/constants';
|
||||||
|
import type { CreateFormProps } from '@/components/dashboard/student/type.d';
|
||||||
|
import type { RecordModel } from 'pocketbase';
|
||||||
|
|
||||||
|
export async function createStudent(data: CreateFormProps): Promise<RecordModel> {
|
||||||
|
return pb.collection(COL_STUDENTS).create(data);
|
||||||
|
}
|
6
002_source/cms/src/db/billingAddress/Delete.tsx
Normal file
6
002_source/cms/src/db/billingAddress/Delete.tsx
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
import { COL_STUDENTS, COL_USER_METAS } from '@/constants';
|
||||||
|
|
||||||
|
export async function deleteStudent(id: string): Promise<boolean> {
|
||||||
|
return pb.collection(COL_USER_METAS).delete(id);
|
||||||
|
}
|
9
002_source/cms/src/db/billingAddress/GetActiveCount.tsx
Normal file
9
002_source/cms/src/db/billingAddress/GetActiveCount.tsx
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { COL_STUDENTS, COL_USER_METAS } from '@/constants';
|
||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
|
||||||
|
export default async function GetActiveCount(): Promise<number> {
|
||||||
|
const { totalItems: count } = await pb.collection(COL_USER_METAS).getList(1, 1, {
|
||||||
|
filter: 'status = "active" && role = "student"',
|
||||||
|
});
|
||||||
|
return count;
|
||||||
|
}
|
7
002_source/cms/src/db/billingAddress/GetAll.tsx
Normal file
7
002_source/cms/src/db/billingAddress/GetAll.tsx
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
import { COL_STUDENTS } from '@/constants';
|
||||||
|
import { RecordModel } from 'pocketbase';
|
||||||
|
|
||||||
|
export async function getAllStudents(options = {}): Promise<RecordModel[]> {
|
||||||
|
return pb.collection(COL_STUDENTS).getFullList(options);
|
||||||
|
}
|
10
002_source/cms/src/db/billingAddress/GetAllCount.tsx
Normal file
10
002_source/cms/src/db/billingAddress/GetAllCount.tsx
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
import { COL_USER_METAS } from '@/constants';
|
||||||
|
|
||||||
|
export async function getAllStudentsCount(): Promise<number> {
|
||||||
|
const result = await pb.collection(COL_USER_METAS).getList(1, 1, {
|
||||||
|
filter: `role = "student"`,
|
||||||
|
//
|
||||||
|
});
|
||||||
|
return result.totalItems;
|
||||||
|
}
|
9
002_source/cms/src/db/billingAddress/GetBlockedCount.tsx
Normal file
9
002_source/cms/src/db/billingAddress/GetBlockedCount.tsx
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { COL_USER_METAS } from '@/constants';
|
||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
|
||||||
|
export default async function GetBlockedCount(): Promise<number> {
|
||||||
|
const { totalItems: count } = await pb.collection(COL_USER_METAS).getList(1, 1, {
|
||||||
|
filter: 'status = "blocked" && role = "student"',
|
||||||
|
});
|
||||||
|
return count;
|
||||||
|
}
|
36
002_source/cms/src/db/billingAddress/GetById.tsx
Normal file
36
002_source/cms/src/db/billingAddress/GetById.tsx
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
// src/db/billingAddress/GetById.tsx
|
||||||
|
//
|
||||||
|
// PURPOSE:
|
||||||
|
// to get billing address by its id
|
||||||
|
//
|
||||||
|
|
||||||
|
import { COL_BILLING_ADDRESS } from '@/constants';
|
||||||
|
|
||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
import type { DBUserMeta, UserMeta } from '@/components/dashboard/user_meta/type.d';
|
||||||
|
|
||||||
|
export async function getBillingAddressById(id: string): Promise<UserMeta> {
|
||||||
|
const record = await pb
|
||||||
|
.collection(COL_BILLING_ADDRESS)
|
||||||
|
.getOne<DBUserMeta>(id, { expand: 'billingAddress, helloworld' });
|
||||||
|
|
||||||
|
const temp: UserMeta = {
|
||||||
|
id: record.id,
|
||||||
|
name: record.name,
|
||||||
|
email: record.email,
|
||||||
|
quota: record.quota,
|
||||||
|
billingAddress: record.expand.billingAddress ? record.expand.billingAddress[0] : {},
|
||||||
|
status: record.status,
|
||||||
|
state: record.state,
|
||||||
|
createdAt: new Date(record.created),
|
||||||
|
collectionId: record.collectionId,
|
||||||
|
avatar: record.avatar,
|
||||||
|
phone: record.phone,
|
||||||
|
company: record.company,
|
||||||
|
timezone: record.timezone,
|
||||||
|
language: record.language,
|
||||||
|
currency: record.currency,
|
||||||
|
};
|
||||||
|
|
||||||
|
return temp;
|
||||||
|
}
|
9
002_source/cms/src/db/billingAddress/GetPendingCount.tsx
Normal file
9
002_source/cms/src/db/billingAddress/GetPendingCount.tsx
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { COL_USER_METAS } from '@/constants';
|
||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
|
||||||
|
export default async function GetPendingCount(): Promise<number> {
|
||||||
|
const { totalItems: count } = await pb.collection(COL_USER_METAS).getList(1, 1, {
|
||||||
|
filter: 'status = "pending" && role = "student"',
|
||||||
|
});
|
||||||
|
return count;
|
||||||
|
}
|
3
002_source/cms/src/db/billingAddress/Helloworld.tsx
Normal file
3
002_source/cms/src/db/billingAddress/Helloworld.tsx
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export function helloCustomer() {
|
||||||
|
return 'Hello from Customers module!';
|
||||||
|
}
|
8
002_source/cms/src/db/billingAddress/Update.tsx
Normal file
8
002_source/cms/src/db/billingAddress/Update.tsx
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
import { COL_CUSTOMERS } from '@/constants';
|
||||||
|
import type { RecordModel } from 'pocketbase';
|
||||||
|
import type { EditFormProps } from '@/components/dashboard/customer/type.d';
|
||||||
|
|
||||||
|
export async function updateCustomer(id: string, data: Partial<EditFormProps>): Promise<RecordModel> {
|
||||||
|
return pb.collection(COL_CUSTOMERS).update(id, data);
|
||||||
|
}
|
10
002_source/cms/src/db/billingAddress/UpdateById.tsx
Normal file
10
002_source/cms/src/db/billingAddress/UpdateById.tsx
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { COL_BILLING_ADDRESS } from '@/constants';
|
||||||
|
import type { RecordModel } from 'pocketbase';
|
||||||
|
|
||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
|
||||||
|
import type { UpdateBillingAddress } from './type';
|
||||||
|
|
||||||
|
export async function UpdateBillingAddressById(id: string, data: Partial<UpdateBillingAddress>): Promise<RecordModel> {
|
||||||
|
return pb.collection(COL_BILLING_ADDRESS).update(id, data);
|
||||||
|
}
|
31
002_source/cms/src/db/billingAddress/_GUIDELINES.md
Normal file
31
002_source/cms/src/db/billingAddress/_GUIDELINES.md
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
# GUIDELINES
|
||||||
|
|
||||||
|
This folder contains drivers for `Customer`/`Customers` records using PocketBase:
|
||||||
|
|
||||||
|
- create (Create.tsx)
|
||||||
|
- read (GetById.tsx)
|
||||||
|
- write (Update.tsx)
|
||||||
|
- count (GetAllCount.tsx, GetActiveCount.tsx, GetBlockedCount.tsx, GetPendingCount.tsx)
|
||||||
|
- misc (Helloworld.tsx)
|
||||||
|
- delete (Delete.tsx)
|
||||||
|
- list (GetAll.tsx)
|
||||||
|
|
||||||
|
the `@` sign refer to `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src`
|
||||||
|
|
||||||
|
## Assumption and Requirements
|
||||||
|
|
||||||
|
- assume `pb` is located in `@/lib/pb`
|
||||||
|
- no need to handle error in this function, i'll handle it in the caller
|
||||||
|
- type information defined in `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/db/Customers/type.d.tsx`
|
||||||
|
|
||||||
|
simple template:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { pb } from '@/lib/pb';
|
||||||
|
import { COL_CUSTOMERS } from '@/constants';
|
||||||
|
|
||||||
|
export async function createCustomer(data: CreateFormProps) {
|
||||||
|
// ...content
|
||||||
|
// use direct return of pb.collection (e.g. return pb.collection(xxx))
|
||||||
|
}
|
||||||
|
```
|
23
002_source/cms/src/db/billingAddress/type.d.ts
vendored
Normal file
23
002_source/cms/src/db/billingAddress/type.d.ts
vendored
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
export interface BillingAddress {
|
||||||
|
city: string;
|
||||||
|
country: string;
|
||||||
|
line1: string;
|
||||||
|
line2: string;
|
||||||
|
state: string;
|
||||||
|
zipCode: string;
|
||||||
|
//
|
||||||
|
id: string;
|
||||||
|
collectionId: string;
|
||||||
|
collectionName: string;
|
||||||
|
updated: string;
|
||||||
|
created: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UpdateBillingAddress {
|
||||||
|
city?: string;
|
||||||
|
country?: string;
|
||||||
|
line1?: string;
|
||||||
|
line2?: string;
|
||||||
|
state?: string;
|
||||||
|
zipCode?: string;
|
||||||
|
}
|
@@ -1,9 +1,12 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
// src/lib/auth/custom/client.ts
|
||||||
|
//
|
||||||
import { getUserMetaById } from '@/db/UserMetas/GetById';
|
import { getUserMetaById } from '@/db/UserMetas/GetById';
|
||||||
|
|
||||||
|
import type { User } from '@/types/user';
|
||||||
import { logger } from '@/lib/default-logger';
|
import { logger } from '@/lib/default-logger';
|
||||||
import { pb } from '@/lib/pb';
|
import { pb } from '@/lib/pb';
|
||||||
import type { User } from '@/types/user';
|
|
||||||
|
|
||||||
function generateToken(): string {
|
function generateToken(): string {
|
||||||
const arr = new Uint8Array(12);
|
const arr = new Uint8Array(12);
|
||||||
@@ -11,14 +14,6 @@ function generateToken(): string {
|
|||||||
return Array.from(arr, (v) => v.toString(16).padStart(2, '0')).join('');
|
return Array.from(arr, (v) => v.toString(16).padStart(2, '0')).join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
const user_xxx = {
|
|
||||||
id: 'USR-000',
|
|
||||||
avatar: '/assets/avatar.png',
|
|
||||||
firstName: 'Sofia',
|
|
||||||
lastName: 'Rivers',
|
|
||||||
email: 'sofia@devias.io',
|
|
||||||
} satisfies User;
|
|
||||||
|
|
||||||
export interface SignUpParams {
|
export interface SignUpParams {
|
||||||
firstName: string;
|
firstName: string;
|
||||||
lastName: string;
|
lastName: string;
|
||||||
|
@@ -1,3 +1,8 @@
|
|||||||
export default function getImageUrlFromFile(collectionId: string, id: string, catImage: string): string {
|
//
|
||||||
return `http://127.0.0.1:8090/api/files/${collectionId}/${id}/${catImage}`;
|
// PURPOSE:
|
||||||
|
// get file url from pocketbase record
|
||||||
|
//
|
||||||
|
|
||||||
|
export default function getImageUrlFromFile(collectionId: string, id: string, imgFile: string): string {
|
||||||
|
return `http://127.0.0.1:8090/api/files/${collectionId}/${id}/${imgFile}`;
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,7 @@
|
|||||||
|
// src/lib/helloworld.ts
|
||||||
|
// RULES:
|
||||||
|
// T.B.A.
|
||||||
|
//
|
||||||
export function helloworld(): string {
|
export function helloworld(): string {
|
||||||
return 'Helloworld';
|
return 'Helloworld';
|
||||||
}
|
}
|
||||||
|
@@ -140,7 +140,7 @@ export const paths = {
|
|||||||
list: '/dashboard/teachers/list',
|
list: '/dashboard/teachers/list',
|
||||||
create: '/dashboard/teachers/create',
|
create: '/dashboard/teachers/create',
|
||||||
details: (id: string) => `/dashboard/teachers/view/${id}`,
|
details: (id: string) => `/dashboard/teachers/view/${id}`,
|
||||||
view: (id: string) => `/dashboard/students/view/${id}`,
|
view: (id: string) => `/dashboard/teachers/view/${id}`,
|
||||||
edit: (id: string) => `/dashboard/teachers/edit/${id}`,
|
edit: (id: string) => `/dashboard/teachers/edit/${id}`,
|
||||||
mail: {
|
mail: {
|
||||||
list: (id: string) => `/dashboard/teachers/mail/${id}/list`,
|
list: (id: string) => `/dashboard/teachers/mail/${id}/list`,
|
||||||
|
@@ -1,149 +0,0 @@
|
|||||||
volumes:
|
|
||||||
shared:
|
|
||||||
dist:
|
|
||||||
|
|
||||||
services:
|
|
||||||
cms:
|
|
||||||
image: 192.168.10.61:5000/cms_ubuntu
|
|
||||||
# build: ./cms
|
|
||||||
env_file:
|
|
||||||
- .env
|
|
||||||
volumes:
|
|
||||||
- ./cms:/app
|
|
||||||
ports:
|
|
||||||
- 3000:3000
|
|
||||||
working_dir: /app
|
|
||||||
command: ./scripts/docker/entrypoint.sh
|
|
||||||
depends_on:
|
|
||||||
pocketbase:
|
|
||||||
condition: service_healthy
|
|
||||||
healthcheck:
|
|
||||||
#optional (recommended) since v0.10.0
|
|
||||||
test: wget --no-verbose --tries=1 --spider http://localhost:3000 || exit 1
|
|
||||||
interval: 5s
|
|
||||||
timeout: 5s
|
|
||||||
retries: 5
|
|
||||||
deploy:
|
|
||||||
resources:
|
|
||||||
limits:
|
|
||||||
cpus: "0.5"
|
|
||||||
reservations:
|
|
||||||
cpus: "0.01"
|
|
||||||
|
|
||||||
doc:
|
|
||||||
build: ./doc
|
|
||||||
env_file:
|
|
||||||
- .env
|
|
||||||
volumes:
|
|
||||||
- ./doc:/app
|
|
||||||
ports:
|
|
||||||
- 3001:3000
|
|
||||||
working_dir: /app
|
|
||||||
command: ./scripts/docker/entrypoint.sh
|
|
||||||
healthcheck:
|
|
||||||
#optional (recommended) since v0.10.0
|
|
||||||
test: wget --no-verbose --tries=1 --spider http://localhost:3000 || exit 1
|
|
||||||
interval: 5s
|
|
||||||
timeout: 5s
|
|
||||||
retries: 5
|
|
||||||
|
|
||||||
deploy:
|
|
||||||
resources:
|
|
||||||
limits:
|
|
||||||
cpus: "0.5"
|
|
||||||
reservations:
|
|
||||||
cpus: "0.01"
|
|
||||||
|
|
||||||
ionic_mobile:
|
|
||||||
# image: node:20-bullseye-slim
|
|
||||||
# build: ./ionic_mobile
|
|
||||||
image: 192.168.10.61:5000/ionic_mobile_ubuntu
|
|
||||||
# user: 1000:1000
|
|
||||||
env_file:
|
|
||||||
- .env
|
|
||||||
volumes:
|
|
||||||
- ./ionic_mobile:/app
|
|
||||||
ports:
|
|
||||||
- 5173:5173
|
|
||||||
working_dir: /app
|
|
||||||
command: ./scripts/docker/entrypoint.sh
|
|
||||||
depends_on:
|
|
||||||
pocketbase:
|
|
||||||
condition: service_healthy
|
|
||||||
healthcheck:
|
|
||||||
#optional (recommended) since v0.10.0
|
|
||||||
test: wget --no-verbose --tries=1 --spider http://localhost:5173 || exit 1
|
|
||||||
interval: 5s
|
|
||||||
timeout: 5s
|
|
||||||
retries: 5
|
|
||||||
|
|
||||||
deploy:
|
|
||||||
resources:
|
|
||||||
limits:
|
|
||||||
cpus: "0.5"
|
|
||||||
reservations:
|
|
||||||
cpus: "0.01"
|
|
||||||
|
|
||||||
api_ts:
|
|
||||||
image: 192.168.10.61:5000/api_ts_ubuntu
|
|
||||||
# build: ./api_ts
|
|
||||||
volumes:
|
|
||||||
- ./api_ts:/app
|
|
||||||
working_dir: /app
|
|
||||||
# env_file:
|
|
||||||
# - .env
|
|
||||||
environment:
|
|
||||||
- NODE_ENV=production
|
|
||||||
- PB_HOSTNAME=pocketbase
|
|
||||||
- PB_USERNAME=admin@123.com
|
|
||||||
- PB_PASSWORD=Aa12345678
|
|
||||||
ports:
|
|
||||||
- 8080:3000
|
|
||||||
# command: sleep infinity
|
|
||||||
command: ./entrypoint.sh
|
|
||||||
# depends_on:
|
|
||||||
# pocketbase:
|
|
||||||
# condition: service_healthy
|
|
||||||
# healthcheck:
|
|
||||||
# #optional (recommended) since v0.10.0
|
|
||||||
# test: wget --no-verbose --tries=1 --spider http://localhost:3000 || exit 1
|
|
||||||
# interval: 5s
|
|
||||||
# timeout: 5s
|
|
||||||
# retries: 5
|
|
||||||
|
|
||||||
deploy:
|
|
||||||
resources:
|
|
||||||
limits:
|
|
||||||
cpus: 0.5
|
|
||||||
reservations:
|
|
||||||
cpus: 0.01
|
|
||||||
|
|
||||||
pocketbase:
|
|
||||||
# image: ghcr.io/muchobien/pocketbase:latest
|
|
||||||
build:
|
|
||||||
context: ./pocketbase/docker
|
|
||||||
args:
|
|
||||||
- VERSION=0.26.6 # Specify the PocketBase version here
|
|
||||||
# hostname: pocketbase
|
|
||||||
restart: always
|
|
||||||
# environment:
|
|
||||||
# ENCRYPTION: example #optional
|
|
||||||
ports:
|
|
||||||
- 8090:8090
|
|
||||||
volumes:
|
|
||||||
- ./pocketbase/volumes/pb_data:/pb_data
|
|
||||||
- ./pocketbase/pb_hooks:/pb_hooks
|
|
||||||
- ./pocketbase/pb_migrations:/pb_migrations
|
|
||||||
# healthcheck:
|
|
||||||
# #optional (recommended) since v0.10.0
|
|
||||||
# test: wget --no-verbose --tries=1 --spider http://localhost:8090/api/health || exit 1
|
|
||||||
# interval: 5s
|
|
||||||
# timeout: 5s
|
|
||||||
# retries: 5
|
|
||||||
|
|
||||||
deploy:
|
|
||||||
resources:
|
|
||||||
limits:
|
|
||||||
cpus: 0.5
|
|
||||||
reservations:
|
|
||||||
cpus: 0.01
|
|
@@ -1,3 +1,4 @@
|
|||||||
# TODO
|
# TODO
|
||||||
|
|
||||||
- [ ] add login mechanism
|
- [ ] add login mechanism
|
||||||
|
- [ ] add task server handle callback tasks
|
||||||
|
50
002_source/ionic_mobile/package-lock.json
generated
50
002_source/ionic_mobile/package-lock.json
generated
@@ -16,6 +16,7 @@
|
|||||||
"@capacitor/keyboard": "6.0.3",
|
"@capacitor/keyboard": "6.0.3",
|
||||||
"@capacitor/splash-screen": "^6.0.3",
|
"@capacitor/splash-screen": "^6.0.3",
|
||||||
"@capacitor/status-bar": "6.0.2",
|
"@capacitor/status-bar": "6.0.2",
|
||||||
|
"@hookform/resolvers": "3.3.4",
|
||||||
"@ionic/prettier-config": "^4.0.0",
|
"@ionic/prettier-config": "^4.0.0",
|
||||||
"@ionic/react": "^8.0.0",
|
"@ionic/react": "^8.0.0",
|
||||||
"@ionic/react-router": "^8.0.0",
|
"@ionic/react-router": "^8.0.0",
|
||||||
@@ -23,21 +24,25 @@
|
|||||||
"@lifeomic/attempt": "^3.1.0",
|
"@lifeomic/attempt": "^3.1.0",
|
||||||
"@tanstack/react-query": "^5.74.4",
|
"@tanstack/react-query": "^5.74.4",
|
||||||
"@tanstack/react-query-devtools": "^5.74.6",
|
"@tanstack/react-query-devtools": "^5.74.6",
|
||||||
|
"@types/lodash": "^4.17.16",
|
||||||
"@types/react-router": "^5.1.20",
|
"@types/react-router": "^5.1.20",
|
||||||
"@types/react-router-dom": "^5.3.3",
|
"@types/react-router-dom": "^5.3.3",
|
||||||
"axios": "^1.8.1",
|
"axios": "^1.8.1",
|
||||||
"i18next": "^24.2.2",
|
"i18next": "^24.2.2",
|
||||||
"ionicons": "^7.0.0",
|
"ionicons": "^7.0.0",
|
||||||
|
"lodash": "^4.17.21",
|
||||||
"pocketbase": "^0.26.0",
|
"pocketbase": "^0.26.0",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
|
"react-hook-form": "7.50.1",
|
||||||
"react-i18next": "^15.4.1",
|
"react-i18next": "^15.4.1",
|
||||||
"react-markdown": "^9.0.3",
|
"react-markdown": "^9.0.3",
|
||||||
"react-router": "^5.3.4",
|
"react-router": "^5.3.4",
|
||||||
"react-router-dom": "^5.3.4",
|
"react-router-dom": "^5.3.4",
|
||||||
"react-use": "^17.6.0",
|
"react-use": "^17.6.0",
|
||||||
"react-use-audio-player": "^2.3.0-alpha.1",
|
"react-use-audio-player": "^2.3.0-alpha.1",
|
||||||
"remark-gfm": "^4.0.0"
|
"remark-gfm": "^4.0.0",
|
||||||
|
"zod": "3.22.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@capacitor/assets": "^3.0.5",
|
"@capacitor/assets": "^3.0.5",
|
||||||
@@ -65,7 +70,7 @@
|
|||||||
"vitest": "^0.34.6"
|
"vitest": "^0.34.6"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "==18"
|
"node": "==22"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@adobe/css-tools": {
|
"node_modules/@adobe/css-tools": {
|
||||||
@@ -2242,6 +2247,15 @@
|
|||||||
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
|
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@hookform/resolvers": {
|
||||||
|
"version": "3.3.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@hookform/resolvers/-/resolvers-3.3.4.tgz",
|
||||||
|
"integrity": "sha512-o5cgpGOuJYrd+iMKvkttOclgwRW86EsWJZZRC23prf0uU2i48Htq4PuT73AVb9ionFyZrwYEITuOFGF+BydEtQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"peerDependencies": {
|
||||||
|
"react-hook-form": "^7.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@humanwhocodes/config-array": {
|
"node_modules/@humanwhocodes/config-array": {
|
||||||
"version": "0.13.0",
|
"version": "0.13.0",
|
||||||
"resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.13.0.tgz",
|
"resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.13.0.tgz",
|
||||||
@@ -3699,6 +3713,12 @@
|
|||||||
"integrity": "sha512-aLkWa0C0vO5b4Sr798E26QgOkss68Un0bLjs7u9qxzPT5CG+8DuNTffWES58YzJs3hrVAOs1wonycqEBqNJubA==",
|
"integrity": "sha512-aLkWa0C0vO5b4Sr798E26QgOkss68Un0bLjs7u9qxzPT5CG+8DuNTffWES58YzJs3hrVAOs1wonycqEBqNJubA==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/lodash": {
|
||||||
|
"version": "4.17.16",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.16.tgz",
|
||||||
|
"integrity": "sha512-HX7Em5NYQAXKW+1T+FiuG27NGwzJfCX3s1GjOa7ujxZa52kjJLOr4FUxT+giF6Tgxv1e+/czV/iTtBw27WTU9g==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/@types/mdast": {
|
"node_modules/@types/mdast": {
|
||||||
"version": "4.0.4",
|
"version": "4.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/@types/mdast/-/mdast-4.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/@types/mdast/-/mdast-4.0.4.tgz",
|
||||||
@@ -10602,7 +10622,6 @@
|
|||||||
"version": "4.17.21",
|
"version": "4.17.21",
|
||||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
||||||
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
|
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/lodash.debounce": {
|
"node_modules/lodash.debounce": {
|
||||||
@@ -13138,6 +13157,22 @@
|
|||||||
"react": "^18.3.1"
|
"react": "^18.3.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/react-hook-form": {
|
||||||
|
"version": "7.50.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.50.1.tgz",
|
||||||
|
"integrity": "sha512-3PCY82oE0WgeOgUtIr3nYNNtNvqtJ7BZjsbxh6TnYNbXButaD5WpjOmTjdxZfheuHKR68qfeFnEDVYoSSFPMTQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12.22.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"type": "opencollective",
|
||||||
|
"url": "https://opencollective.com/react-hook-form"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"react": "^16.8.0 || ^17 || ^18"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/react-i18next": {
|
"node_modules/react-i18next": {
|
||||||
"version": "15.4.1",
|
"version": "15.4.1",
|
||||||
"resolved": "https://registry.npmjs.org/react-i18next/-/react-i18next-15.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/react-i18next/-/react-i18next-15.4.1.tgz",
|
||||||
@@ -16747,6 +16782,15 @@
|
|||||||
"url": "https://github.com/sponsors/sindresorhus"
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/zod": {
|
||||||
|
"version": "3.22.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/zod/-/zod-3.22.4.tgz",
|
||||||
|
"integrity": "sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/colinhacks"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/zwitch": {
|
"node_modules/zwitch": {
|
||||||
"version": "2.0.4",
|
"version": "2.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/zwitch/-/zwitch-2.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/zwitch/-/zwitch-2.0.4.tgz",
|
||||||
|
@@ -31,6 +31,7 @@
|
|||||||
"@capacitor/keyboard": "6.0.3",
|
"@capacitor/keyboard": "6.0.3",
|
||||||
"@capacitor/splash-screen": "^6.0.3",
|
"@capacitor/splash-screen": "^6.0.3",
|
||||||
"@capacitor/status-bar": "6.0.2",
|
"@capacitor/status-bar": "6.0.2",
|
||||||
|
"@hookform/resolvers": "3.3.4",
|
||||||
"@ionic/prettier-config": "^4.0.0",
|
"@ionic/prettier-config": "^4.0.0",
|
||||||
"@ionic/react": "^8.0.0",
|
"@ionic/react": "^8.0.0",
|
||||||
"@ionic/react-router": "^8.0.0",
|
"@ionic/react-router": "^8.0.0",
|
||||||
@@ -38,21 +39,25 @@
|
|||||||
"@lifeomic/attempt": "^3.1.0",
|
"@lifeomic/attempt": "^3.1.0",
|
||||||
"@tanstack/react-query": "^5.74.4",
|
"@tanstack/react-query": "^5.74.4",
|
||||||
"@tanstack/react-query-devtools": "^5.74.6",
|
"@tanstack/react-query-devtools": "^5.74.6",
|
||||||
|
"@types/lodash": "^4.17.16",
|
||||||
"@types/react-router": "^5.1.20",
|
"@types/react-router": "^5.1.20",
|
||||||
"@types/react-router-dom": "^5.3.3",
|
"@types/react-router-dom": "^5.3.3",
|
||||||
"axios": "^1.8.1",
|
"axios": "^1.8.1",
|
||||||
"i18next": "^24.2.2",
|
"i18next": "^24.2.2",
|
||||||
"ionicons": "^7.0.0",
|
"ionicons": "^7.0.0",
|
||||||
|
"lodash": "^4.17.21",
|
||||||
"pocketbase": "^0.26.0",
|
"pocketbase": "^0.26.0",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
|
"react-hook-form": "7.50.1",
|
||||||
"react-i18next": "^15.4.1",
|
"react-i18next": "^15.4.1",
|
||||||
"react-markdown": "^9.0.3",
|
"react-markdown": "^9.0.3",
|
||||||
"react-router": "^5.3.4",
|
"react-router": "^5.3.4",
|
||||||
"react-router-dom": "^5.3.4",
|
"react-router-dom": "^5.3.4",
|
||||||
"react-use": "^17.6.0",
|
"react-use": "^17.6.0",
|
||||||
"react-use-audio-player": "^2.3.0-alpha.1",
|
"react-use-audio-player": "^2.3.0-alpha.1",
|
||||||
"remark-gfm": "^4.0.0"
|
"remark-gfm": "^4.0.0",
|
||||||
|
"zod": "3.22.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@capacitor/assets": "^3.0.5",
|
"@capacitor/assets": "^3.0.5",
|
||||||
@@ -81,6 +86,6 @@
|
|||||||
},
|
},
|
||||||
"description": "An Ionic project",
|
"description": "An Ionic project",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "==18"
|
"node": "==22"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
16
002_source/ionic_mobile/src/Paths.tsx
Normal file
16
002_source/ionic_mobile/src/Paths.tsx
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
const Paths = {
|
||||||
|
AuthHome: `/auth/home`,
|
||||||
|
AuthLogin: `/auth/login`,
|
||||||
|
AuthSignUp: `/auth/signup`,
|
||||||
|
SignUpSuccess: `/auth/sign_up_success`,
|
||||||
|
//
|
||||||
|
StudentMenu: `/auth/student_menu`,
|
||||||
|
StudentInfo: `/auth/student_info/:id`,
|
||||||
|
GetStudentInfoLink: (id: string) => `/auth/student_info/${id}`,
|
||||||
|
//
|
||||||
|
AuthorizedTest: `/auth/authorized_test`,
|
||||||
|
//
|
||||||
|
Setting: `/setting`,
|
||||||
|
};
|
||||||
|
|
||||||
|
export { Paths };
|
@@ -45,10 +45,17 @@ import Page from './pages/Page';
|
|||||||
import QuizzesMainMenu from './pages/QuizzesMainMenu';
|
import QuizzesMainMenu from './pages/QuizzesMainMenu';
|
||||||
//
|
//
|
||||||
import MyAchievementPage from './pages/Record/index';
|
import MyAchievementPage from './pages/Record/index';
|
||||||
import Setting from './pages/Setting/indx';
|
import Setting from './pages/Setting';
|
||||||
import Tab1 from './pages/Tab1';
|
import Tab1 from './pages/Tab1';
|
||||||
import Tab2 from './pages/Tab2';
|
import Tab2 from './pages/Tab2';
|
||||||
import Tab3 from './pages/Tab3';
|
import Tab3 from './pages/Tab3';
|
||||||
|
import { Paths } from './Paths';
|
||||||
|
import SignUpSuccess from './pages/auth/SignUpSuccess';
|
||||||
|
import AuthorizedTest from './pages/auth/AuthorizedTest';
|
||||||
|
import { AuthGuard } from './components/auth/auth-guard';
|
||||||
|
import StudentInfo from './pages/auth/StudentInfo';
|
||||||
|
import StudentMenu from './pages/auth/StudentMenu';
|
||||||
|
// import { AuthGuard } from './pages/auth/AuthorizedTest/auth-guard';
|
||||||
// import WordPageWithLayout from './pages/Lesson/WordPageWithLayout.del';
|
// import WordPageWithLayout from './pages/Lesson/WordPageWithLayout.del';
|
||||||
|
|
||||||
function RouteConfig() {
|
function RouteConfig() {
|
||||||
@@ -160,18 +167,35 @@ function RouteConfig() {
|
|||||||
<ConnectivesPage />
|
<ConnectivesPage />
|
||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
<Route exact path={`/auth/Home`}>
|
<Route exact path={Paths.AuthHome}>
|
||||||
<AuthHome />
|
<AuthHome />
|
||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
<Route exact path={`/auth/login`}>
|
<Route exact path={Paths.AuthLogin}>
|
||||||
<AuthLogin />
|
<AuthLogin />
|
||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
<Route exact path={`/auth/signup`}>
|
<Route exact path={Paths.AuthSignUp}>
|
||||||
<AuthSignUp />
|
<AuthSignUp />
|
||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
|
<Route exact path={Paths.SignUpSuccess}>
|
||||||
|
<SignUpSuccess />
|
||||||
|
</Route>
|
||||||
|
|
||||||
|
{/* protected page */}
|
||||||
|
<AuthGuard>
|
||||||
|
<Route exact path={Paths.StudentInfo}>
|
||||||
|
<StudentInfo />
|
||||||
|
</Route>
|
||||||
|
<Route exact path={Paths.StudentMenu}>
|
||||||
|
<StudentMenu />
|
||||||
|
</Route>
|
||||||
|
<Route exact path={Paths.AuthorizedTest}>
|
||||||
|
<AuthorizedTest />
|
||||||
|
</Route>
|
||||||
|
</AuthGuard>
|
||||||
|
|
||||||
{/* TODO: remove below */}
|
{/* TODO: remove below */}
|
||||||
<Route exact path="/tab1">
|
<Route exact path="/tab1">
|
||||||
<Tab1 />
|
<Tab1 />
|
||||||
@@ -182,7 +206,7 @@ function RouteConfig() {
|
|||||||
<Route path="/tab3">
|
<Route path="/tab3">
|
||||||
<Tab3 />
|
<Tab3 />
|
||||||
</Route>
|
</Route>
|
||||||
<Route path="/setting">
|
<Route path={Paths.Setting}>
|
||||||
<Setting />
|
<Setting />
|
||||||
</Route>
|
</Route>
|
||||||
<Route path="/page/:name" exact={true}>
|
<Route path="/page/:name" exact={true}>
|
||||||
|
@@ -1,10 +1,7 @@
|
|||||||
import { IonInput, IonLabel } from '@ionic/react';
|
import { IonInput, IonLabel } from '@ionic/react';
|
||||||
import styles from './style.module.scss';
|
import styles from './style.module.scss';
|
||||||
|
|
||||||
function CustomField({
|
interface CustomFieldProps {
|
||||||
field,
|
|
||||||
errors,
|
|
||||||
}: {
|
|
||||||
field: {
|
field: {
|
||||||
id: string;
|
id: string;
|
||||||
label: string;
|
label: string;
|
||||||
@@ -20,7 +17,9 @@ function CustomField({
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
errors: any;
|
errors: any;
|
||||||
}): React.JSX.Element {
|
}
|
||||||
|
|
||||||
|
function CustomField({ field, errors }: CustomFieldProps): React.JSX.Element {
|
||||||
const error = errors && errors.filter((e) => e.id === field.id)[0];
|
const error = errors && errors.filter((e) => e.id === field.id)[0];
|
||||||
const errorMessage = error && errors.filter((e) => e.id === field.id)[0].message;
|
const errorMessage = error && errors.filter((e) => e.id === field.id)[0].message;
|
||||||
|
|
||||||
|
@@ -2,6 +2,8 @@ import { IonButton, IonIcon, useIonRouter } from '@ionic/react';
|
|||||||
import { arrowBack } from 'ionicons/icons';
|
import { arrowBack } from 'ionicons/icons';
|
||||||
import { LESSON_LINK, VERSIONS } from '../../constants';
|
import { LESSON_LINK, VERSIONS } from '../../constants';
|
||||||
import SettingSvg from './image.svg';
|
import SettingSvg from './image.svg';
|
||||||
|
import { Paths } from '../../Paths';
|
||||||
|
import { pb } from '../../lib/pb';
|
||||||
|
|
||||||
interface ContainerProps {
|
interface ContainerProps {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -9,6 +11,19 @@ interface ContainerProps {
|
|||||||
|
|
||||||
const SettingContainer: React.FC<ContainerProps> = ({ name }) => {
|
const SettingContainer: React.FC<ContainerProps> = ({ name }) => {
|
||||||
const router = useIonRouter();
|
const router = useIonRouter();
|
||||||
|
|
||||||
|
function handleAuthHomeClick() {
|
||||||
|
router.push(Paths.AuthHome);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleUserProfileClick() {
|
||||||
|
if (pb.authStore.record?.id) {
|
||||||
|
router.push(Paths.GetStudentInfoLink(pb.authStore.record.id));
|
||||||
|
} else {
|
||||||
|
router.push(Paths.AuthLogin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
@@ -34,6 +49,7 @@ const SettingContainer: React.FC<ContainerProps> = ({ name }) => {
|
|||||||
<p>T.B.A.</p>
|
<p>T.B.A.</p>
|
||||||
</div>
|
</div>
|
||||||
<div>{VERSIONS}</div>
|
<div>{VERSIONS}</div>
|
||||||
|
<IonButton onClick={handleUserProfileClick}>User Profile</IonButton>
|
||||||
<IonButton
|
<IonButton
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
router.push(LESSON_LINK, undefined, 'replace');
|
router.push(LESSON_LINK, undefined, 'replace');
|
||||||
|
52
002_source/ionic_mobile/src/components/auth/auth-guard.tsx
Normal file
52
002_source/ionic_mobile/src/components/auth/auth-guard.tsx
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import { useIonRouter } from '@ionic/react';
|
||||||
|
import * as React from 'react';
|
||||||
|
import { IonAlert, IonButton } from '@ionic/react';
|
||||||
|
import { useUser } from '../../hooks/use-user';
|
||||||
|
import { Paths } from '../../Paths';
|
||||||
|
|
||||||
|
export interface AuthGuardProps {
|
||||||
|
children: React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function AuthGuard({ children }: AuthGuardProps): React.JSX.Element | null {
|
||||||
|
const router = useIonRouter();
|
||||||
|
const { user, error, isLoading } = useUser();
|
||||||
|
const [isChecking, setIsChecking] = React.useState<boolean>(true);
|
||||||
|
|
||||||
|
const checkPermissions = async (): Promise<void> => {
|
||||||
|
//
|
||||||
|
if (isLoading) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
if (error) {
|
||||||
|
setIsChecking(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// NOTE: here state that if user = null, eject user to login page
|
||||||
|
if (!user) {
|
||||||
|
// logger.debug('[AuthGuard]: User is not logged in, redirecting to sign in');
|
||||||
|
|
||||||
|
router.push(Paths.AuthLogin);
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsChecking(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
checkPermissions().catch(() => {
|
||||||
|
// noop
|
||||||
|
});
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps -- Expected
|
||||||
|
}, [user, error, isLoading]);
|
||||||
|
|
||||||
|
if (isChecking) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return <IonAlert color="error">{error}</IonAlert>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return <React.Fragment>{children}</React.Fragment>;
|
||||||
|
}
|
@@ -77,6 +77,10 @@ const MY_FAVORITE = 'My Favorite';
|
|||||||
|
|
||||||
//
|
//
|
||||||
const POCKETBASE_URL = import.meta.env.VITE_POCKETBASE_URL;
|
const POCKETBASE_URL = import.meta.env.VITE_POCKETBASE_URL;
|
||||||
|
//
|
||||||
|
// database constants
|
||||||
|
export const COL_USERS = 'users';
|
||||||
|
export const COL_USER_METAS = 'UserMetas';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
//
|
//
|
||||||
|
@@ -0,0 +1,54 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import { User } from '../../../types/user';
|
||||||
|
import { authClient } from '../../../lib/auth/custom/client';
|
||||||
|
|
||||||
|
import type { UserContextValue } from '../types';
|
||||||
|
|
||||||
|
export const UserContext = React.createContext<UserContextValue | undefined>(undefined);
|
||||||
|
|
||||||
|
export interface UserProviderProps {
|
||||||
|
children: React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function UserProvider({ children }: UserProviderProps): React.JSX.Element {
|
||||||
|
const [state, setState] = React.useState<{ user: User | null; error: string | null; isLoading: boolean }>({
|
||||||
|
user: null,
|
||||||
|
error: null,
|
||||||
|
isLoading: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const checkSession = React.useCallback(async (): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { data, error } = await authClient.getUser();
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
// logger.error(error);
|
||||||
|
setState((prev) => ({ ...prev, user: null, error: 'Something went wrong', isLoading: false }));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setState((prev) => ({ ...prev, user: data ?? null, error: null, isLoading: false }));
|
||||||
|
} catch (err) {
|
||||||
|
// logger.error(err);
|
||||||
|
setState((prev) => ({ ...prev, user: null, error: 'Something went wrong', isLoading: false }));
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
checkSession().catch((err) => {
|
||||||
|
// logger.error(err);
|
||||||
|
// noop
|
||||||
|
});
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps -- Expected
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<UserContext.Provider value={{ ...state, checkSession }}>
|
||||||
|
{/* */}
|
||||||
|
{children}
|
||||||
|
</UserContext.Provider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const UserConsumer = UserContext.Consumer;
|
8
002_source/ionic_mobile/src/contexts/auth/types.d.ts
vendored
Normal file
8
002_source/ionic_mobile/src/contexts/auth/types.d.ts
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import type { User } from '../../types/user';
|
||||||
|
|
||||||
|
export interface UserContextValue {
|
||||||
|
user: User | null;
|
||||||
|
error: string | null;
|
||||||
|
isLoading: boolean;
|
||||||
|
checkSession?: () => Promise<void>;
|
||||||
|
}
|
16
002_source/ionic_mobile/src/contexts/auth/user-context.tsx
Normal file
16
002_source/ionic_mobile/src/contexts/auth/user-context.tsx
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import type * as React from 'react';
|
||||||
|
|
||||||
|
import type { UserContextValue } from './types';
|
||||||
|
|
||||||
|
import { UserContext as CustomUserContext, UserProvider as CustomUserProvider } from './custom/user-context';
|
||||||
|
|
||||||
|
// eslint-disable-next-line import/no-mutable-exports -- Export based on config
|
||||||
|
let UserProvider: React.FC<{ children: React.ReactNode }>;
|
||||||
|
|
||||||
|
// eslint-disable-next-line import/no-mutable-exports -- Export based on config
|
||||||
|
let UserContext: React.Context<UserContextValue | undefined>;
|
||||||
|
|
||||||
|
UserContext = CustomUserContext;
|
||||||
|
UserProvider = CustomUserProvider;
|
||||||
|
|
||||||
|
export { UserProvider, UserContext };
|
@@ -1,5 +1,6 @@
|
|||||||
import { PocketBaseProvider } from '../hooks/usePocketBase';
|
import { PocketBaseProvider } from '../hooks/usePocketBase';
|
||||||
import { AppStateProvider } from './AppState';
|
import { AppStateProvider } from './AppState';
|
||||||
|
import { UserProvider } from './auth/user-context';
|
||||||
import { MyIonFavoriteProvider } from './MyIonFavorite';
|
import { MyIonFavoriteProvider } from './MyIonFavorite';
|
||||||
import { MyIonMetricProvider } from './MyIonMetric';
|
import { MyIonMetricProvider } from './MyIonMetric';
|
||||||
import { MyIonQuizProvider } from './MyIonQuiz';
|
import { MyIonQuizProvider } from './MyIonQuiz';
|
||||||
@@ -12,6 +13,7 @@ const ContextMeta = ({ children }: { children: React.ReactNode }) => {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<AppStateProvider>
|
<AppStateProvider>
|
||||||
|
<UserProvider>
|
||||||
<MyIonStoreProvider>
|
<MyIonStoreProvider>
|
||||||
<MyIonFavoriteProvider>
|
<MyIonFavoriteProvider>
|
||||||
<MyIonQuizProvider>
|
<MyIonQuizProvider>
|
||||||
@@ -26,6 +28,7 @@ const ContextMeta = ({ children }: { children: React.ReactNode }) => {
|
|||||||
</MyIonQuizProvider>
|
</MyIonQuizProvider>
|
||||||
</MyIonFavoriteProvider>
|
</MyIonFavoriteProvider>
|
||||||
</MyIonStoreProvider>
|
</MyIonStoreProvider>
|
||||||
|
</UserProvider>
|
||||||
</AppStateProvider>
|
</AppStateProvider>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
@@ -7,10 +7,7 @@ export const useSignupFields = () => {
|
|||||||
label: 'Name',
|
label: 'Name',
|
||||||
required: true,
|
required: true,
|
||||||
input: {
|
input: {
|
||||||
props: {
|
props: { type: 'text', placeholder: 'Joe Bloggs' },
|
||||||
type: 'text',
|
|
||||||
placeholder: 'Joe Bloggs',
|
|
||||||
},
|
|
||||||
state: useFormInput(''),
|
state: useFormInput(''),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -19,10 +16,7 @@ export const useSignupFields = () => {
|
|||||||
label: 'Email',
|
label: 'Email',
|
||||||
required: true,
|
required: true,
|
||||||
input: {
|
input: {
|
||||||
props: {
|
props: { type: 'email', placeholder: 'joe@bloggs.com' },
|
||||||
type: 'email',
|
|
||||||
placeholder: 'joe@bloggs.com',
|
|
||||||
},
|
|
||||||
state: useFormInput(''),
|
state: useFormInput(''),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -31,10 +25,7 @@ export const useSignupFields = () => {
|
|||||||
label: 'Password',
|
label: 'Password',
|
||||||
required: true,
|
required: true,
|
||||||
input: {
|
input: {
|
||||||
props: {
|
props: { type: 'password', placeholder: '*********' },
|
||||||
type: 'password',
|
|
||||||
placeholder: '*********',
|
|
||||||
},
|
|
||||||
state: useFormInput(''),
|
state: useFormInput(''),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
11
002_source/ionic_mobile/src/db/UserMetas/GetById.tsx
Normal file
11
002_source/ionic_mobile/src/db/UserMetas/GetById.tsx
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import type { RecordModel } from 'pocketbase';
|
||||||
|
|
||||||
|
import { COL_USER_METAS } from '../../constants';
|
||||||
|
import { pb } from '../../lib/pb';
|
||||||
|
|
||||||
|
export async function getUserMetaById(id: string): Promise<RecordModel> {
|
||||||
|
return pb.collection(COL_USER_METAS).getOne(id, {
|
||||||
|
expand: 'billingAddress',
|
||||||
|
requestKey: null,
|
||||||
|
});
|
||||||
|
}
|
@@ -1,11 +1,12 @@
|
|||||||
# GUIDELINES
|
# GUIDELINES
|
||||||
|
|
||||||
This folder contains drivers for `User`/`Users` records using PocketBase:
|
This folder contains drivers for `UserMeta`/`UserMetas`(Collection ID: pbc_1305841361) records using PocketBase:
|
||||||
|
|
||||||
- create (Create.tsx)
|
- create (Create.tsx)
|
||||||
- read (GetById.tsx)
|
- read (GetById.tsx)
|
||||||
- write (Update.tsx)
|
- write (Update.tsx)
|
||||||
- count (GetAllCount.tsx)
|
- count (GetAllCount.tsx, GetActiveCount.tsx, GetBlockedCount.tsx, GetPendingCount.tsx)
|
||||||
|
- misc (Helloworld.tsx)
|
||||||
- delete (Delete.tsx)
|
- delete (Delete.tsx)
|
||||||
- list (GetAll.tsx)
|
- list (GetAll.tsx)
|
||||||
|
|
||||||
@@ -15,15 +16,15 @@ the `@` sign refer to `/home/logic/_wsl_workspace/001_github_ws/lettersoup-onlin
|
|||||||
|
|
||||||
- assume `pb` is located in `@/lib/pb`
|
- assume `pb` is located in `@/lib/pb`
|
||||||
- no need to handle error in this function, i'll handle it in the caller
|
- no need to handle error in this function, i'll handle it in the caller
|
||||||
- type information defined in `@/db/Users/type.d.tsx`
|
- type information defined in `./type.d.tsx`
|
||||||
|
|
||||||
simple template:
|
simple template:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { pb } from '@/lib/pb';
|
import { pb } from '@/lib/pb';
|
||||||
import { COL_USERS } from '@/constants';
|
import { COL_CUSTOMERS } from '@/constants';
|
||||||
|
|
||||||
export async function createUser(data: CreateFormProps) {
|
export async function createCustomer(data: CreateFormProps) {
|
||||||
// ...content
|
// ...content
|
||||||
// use direct return of pb.collection (e.g. return pb.collection(xxx))
|
// use direct return of pb.collection (e.g. return pb.collection(xxx))
|
||||||
}
|
}
|
11
002_source/ionic_mobile/src/db/UserMetas/_PROMPT.md
Normal file
11
002_source/ionic_mobile/src/db/UserMetas/_PROMPT.md
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
`working directory`: `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/db/UserMetas`
|
||||||
|
|
||||||
|
these files are clone from elsewhere,
|
||||||
|
please help to list `*.tsx.draft` files in `working directory` (e.g. `find`),
|
||||||
|
iterate the files listed in the result.
|
||||||
|
please understand, modify and update the content to handle `UserMeta` record thanks, modify comments/variables/paths/functions name please
|
||||||
|
|
||||||
|
restrict your modifications in working directory only,
|
||||||
|
I will handle all the modification outside this direcotry
|
||||||
|
|
||||||
|
e.g. if `lessonCategories` exist in file, modify it to `userMetas`
|
53
002_source/ionic_mobile/src/db/UserMetas/type.d.ts
vendored
Normal file
53
002_source/ionic_mobile/src/db/UserMetas/type.d.ts
vendored
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import type { BillingAddress } from '@/components/dashboard/user_meta/type.d';
|
||||||
|
|
||||||
|
// DBUserMeta type definitions
|
||||||
|
export interface DBUserMeta {
|
||||||
|
name: string;
|
||||||
|
avatar: string;
|
||||||
|
email: string;
|
||||||
|
phone: string;
|
||||||
|
quota: number;
|
||||||
|
status: 'active' | 'blocked' | 'pending';
|
||||||
|
//
|
||||||
|
collectionId: string;
|
||||||
|
id: string;
|
||||||
|
createdAt: Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserMeta type definitions
|
||||||
|
export interface UserMeta {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
avatar: string;
|
||||||
|
email: string;
|
||||||
|
phone: string;
|
||||||
|
quota: number;
|
||||||
|
status: 'active' | 'blocked' | 'pending';
|
||||||
|
createdAt: Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UpdateUserMeta {
|
||||||
|
name?: string;
|
||||||
|
//
|
||||||
|
// NOTE: obslete "avatar" and use "avatar_file"
|
||||||
|
// avatar_file?: string;
|
||||||
|
avatar: File | null;
|
||||||
|
//
|
||||||
|
email?: string;
|
||||||
|
phone?: string;
|
||||||
|
quota?: number;
|
||||||
|
company?: string;
|
||||||
|
//
|
||||||
|
// relation handle seperately
|
||||||
|
// billingAddress: BillingAddress | Record<string, never>;
|
||||||
|
|
||||||
|
// status is obsoleted, replace by state
|
||||||
|
// status: 'pending' | 'active' | 'blocked';
|
||||||
|
state?: 'pending' | 'active' | 'blocked';
|
||||||
|
//
|
||||||
|
timezone?: string;
|
||||||
|
language?: string;
|
||||||
|
currency?: string;
|
||||||
|
//
|
||||||
|
taxId?: string;
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user