@plasius/profile 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +66 -0
- package/CODE_OF_CONDUCT.md +79 -0
- package/CONTRIBUTORS.md +27 -0
- package/LICENSE +21 -0
- package/README.md +43 -0
- package/SECURITY.md +17 -0
- package/dist/Pages/Settings/Settings.d.ts +3 -0
- package/dist/Pages/Settings/Settings.d.ts.map +1 -0
- package/dist/Pages/Settings/Settings.js +93 -0
- package/dist/Pages/Settings/Settings.module.css +13 -0
- package/dist/Pages/Settings/index.d.ts +2 -0
- package/dist/Pages/Settings/index.d.ts.map +1 -0
- package/dist/Pages/Settings/index.js +1 -0
- package/dist/SettingsProvider.d.ts +28 -0
- package/dist/SettingsProvider.d.ts.map +1 -0
- package/dist/SettingsProvider.js +96 -0
- package/dist/UserProvider.d.ts +51 -0
- package/dist/UserProvider.d.ts.map +1 -0
- package/dist/UserProvider.js +141 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist-cjs/Pages/Settings/Settings.d.ts +3 -0
- package/dist-cjs/Pages/Settings/Settings.d.ts.map +1 -0
- package/dist-cjs/Pages/Settings/Settings.js +99 -0
- package/dist-cjs/Pages/Settings/Settings.module.css +13 -0
- package/dist-cjs/Pages/Settings/index.d.ts +2 -0
- package/dist-cjs/Pages/Settings/index.d.ts.map +1 -0
- package/dist-cjs/Pages/Settings/index.js +17 -0
- package/dist-cjs/SettingsProvider.d.ts +28 -0
- package/dist-cjs/SettingsProvider.d.ts.map +1 -0
- package/dist-cjs/SettingsProvider.js +100 -0
- package/dist-cjs/UserProvider.d.ts +51 -0
- package/dist-cjs/UserProvider.d.ts.map +1 -0
- package/dist-cjs/UserProvider.js +146 -0
- package/dist-cjs/index.d.ts +4 -0
- package/dist-cjs/index.d.ts.map +1 -0
- package/dist-cjs/index.js +19 -0
- package/docs/adrs/adr-0001-profile-package-scope.md +21 -0
- package/docs/adrs/adr-0002-public-repo-governance.md +24 -0
- package/docs/adrs/adr-template.md +35 -0
- package/legal/CLA-REGISTRY.csv +1 -0
- package/legal/CLA.md +22 -0
- package/legal/CORPORATE_CLA.md +57 -0
- package/legal/INDIVIDUAL_CLA.md +91 -0
- package/package.json +109 -0
- package/src/Pages/Settings/Settings.module.css +13 -0
- package/src/Pages/Settings/Settings.tsx +228 -0
- package/src/Pages/Settings/index.ts +1 -0
- package/src/SettingsProvider.tsx +146 -0
- package/src/UserProvider.tsx +167 -0
- package/src/declarations.d.ts +5 -0
- package/src/index.ts +3 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on **[Keep a Changelog](https://keepachangelog.com/en/1.1.0/)**, and this project adheres to **[Semantic Versioning](https://semver.org/spec/v2.0.0.html)**.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## [Unreleased]
|
|
10
|
+
|
|
11
|
+
- **Added**
|
|
12
|
+
- (placeholder)
|
|
13
|
+
|
|
14
|
+
- **Changed**
|
|
15
|
+
- (placeholder)
|
|
16
|
+
|
|
17
|
+
- **Fixed**
|
|
18
|
+
- (placeholder)
|
|
19
|
+
|
|
20
|
+
- **Security**
|
|
21
|
+
- (placeholder)
|
|
22
|
+
|
|
23
|
+
## [1.0.4] - 2026-02-12
|
|
24
|
+
|
|
25
|
+
- **Added**
|
|
26
|
+
- Standalone public package scaffold at repository root with independent CI/CD, ADRs, and legal governance assets.
|
|
27
|
+
|
|
28
|
+
- **Changed**
|
|
29
|
+
- Add dual ESM + CJS build outputs with `exports` entries and CJS artifacts in `dist-cjs/`.
|
|
30
|
+
|
|
31
|
+
- **Fixed**
|
|
32
|
+
- Removed monorepo-relative TypeScript configuration coupling for standalone builds.
|
|
33
|
+
|
|
34
|
+
- **Security**
|
|
35
|
+
- Added baseline public package governance and CLA documentation.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Release process (maintainers)
|
|
40
|
+
|
|
41
|
+
1. Update `CHANGELOG.md` under **Unreleased** with user-visible changes.
|
|
42
|
+
2. Bump version in `package.json` following SemVer (major/minor/patch).
|
|
43
|
+
3. Move entries from **Unreleased** to a new version section with the current date.
|
|
44
|
+
4. Tag the release in Git (`vX.Y.Z`) and push tags.
|
|
45
|
+
5. Publish to npm (via CI/CD or `npm publish`).
|
|
46
|
+
|
|
47
|
+
> Tip: Use Conventional Commits in PR titles/bodies to make changelog updates easier.
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
[Unreleased]: https://github.com/Plasius-LTD/profile/compare/v1.0.4...HEAD
|
|
52
|
+
|
|
53
|
+
## [1.0.0] - 2026-02-11
|
|
54
|
+
|
|
55
|
+
- **Added**
|
|
56
|
+
- Initial release.
|
|
57
|
+
|
|
58
|
+
- **Changed**
|
|
59
|
+
- (placeholder)
|
|
60
|
+
|
|
61
|
+
- **Fixed**
|
|
62
|
+
- (placeholder)
|
|
63
|
+
|
|
64
|
+
- **Security**
|
|
65
|
+
- (placeholder)
|
|
66
|
+
[1.0.4]: https://github.com/Plasius-LTD/profile/releases/tag/v1.0.4
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct v2.1
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
|
6
|
+
|
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
|
8
|
+
|
|
9
|
+
## Our Standards
|
|
10
|
+
|
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
|
12
|
+
|
|
13
|
+
- Demonstrating empathy and kindness toward other people
|
|
14
|
+
- Being respectful of differing opinions, viewpoints, and experiences
|
|
15
|
+
- Giving and gracefully accepting constructive feedback
|
|
16
|
+
- Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
|
17
|
+
- Focusing on what is best not just for us as individuals, but for the overall community
|
|
18
|
+
|
|
19
|
+
Examples of unacceptable behavior include:
|
|
20
|
+
|
|
21
|
+
- The use of sexualized language or imagery, and sexual attention or advances of any kind
|
|
22
|
+
- Trolling, insulting or derogatory comments, and personal or political attacks
|
|
23
|
+
- Public or private harassment
|
|
24
|
+
- Publishing others’ private information, such as a physical or email address, without their explicit permission
|
|
25
|
+
- Other conduct which could reasonably be considered inappropriate in a professional setting
|
|
26
|
+
|
|
27
|
+
## Enforcement Responsibilities
|
|
28
|
+
|
|
29
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
|
30
|
+
|
|
31
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
|
32
|
+
|
|
33
|
+
## Scope
|
|
34
|
+
|
|
35
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
|
36
|
+
|
|
37
|
+
## Enforcement
|
|
38
|
+
|
|
39
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [conduct@plasius.co.uk](mailto:conduct@plasius.co.uk). All complaints will be reviewed and investigated promptly and fairly.
|
|
40
|
+
|
|
41
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
|
42
|
+
|
|
43
|
+
## Enforcement Guidelines
|
|
44
|
+
|
|
45
|
+
Community leaders will follow these Enforcement Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
|
46
|
+
|
|
47
|
+
### 1. Correction
|
|
48
|
+
|
|
49
|
+
**Community Impact:** Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
|
50
|
+
|
|
51
|
+
**Consequence:** A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
|
52
|
+
|
|
53
|
+
### 2. Warning
|
|
54
|
+
|
|
55
|
+
**Community Impact:** A violation through a single incident or series of actions.
|
|
56
|
+
|
|
57
|
+
**Consequence:** A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
|
58
|
+
|
|
59
|
+
### 3. Temporary Ban
|
|
60
|
+
|
|
61
|
+
**Community Impact:** A serious violation of community standards, including sustained inappropriate behavior.
|
|
62
|
+
|
|
63
|
+
**Consequence:** A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
|
64
|
+
|
|
65
|
+
### 4. Permanent Ban
|
|
66
|
+
|
|
67
|
+
**Community Impact:** Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
|
68
|
+
|
|
69
|
+
**Consequence:** A permanent ban from any sort of public interaction within the community.
|
|
70
|
+
|
|
71
|
+
## Attribution
|
|
72
|
+
|
|
73
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.1, available at [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html](https://www.contributor-covenant.org/version/2/1/code_of_conduct.html)
|
|
74
|
+
|
|
75
|
+
For answers to common questions about this code of conduct, see the [FAQ](https://www.contributor-covenant.org/faq)
|
|
76
|
+
|
|
77
|
+
[homepage]: [https://www.contributor-covenant.org](https://www.contributor-covenant.org)
|
|
78
|
+
|
|
79
|
+
If you have any questions or concerns regarding this Code of Conduct, please contact us at [conduct@plasius.co.uk](mailto:conduct@plasius.co.uk).
|
package/CONTRIBUTORS.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Contributing Guidelines
|
|
2
|
+
|
|
3
|
+
Thank you for considering contributing to this project! We welcome contributions that improve the code, documentation, and overall project quality.
|
|
4
|
+
|
|
5
|
+
## Getting Started
|
|
6
|
+
|
|
7
|
+
- Fork the repository.
|
|
8
|
+
- Create a feature branch from `main`.
|
|
9
|
+
- Commit your changes with clear messages (we follow **Conventional Commits**).
|
|
10
|
+
- Push your branch and open a Pull Request (PR).
|
|
11
|
+
|
|
12
|
+
## Requirements
|
|
13
|
+
|
|
14
|
+
- Write tests alongside code where possible.
|
|
15
|
+
- Ensure all tests pass before submitting a PR.
|
|
16
|
+
- Follow the repository’s coding style and linting rules.
|
|
17
|
+
- Update documentation (README, ADRs, etc.) when making significant changes.
|
|
18
|
+
- When making architectural changes, create a new ADR (Architecture Decision Record) that **succeeds** the previous one rather than modifying old ADRs. This preserves history and ensures decisions are traceable.
|
|
19
|
+
- Use the [ADR template](./docs/adrs/adr-template.md) when writing new ADRs to ensure consistency.
|
|
20
|
+
- Before your first contribution, sign the appropriate Contributor License Agreement (CLA). See [legal/CLA.md](legal/CLA.md) for details, then email the signed document to [contributors@plasius.co.uk](mailto:contributors@plasius.co.uk).
|
|
21
|
+
|
|
22
|
+
## Communication
|
|
23
|
+
|
|
24
|
+
- Use GitHub Issues for bugs and feature requests.
|
|
25
|
+
- Pull Requests should describe the problem, solution, and trade-offs.
|
|
26
|
+
|
|
27
|
+
We appreciate your support in making this project better!
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Plasius LTD
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# @plasius/profile
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@plasius/profile)
|
|
4
|
+
[](https://github.com/Plasius-LTD/profile/actions/workflows/ci.yml)
|
|
5
|
+
[](https://codecov.io/gh/Plasius-LTD/profile)
|
|
6
|
+
[](./LICENSE)
|
|
7
|
+
[](./CODE_OF_CONDUCT.md)
|
|
8
|
+
[](./SECURITY.md)
|
|
9
|
+
[](./CHANGELOG.md)
|
|
10
|
+
|
|
11
|
+
Public package containing user/profile state and settings providers for Plasius React applications.
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @plasius/profile
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { UserProvider, SettingsProvider } from "@plasius/profile";
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Development
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm ci
|
|
30
|
+
npm run build
|
|
31
|
+
npm test
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Governance
|
|
35
|
+
|
|
36
|
+
- Security policy: [SECURITY.md](./SECURITY.md)
|
|
37
|
+
- Code of conduct: [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md)
|
|
38
|
+
- ADRs: [docs/adrs](./docs/adrs)
|
|
39
|
+
- Legal docs: [legal](./legal)
|
|
40
|
+
|
|
41
|
+
## License
|
|
42
|
+
|
|
43
|
+
MIT
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Supported Versions
|
|
4
|
+
|
|
5
|
+
We currently support the latest major version of this project. Older versions may not receive security updates.
|
|
6
|
+
|
|
7
|
+
## Reporting a Vulnerability
|
|
8
|
+
|
|
9
|
+
If you discover a security vulnerability, please report it privately by emailing us at [security@plasius.co.uk](mailto:security@plasius.co.uk). Please do not create a public issue for security-related matters.
|
|
10
|
+
|
|
11
|
+
## Response Timeline
|
|
12
|
+
|
|
13
|
+
We aim to acknowledge your report within 2 business days and to provide a more detailed response (including next steps and, if applicable, a timeline for a fix) within 7 business days.
|
|
14
|
+
|
|
15
|
+
## Disclosure Policy
|
|
16
|
+
|
|
17
|
+
We request that you give us the opportunity to address the vulnerability before publicly disclosing it. We will coordinate with you on public disclosure once a fix is available and deployed.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Settings.d.ts","sourceRoot":"","sources":["../../../src/Pages/Settings/Settings.tsx"],"names":[],"mappings":"AA0BA,wBAAgB,YAAY,4CAuM3B;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
import { userEntitySchema, userAvatarSchema, UserEmailPreferences, PreferredDisplayOrder, } from "@plasius/entity-manager";
|
|
4
|
+
import { useAuthorizedFetch } from "@plasius/auth";
|
|
5
|
+
import { useI18n } from "@plasius/translations";
|
|
6
|
+
import { UserStore } from "../../UserProvider.js";
|
|
7
|
+
import styles from "./Settings.module.css";
|
|
8
|
+
const getEmailPreferenceOptions = () => Object.entries(UserEmailPreferences).map(([key, value]) => ({
|
|
9
|
+
label: key.replace(/([a-z])([A-Z])/g, "$1 $2"), // Optional: format nicely
|
|
10
|
+
value,
|
|
11
|
+
}));
|
|
12
|
+
const getPreferredDisplayOrder = () => Object.entries(PreferredDisplayOrder).map(([key, value]) => ({
|
|
13
|
+
label: key.replace(/([a-z])([A-Z])/g, "$1 $2"), // Optional: format nicely
|
|
14
|
+
value,
|
|
15
|
+
}));
|
|
16
|
+
export function SettingsPage() {
|
|
17
|
+
const authorizedFetch = useAuthorizedFetch();
|
|
18
|
+
const { t } = useI18n();
|
|
19
|
+
const { user } = UserStore.useStore();
|
|
20
|
+
const dispatch = UserStore.useDispatch();
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (user) {
|
|
23
|
+
const res = userEntitySchema.validate(user);
|
|
24
|
+
if (!res.valid || res.errors?.length != 0) {
|
|
25
|
+
throw new Error(`Invalid user ${String(user)}. Errors: ${res.errors?.join("\n") ?? "unknown"}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}, [user]);
|
|
29
|
+
const handleChange = (e) => {
|
|
30
|
+
const { name, value } = e.target;
|
|
31
|
+
if (name.startsWith("name.")) {
|
|
32
|
+
const [, field] = name.split(".");
|
|
33
|
+
dispatch({ type: "updateNameField", payload: { field, value } });
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
dispatch({ type: "updateField", payload: { field: name, value } });
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const uploadAvatar = async (file) => {
|
|
40
|
+
const formData = new FormData();
|
|
41
|
+
formData.append("avatar", file); // "avatar" must match the expected server-side field
|
|
42
|
+
const response = await authorizedFetch(`/user/avatar`, {
|
|
43
|
+
method: "POST",
|
|
44
|
+
body: formData,
|
|
45
|
+
headers: {
|
|
46
|
+
// Do NOT set Content-Type explicitly; browser will set it with boundary
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
if (!response.ok) {
|
|
50
|
+
throw new Error("Failed to upload avatar");
|
|
51
|
+
}
|
|
52
|
+
const data = await response.json();
|
|
53
|
+
return data; // e.g. { imageUrl: "...uploaded file url..." }
|
|
54
|
+
};
|
|
55
|
+
const handleAvatarChange = async (e) => {
|
|
56
|
+
const file = e.target.files?.[0];
|
|
57
|
+
if (!file)
|
|
58
|
+
return;
|
|
59
|
+
try {
|
|
60
|
+
const uploadedAvatar = await uploadAvatar(file);
|
|
61
|
+
const validatedAvatar = userAvatarSchema.validate(uploadedAvatar);
|
|
62
|
+
if (!validatedAvatar.valid || validatedAvatar.errors?.length) {
|
|
63
|
+
throw new Error((validatedAvatar.errors ?? []).map((e) => String(e)).join("; "));
|
|
64
|
+
}
|
|
65
|
+
const base = validatedAvatar.value;
|
|
66
|
+
const userAvatar = {
|
|
67
|
+
...base,
|
|
68
|
+
originalName: file.name,
|
|
69
|
+
};
|
|
70
|
+
dispatch({
|
|
71
|
+
type: "updateField",
|
|
72
|
+
payload: {
|
|
73
|
+
field: "avatar",
|
|
74
|
+
value: userAvatar,
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
console.error(err);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const handleSubmit = (e) => {
|
|
83
|
+
e.preventDefault();
|
|
84
|
+
const errors = userEntitySchema.validate(user);
|
|
85
|
+
if (errors) {
|
|
86
|
+
console.warn("Validation failed", errors);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
console.info("Saved:", user);
|
|
90
|
+
};
|
|
91
|
+
return (_jsx("div", { className: styles.settingsContainer, children: _jsxs("form", { onSubmit: handleSubmit, className: styles.settingsForm, children: [_jsx("h2", { children: t("profile_settings") }), _jsxs("label", { className: styles.label, children: [t("upload_avatar"), _jsx("input", { type: "file", accept: "image/*", onChange: handleAvatarChange, className: styles.input })] }), user?.avatar?.url && (_jsx("div", { children: _jsx("img", { src: user?.avatar?.url, alt: t("avatar_preview"), className: styles.avatarPreview }) })), _jsxs("label", { className: styles.label, children: [t("first_name"), _jsx("input", { name: "name.firstName", value: user?.name?.firstName, onChange: handleChange, className: styles.input })] }), _jsxs("label", { className: styles.label, children: [t("middle_name"), _jsx("input", { name: "name.middleName", value: user?.name?.middleName, onChange: handleChange, className: styles.input })] }), _jsxs("label", { className: styles.label, children: [t("last_name"), _jsx("input", { name: "name.lastName", value: user?.name?.lastName, onChange: handleChange, className: styles.input })] }), _jsxs("label", { className: styles.label, children: [t("display_name"), _jsx("input", { name: "name.displayName", value: user?.name?.displayName, onChange: handleChange, className: styles.input })] }), _jsxs("label", { className: styles.label, children: [t("preferred_name_display"), _jsxs("select", { name: "displayPreferences", value: (user?.name).preferredDisplayOrder, onChange: handleChange, className: styles.select, children: [_jsx("option", { value: "", children: t("select_preference") }), getPreferredDisplayOrder().map((opt) => (_jsx("option", { value: opt.value, children: opt.label }, opt.value)))] })] }), _jsxs("label", { className: styles.label, children: [t("email"), _jsx("input", { name: "email", value: user?.email, onChange: handleChange, className: styles.input })] }), _jsxs("label", { className: styles.label, children: [t("email_preferences"), _jsxs("select", { name: "emailPreferences", value: user?.emailPreferences, onChange: handleChange, className: styles.select, children: [_jsx("option", { value: "", children: t("select_preference") }), getEmailPreferenceOptions().map((opt) => (_jsx("option", { value: opt.value, children: opt.label }, opt.value)))] })] }), _jsx("button", { type: "submit", className: styles.submitButton, children: t("save_settings") })] }) }));
|
|
92
|
+
}
|
|
93
|
+
export default SettingsPage;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
.avatarPreview {
|
|
2
|
+
margin-top: 10px;
|
|
3
|
+
border-radius: 50%;
|
|
4
|
+
overflow: hidden;
|
|
5
|
+
width: 100px;
|
|
6
|
+
height: 100px;
|
|
7
|
+
display: flex;
|
|
8
|
+
align-items: center;
|
|
9
|
+
justify-content: center;
|
|
10
|
+
background-color: var(--color-surface-muted);
|
|
11
|
+
box-shadow: var(--shadow-elevation-low);
|
|
12
|
+
transition: background-color 0.3s ease, box-shadow 0.3s ease;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Pages/Settings/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Settings.js";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { IState } from "@plasius/react-state";
|
|
3
|
+
export type SettingsState = IState & Record<string, unknown>;
|
|
4
|
+
export type SettingsAction = {
|
|
5
|
+
type: "update";
|
|
6
|
+
key: string;
|
|
7
|
+
value: unknown;
|
|
8
|
+
} | {
|
|
9
|
+
type: "reset";
|
|
10
|
+
} | {
|
|
11
|
+
type: "load";
|
|
12
|
+
payload: Partial<SettingsState>;
|
|
13
|
+
};
|
|
14
|
+
export declare const SettingsStore: {
|
|
15
|
+
Context: React.Context<import("@plasius/react-state").Store<SettingsState, SettingsAction> | null>;
|
|
16
|
+
Provider: ({ children, initialState: override, }: {
|
|
17
|
+
children: React.ReactNode;
|
|
18
|
+
initialState?: SettingsState | undefined;
|
|
19
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
20
|
+
useStore: () => SettingsState;
|
|
21
|
+
useDispatch: () => (action: SettingsAction) => void;
|
|
22
|
+
useSelector: <T>(selector: (state: SettingsState) => T, isEqual?: ((a: T, b: T) => boolean) | undefined) => T;
|
|
23
|
+
};
|
|
24
|
+
export declare const SettingsProvider: ({ children, configUrl, }: {
|
|
25
|
+
children: React.ReactNode;
|
|
26
|
+
configUrl?: string;
|
|
27
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
28
|
+
//# sourceMappingURL=SettingsProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SettingsProvider.d.ts","sourceRoot":"","sources":["../src/SettingsProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAoB,MAAM,OAAO,CAAC;AAEzC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAKnD,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE7D,MAAM,MAAM,cAAc,GACtB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAC/C;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,GACjB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,CAAA;CAAE,CAAC;AAoBtD,eAAO,MAAM,aAAa;;;;;;;;;CAGF,CAAC;AAEzB,eAAO,MAAM,gBAAgB,GAAI,0BAG9B;IACD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,4CAMA,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
const PRIVATE_ID = Symbol("settings.id");
|
|
3
|
+
const PRIVATE_PARTITION_KEY = Symbol("settings.partitionKey");
|
|
4
|
+
import { useEffect } from "react";
|
|
5
|
+
import { createScopedStoreContext } from "@plasius/react-state";
|
|
6
|
+
import { useAuthorizedFetch } from "@plasius/auth";
|
|
7
|
+
import { useQuery, useMutation, useQueryClient } from "@plasius/react-query";
|
|
8
|
+
const initialState = {};
|
|
9
|
+
const reducer = (state, action) => {
|
|
10
|
+
switch (action.type) {
|
|
11
|
+
case "update":
|
|
12
|
+
return { ...state, [action.key]: action.value };
|
|
13
|
+
case "load":
|
|
14
|
+
return { ...state, ...action.payload };
|
|
15
|
+
case "reset":
|
|
16
|
+
return initialState;
|
|
17
|
+
default:
|
|
18
|
+
return state;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
export const SettingsStore = createScopedStoreContext(reducer, initialState);
|
|
22
|
+
export const SettingsProvider = ({ children, configUrl = "/settings", }) => {
|
|
23
|
+
return (_jsx(SettingsStore.Provider, { children: _jsx(SettingsInitializer, { configUrl: configUrl, children: children }) }));
|
|
24
|
+
};
|
|
25
|
+
const SettingsInitializer = ({ children, configUrl, }) => {
|
|
26
|
+
const authorizedFetch = useAuthorizedFetch();
|
|
27
|
+
const dispatch = SettingsStore.useDispatch();
|
|
28
|
+
const state = SettingsStore.useStore();
|
|
29
|
+
const queryClient = useQueryClient();
|
|
30
|
+
const toSettingsEntity = (state) => {
|
|
31
|
+
const hidden = state;
|
|
32
|
+
return {
|
|
33
|
+
id: hidden[PRIVATE_ID] ?? "",
|
|
34
|
+
partitionKey: hidden[PRIVATE_PARTITION_KEY] ?? "",
|
|
35
|
+
settings: state,
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
const fromSettingsEntity = (entity) => {
|
|
39
|
+
const result = {
|
|
40
|
+
...entity.settings,
|
|
41
|
+
};
|
|
42
|
+
Object.defineProperty(result, PRIVATE_ID, {
|
|
43
|
+
value: entity.id,
|
|
44
|
+
enumerable: false,
|
|
45
|
+
writable: false,
|
|
46
|
+
});
|
|
47
|
+
Object.defineProperty(result, PRIVATE_PARTITION_KEY, {
|
|
48
|
+
value: entity.partitionKey,
|
|
49
|
+
enumerable: false,
|
|
50
|
+
writable: false,
|
|
51
|
+
});
|
|
52
|
+
return result;
|
|
53
|
+
};
|
|
54
|
+
const { data } = useQuery("settings", async () => {
|
|
55
|
+
const res = await authorizedFetch(configUrl);
|
|
56
|
+
if (!res.ok)
|
|
57
|
+
throw new Error(`Load failed with status ${res.status}`);
|
|
58
|
+
return (await res.json());
|
|
59
|
+
});
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (data) {
|
|
62
|
+
dispatch({ type: "load", payload: fromSettingsEntity(data) });
|
|
63
|
+
}
|
|
64
|
+
}, [data]);
|
|
65
|
+
const saveMutation = useMutation(async () => {
|
|
66
|
+
const res = await authorizedFetch(configUrl, {
|
|
67
|
+
method: "POST",
|
|
68
|
+
headers: {
|
|
69
|
+
"Content-Type": "application/json",
|
|
70
|
+
},
|
|
71
|
+
body: JSON.stringify(toSettingsEntity(state)),
|
|
72
|
+
});
|
|
73
|
+
if (!res.ok)
|
|
74
|
+
throw new Error(`Save failed with status ${res.status}`);
|
|
75
|
+
}, {
|
|
76
|
+
onSuccess: () => {
|
|
77
|
+
console.info("✅ Settings saved successfully.");
|
|
78
|
+
queryClient.invalidateQuery("settings", async () => {
|
|
79
|
+
const res = await authorizedFetch(configUrl);
|
|
80
|
+
if (!res.ok)
|
|
81
|
+
throw new Error(`Load failed with status ${res.status}`);
|
|
82
|
+
const entity = (await res.json());
|
|
83
|
+
return entity;
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
onError: (err) => {
|
|
87
|
+
console.error("❌ Error saving settings:", err);
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
return () => {
|
|
92
|
+
void saveMutation.mutate();
|
|
93
|
+
};
|
|
94
|
+
}, [saveMutation]);
|
|
95
|
+
return _jsx(_Fragment, { children: children });
|
|
96
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { type UserEntity } from "@plasius/entity-manager";
|
|
3
|
+
import { type IState } from "@plasius/react-state";
|
|
4
|
+
export declare function ValidateUser(user: UserEntity): UserEntity;
|
|
5
|
+
interface UserState extends IState {
|
|
6
|
+
user?: UserEntity;
|
|
7
|
+
userId: string | null;
|
|
8
|
+
}
|
|
9
|
+
type UserAction = {
|
|
10
|
+
type: "setUser";
|
|
11
|
+
user: UserEntity;
|
|
12
|
+
} | {
|
|
13
|
+
type: "setUserId";
|
|
14
|
+
userId: string | null;
|
|
15
|
+
} | {
|
|
16
|
+
type: "updateUser";
|
|
17
|
+
user: Partial<UserEntity>;
|
|
18
|
+
} | {
|
|
19
|
+
type: "updateField";
|
|
20
|
+
payload: {
|
|
21
|
+
field: string;
|
|
22
|
+
value: unknown;
|
|
23
|
+
};
|
|
24
|
+
} | {
|
|
25
|
+
type: "updateNameField";
|
|
26
|
+
payload: {
|
|
27
|
+
field: string;
|
|
28
|
+
value: unknown;
|
|
29
|
+
};
|
|
30
|
+
} | {
|
|
31
|
+
type: "updateAvatarField";
|
|
32
|
+
payload: {
|
|
33
|
+
field: string;
|
|
34
|
+
value: unknown;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export declare const UserStore: {
|
|
38
|
+
Context: React.Context<import("@plasius/react-state").Store<UserState, UserAction> | null>;
|
|
39
|
+
Provider: ({ children, initialState: override, }: {
|
|
40
|
+
children: React.ReactNode;
|
|
41
|
+
initialState?: UserState | undefined;
|
|
42
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
43
|
+
useStore: () => UserState;
|
|
44
|
+
useDispatch: () => (action: UserAction) => void;
|
|
45
|
+
useSelector: <T>(selector: (state: UserState) => T, isEqual?: ((a: T, b: T) => boolean) | undefined) => T;
|
|
46
|
+
};
|
|
47
|
+
export declare const UserProvider: ({ children }: {
|
|
48
|
+
children: React.ReactNode;
|
|
49
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
50
|
+
export {};
|
|
51
|
+
//# sourceMappingURL=UserProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UserProvider.d.ts","sourceRoot":"","sources":["../src/UserProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAiC,MAAM,OAAO,CAAC;AACtD,OAAO,EAAyB,KAAK,UAAU,EAAoB,MAAM,yBAAyB,CAAC;AAGnG,OAAO,EAA4B,KAAK,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE7E,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,GAON,UAAU,CAChD;AAED,UAAU,SAAU,SAAQ,MAAM;IAChC,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAED,KAAK,UAAU,GACX;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,UAAU,CAAA;CAAE,GACrC;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAC5C;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,CAAA;CAAE,GACjD;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,CAAA;CAAE,GACnE;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,CAAA;CAAE,GACvE;IAAE,IAAI,EAAE,mBAAmB,CAAC;IAAC,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,CAAA;CAAE,CAAC;AA4D9E,eAAO,MAAM,SAAS;;;;;;;;;CAAkD,CAAC;AAEzE,eAAO,MAAM,YAAY,GAAI,cAAc;IAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,4CAOvE,CAAC"}
|