@salesforce/webapp-template-feature-react-authentication-experimental 1.3.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/LICENSE.txt +82 -0
- package/README.md +77 -0
- package/dist/.a4drules/build-validation.md +81 -0
- package/dist/.a4drules/code-quality.md +150 -0
- package/dist/.a4drules/graphql/tools/knowledge/lds-explore-graphql-schema.md +227 -0
- package/dist/.a4drules/graphql/tools/knowledge/lds-generate-graphql-mutationquery.md +211 -0
- package/dist/.a4drules/graphql/tools/knowledge/lds-generate-graphql-readquery.md +185 -0
- package/dist/.a4drules/graphql/tools/knowledge/lds-guide-graphql.md +205 -0
- package/dist/.a4drules/graphql/tools/schemas/shared.graphqls +1150 -0
- package/dist/.a4drules/graphql.md +98 -0
- package/dist/.a4drules/images.md +13 -0
- package/dist/.a4drules/react.md +361 -0
- package/dist/.a4drules/react_image_processing.md +45 -0
- package/dist/.a4drules/typescript.md +224 -0
- package/dist/.forceignore +15 -0
- package/dist/.husky/pre-commit +4 -0
- package/dist/.prettierignore +11 -0
- package/dist/.prettierrc +17 -0
- package/dist/CHANGELOG.md +19 -0
- package/dist/README.md +18 -0
- package/dist/config/project-scratch-def.json +13 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/.prettierignore +9 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/.prettierrc +11 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/eslint.config.js +113 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/feature-react-authentication.webapplication-meta.xml +7 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/index.html +13 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/package.json +42 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/api/graphql-operations-types.ts +127 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/api/utils/query/highRevenueAccountsQuery.graphql +29 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/app.tsx +16 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/appLayout.tsx +9 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/assets/icons/book.svg +3 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/assets/icons/copy.svg +4 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/assets/icons/rocket.svg +3 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/assets/icons/star.svg +3 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/assets/images/codey-1.png +0 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/assets/images/codey-2.png +0 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/assets/images/codey-3.png +0 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/assets/images/vibe-codey.svg +194 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/alerts/status-alert.tsx +45 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/auth/authentication-route.tsx +21 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/auth/private-route.tsx +36 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/footers/footer-link.tsx +36 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/forms/auth-form.tsx +79 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/forms/submit-button.tsx +49 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/layout/card-layout.tsx +23 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/layout/centered-page-layout.tsx +73 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/layout/loading-page.tsx +46 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/ui/alert.tsx +65 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/ui/button.tsx +56 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/ui/card.tsx +77 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/ui/field.tsx +111 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/ui/index.ts +71 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/ui/input.tsx +19 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/ui/label.tsx +19 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/ui/pagination.tsx +99 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/ui/select.tsx +151 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/ui/skeleton.tsx +7 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/ui/spinner.tsx +21 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/ui/table.tsx +114 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/ui/tabs.tsx +115 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/context/AuthContext.tsx +83 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/hooks/form.tsx +116 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/lib/utils.ts +6 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/pages/About.tsx +12 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/pages/ChangePassword.tsx +105 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/pages/ForgotPassword.tsx +67 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/pages/Home.tsx +12 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/pages/Login.tsx +84 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/pages/NotFound.tsx +18 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/pages/Profile.tsx +146 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/pages/Register.tsx +117 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/pages/ResetPassword.tsx +101 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/routes.tsx +77 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/styles/global.css +94 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/utils/authenticationConfig.ts +52 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/src/utils/helpers.ts +161 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/tsconfig.json +36 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/tsconfig.node.json +13 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/vite-env.d.ts +1 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/vite.config.ts +82 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/vitest-env.d.ts +2 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/vitest.config.ts +11 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/vitest.setup.ts +1 -0
- package/dist/force-app/main/default/webapplications/feature-react-authentication/webapplication.json +7 -0
- package/dist/jest.config.js +6 -0
- package/dist/package.json +37 -0
- package/dist/scripts/apex/hello.apex +10 -0
- package/dist/scripts/soql/account.soql +6 -0
- package/dist/sfdx-project.json +12 -0
- package/package.json +31 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { Link } from "react-router";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { baseClient } from "@salesforce/webapp-experimental/api";
|
|
5
|
+
import { CenteredPageLayout } from "../components/layout/centered-page-layout";
|
|
6
|
+
import { AuthForm } from "../components/forms/auth-form";
|
|
7
|
+
import { useAppForm } from "../hooks/form";
|
|
8
|
+
import { ROUTES, AUTH_PLACEHOLDERS } from "../utils/authenticationConfig";
|
|
9
|
+
import { newPasswordSchema, handleApiResponse, getErrorMessage } from "../utils/helpers";
|
|
10
|
+
import { getUser } from "../context/AuthContext";
|
|
11
|
+
|
|
12
|
+
const changePasswordSchema = z
|
|
13
|
+
.object({
|
|
14
|
+
currentPassword: z.string().min(1, "Current password is required"),
|
|
15
|
+
})
|
|
16
|
+
.and(newPasswordSchema);
|
|
17
|
+
|
|
18
|
+
export default function ChangePassword() {
|
|
19
|
+
const [success, setSuccess] = useState(false);
|
|
20
|
+
const [submitError, setSubmitError] = useState<string | null>(null);
|
|
21
|
+
const user = getUser();
|
|
22
|
+
|
|
23
|
+
const form = useAppForm({
|
|
24
|
+
defaultValues: { currentPassword: "", newPassword: "", confirmPassword: "" },
|
|
25
|
+
validators: { onChange: changePasswordSchema, onSubmit: changePasswordSchema },
|
|
26
|
+
onSubmit: async ({ value }) => {
|
|
27
|
+
setSubmitError(null);
|
|
28
|
+
setSuccess(false);
|
|
29
|
+
try {
|
|
30
|
+
// [Dev Note] Custom Apex Endpoint: /auth/change-password
|
|
31
|
+
// Security Critical:
|
|
32
|
+
// We must pass the `user.id` (from AuthContext) to the Apex endpoint
|
|
33
|
+
// to ensure the password change is applied to the correct user.
|
|
34
|
+
// The Apex backend should also verify that the authenticated session matches this ID.
|
|
35
|
+
// You must ensure this Apex class exists in your org
|
|
36
|
+
const response = await baseClient.post("/services/apexrest/auth/change-password", {
|
|
37
|
+
userId: user.id,
|
|
38
|
+
currentPassword: value.currentPassword,
|
|
39
|
+
newPassword: value.newPassword,
|
|
40
|
+
});
|
|
41
|
+
await handleApiResponse(response, "Password change failed");
|
|
42
|
+
setSuccess(true);
|
|
43
|
+
form.reset();
|
|
44
|
+
} catch (err) {
|
|
45
|
+
setSubmitError(getErrorMessage(err, "Password change failed"));
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
onSubmitInvalid: () => {},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<CenteredPageLayout title={ROUTES.CHANGE_PASSWORD.TITLE}>
|
|
53
|
+
<form.AppForm>
|
|
54
|
+
<AuthForm
|
|
55
|
+
title="Change Password"
|
|
56
|
+
description="Enter your current and new password below"
|
|
57
|
+
error={submitError}
|
|
58
|
+
success={
|
|
59
|
+
success && (
|
|
60
|
+
<>
|
|
61
|
+
Password changed successfully!{" "}
|
|
62
|
+
<Link to={ROUTES.PROFILE.PATH} className="underline">
|
|
63
|
+
Back to Profile
|
|
64
|
+
</Link>
|
|
65
|
+
</>
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
submit={{ text: "Change Password", loadingText: "Changing…" }}
|
|
69
|
+
footer={{ link: ROUTES.PROFILE.PATH, linkText: "Back to Profile" }}
|
|
70
|
+
>
|
|
71
|
+
<form.AppField name="currentPassword">
|
|
72
|
+
{(field) => (
|
|
73
|
+
<field.PasswordField
|
|
74
|
+
label="Current Password"
|
|
75
|
+
placeholder={AUTH_PLACEHOLDERS.PASSWORD}
|
|
76
|
+
autoComplete="current-password"
|
|
77
|
+
disabled={success}
|
|
78
|
+
/>
|
|
79
|
+
)}
|
|
80
|
+
</form.AppField>
|
|
81
|
+
<form.AppField name="newPassword">
|
|
82
|
+
{(field) => (
|
|
83
|
+
<field.PasswordField
|
|
84
|
+
label="New Password"
|
|
85
|
+
placeholder={AUTH_PLACEHOLDERS.PASSWORD_NEW}
|
|
86
|
+
autoComplete="new-password"
|
|
87
|
+
disabled={success}
|
|
88
|
+
/>
|
|
89
|
+
)}
|
|
90
|
+
</form.AppField>
|
|
91
|
+
<form.AppField name="confirmPassword">
|
|
92
|
+
{(field) => (
|
|
93
|
+
<field.PasswordField
|
|
94
|
+
label="Confirm Password"
|
|
95
|
+
placeholder={AUTH_PLACEHOLDERS.PASSWORD_NEW_CONFIRM}
|
|
96
|
+
autoComplete="new-password"
|
|
97
|
+
disabled={success}
|
|
98
|
+
/>
|
|
99
|
+
)}
|
|
100
|
+
</form.AppField>
|
|
101
|
+
</AuthForm>
|
|
102
|
+
</form.AppForm>
|
|
103
|
+
</CenteredPageLayout>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { baseClient } from "@salesforce/webapp-experimental/api";
|
|
4
|
+
import { CenteredPageLayout } from "../components/layout/centered-page-layout";
|
|
5
|
+
import { AuthForm } from "../components/forms/auth-form";
|
|
6
|
+
import { useAppForm } from "../hooks/form";
|
|
7
|
+
import { ROUTES, AUTH_PLACEHOLDERS } from "../utils/authenticationConfig";
|
|
8
|
+
import { handleApiResponse, getErrorMessage } from "../utils/helpers";
|
|
9
|
+
|
|
10
|
+
const forgotPasswordSchema = z.object({
|
|
11
|
+
username: z.string().trim().toLowerCase().email("Please enter a valid username"),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export default function ForgotPassword() {
|
|
15
|
+
const [success, setSuccess] = useState(false);
|
|
16
|
+
const [submitError, setSubmitError] = useState<string | null>(null);
|
|
17
|
+
|
|
18
|
+
const form = useAppForm({
|
|
19
|
+
defaultValues: { username: "" },
|
|
20
|
+
validators: { onChange: forgotPasswordSchema, onSubmit: forgotPasswordSchema },
|
|
21
|
+
onSubmit: async ({ value }) => {
|
|
22
|
+
setSubmitError(null);
|
|
23
|
+
setSuccess(false);
|
|
24
|
+
try {
|
|
25
|
+
// [Dev Note] Custom Apex Endpoint: /auth/forgot-password
|
|
26
|
+
// You must ensure this Apex class exists in your org
|
|
27
|
+
const response = await baseClient.post("/services/apexrest/auth/forgot-password", {
|
|
28
|
+
username: value.username.trim(),
|
|
29
|
+
});
|
|
30
|
+
await handleApiResponse(response, "Failed to send reset link");
|
|
31
|
+
setSuccess(true);
|
|
32
|
+
} catch (err) {
|
|
33
|
+
setSubmitError(getErrorMessage(err, "Failed to send reset link"));
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
onSubmitInvalid: () => {},
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<CenteredPageLayout title={ROUTES.FORGOT_PASSWORD.TITLE}>
|
|
41
|
+
<form.AppForm>
|
|
42
|
+
<AuthForm
|
|
43
|
+
title="Forgot Password"
|
|
44
|
+
description="Enter your username and we'll send you a reset link"
|
|
45
|
+
error={submitError}
|
|
46
|
+
success={
|
|
47
|
+
success &&
|
|
48
|
+
"If that username exists in our system, you will receive a reset link shortly."
|
|
49
|
+
}
|
|
50
|
+
submit={{ text: "Send Reset Link", loadingText: "Sending…" }}
|
|
51
|
+
footer={{ text: "Remember your password?", link: ROUTES.LOGIN.PATH, linkText: "Sign in" }}
|
|
52
|
+
>
|
|
53
|
+
<form.AppField name="username">
|
|
54
|
+
{(field) => (
|
|
55
|
+
<field.TextField
|
|
56
|
+
label="Username"
|
|
57
|
+
placeholder={AUTH_PLACEHOLDERS.USERNAME}
|
|
58
|
+
autoComplete="username"
|
|
59
|
+
disabled={success}
|
|
60
|
+
/>
|
|
61
|
+
)}
|
|
62
|
+
</form.AppField>
|
|
63
|
+
</AuthForm>
|
|
64
|
+
</form.AppForm>
|
|
65
|
+
</CenteredPageLayout>
|
|
66
|
+
);
|
|
67
|
+
}
|
package/dist/force-app/main/default/webapplications/feature-react-authentication/src/pages/Home.tsx
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export default function Home() {
|
|
2
|
+
return (
|
|
3
|
+
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
|
|
4
|
+
<div className="text-center">
|
|
5
|
+
<h1 className="text-4xl font-bold text-gray-900 mb-4">Home</h1>
|
|
6
|
+
<p className="text-lg text-gray-600 mb-8">
|
|
7
|
+
Welcome to your React application.
|
|
8
|
+
</p>
|
|
9
|
+
</div>
|
|
10
|
+
</div>
|
|
11
|
+
);
|
|
12
|
+
}
|
package/dist/force-app/main/default/webapplications/feature-react-authentication/src/pages/Login.tsx
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { useNavigate, useSearchParams, Link } from "react-router";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { baseClient } from "@salesforce/webapp-experimental/api";
|
|
5
|
+
import { CenteredPageLayout } from "../components/layout/centered-page-layout";
|
|
6
|
+
import { AuthForm } from "../components/forms/auth-form";
|
|
7
|
+
import { useAppForm } from "../hooks/form";
|
|
8
|
+
import { ROUTES } from "../utils/authenticationConfig";
|
|
9
|
+
import { emailSchema, getStartUrl, handleApiResponse, getErrorMessage } from "../utils/helpers";
|
|
10
|
+
|
|
11
|
+
const loginSchema = z.object({
|
|
12
|
+
email: emailSchema,
|
|
13
|
+
password: z.string().min(1, "Password is required"),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export default function Login() {
|
|
17
|
+
const navigate = useNavigate();
|
|
18
|
+
const [searchParams] = useSearchParams();
|
|
19
|
+
const [submitError, setSubmitError] = useState<string | null>(null);
|
|
20
|
+
|
|
21
|
+
const form = useAppForm({
|
|
22
|
+
defaultValues: { email: "", password: "" },
|
|
23
|
+
validators: { onChange: loginSchema, onSubmit: loginSchema },
|
|
24
|
+
onSubmit: async ({ value }) => {
|
|
25
|
+
setSubmitError(null);
|
|
26
|
+
try {
|
|
27
|
+
// [Dev Note] Salesforce Integration:
|
|
28
|
+
// We use 'baseClient.post' to make an authenticated (or guest) call to Salesforce.
|
|
29
|
+
// "/services/apexrest/auth/login" refers to a custom Apex Class exposed as a REST resource.
|
|
30
|
+
// You must ensure this Apex class exists in your org and handles the login logic
|
|
31
|
+
// (e.g., creating a session or returning a token).
|
|
32
|
+
const response = await baseClient.post("/services/apexrest/auth/login", {
|
|
33
|
+
email: value.email.trim().toLowerCase(),
|
|
34
|
+
password: value.password,
|
|
35
|
+
});
|
|
36
|
+
await handleApiResponse(response, "Login failed");
|
|
37
|
+
|
|
38
|
+
// [Dev Note] After successful API call, redirect to the intended page.
|
|
39
|
+
// The session cookie is typically set by the server/Apex response headers.
|
|
40
|
+
navigate(getStartUrl(searchParams), { replace: true });
|
|
41
|
+
} catch (err) {
|
|
42
|
+
setSubmitError(getErrorMessage(err, "Login failed"));
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
onSubmitInvalid: () => {},
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<CenteredPageLayout title={ROUTES.LOGIN.TITLE}>
|
|
50
|
+
<form.AppForm>
|
|
51
|
+
<AuthForm
|
|
52
|
+
title="Login"
|
|
53
|
+
description="Enter your email below to login to your account"
|
|
54
|
+
error={submitError}
|
|
55
|
+
submit={{ text: "Login", loadingText: "Logging in…" }}
|
|
56
|
+
footer={{
|
|
57
|
+
text: "Don't have an account?",
|
|
58
|
+
link: ROUTES.REGISTER.PATH,
|
|
59
|
+
linkText: "Sign up",
|
|
60
|
+
}}
|
|
61
|
+
>
|
|
62
|
+
<form.AppField name="email">
|
|
63
|
+
{(field) => <field.EmailField label="Email" />}
|
|
64
|
+
</form.AppField>
|
|
65
|
+
<form.AppField name="password">
|
|
66
|
+
{(field) => (
|
|
67
|
+
<field.PasswordField
|
|
68
|
+
label="Password"
|
|
69
|
+
labelAction={
|
|
70
|
+
<Link
|
|
71
|
+
to={ROUTES.FORGOT_PASSWORD.PATH}
|
|
72
|
+
className="text-sm underline-offset-4 hover:underline"
|
|
73
|
+
>
|
|
74
|
+
Forgot your password?
|
|
75
|
+
</Link>
|
|
76
|
+
}
|
|
77
|
+
/>
|
|
78
|
+
)}
|
|
79
|
+
</form.AppField>
|
|
80
|
+
</AuthForm>
|
|
81
|
+
</form.AppForm>
|
|
82
|
+
</CenteredPageLayout>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Link } from 'react-router';
|
|
2
|
+
|
|
3
|
+
export default function NotFound() {
|
|
4
|
+
return (
|
|
5
|
+
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
|
|
6
|
+
<div className="text-center">
|
|
7
|
+
<h1 className="text-4xl font-bold text-gray-900 mb-4">404</h1>
|
|
8
|
+
<p className="text-lg text-gray-600 mb-8">Page not found</p>
|
|
9
|
+
<Link
|
|
10
|
+
to="/"
|
|
11
|
+
className="inline-block px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 transition-colors"
|
|
12
|
+
>
|
|
13
|
+
Go to Home
|
|
14
|
+
</Link>
|
|
15
|
+
</div>
|
|
16
|
+
</div>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { useState, useEffect } from "react";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
// [Dev Note] These are standard Salesforce SDK methods that interact with the UI API.
|
|
5
|
+
// They respect field-level security and validation rules defined in Salesforce.
|
|
6
|
+
import { getRecord, updateRecord } from "@salesforce/webapp-experimental/api";
|
|
7
|
+
|
|
8
|
+
import { CenteredPageLayout } from "../components/layout/centered-page-layout";
|
|
9
|
+
import { LoadingPage } from "../components/layout/loading-page";
|
|
10
|
+
import { AuthForm } from "../components/forms/auth-form";
|
|
11
|
+
import { useAppForm } from "../hooks/form";
|
|
12
|
+
import { ROUTES } from "../utils/authenticationConfig";
|
|
13
|
+
import { emailSchema, flattenUiApiRecord, getErrorMessage } from "../utils/helpers";
|
|
14
|
+
import { getUser } from "../context/AuthContext";
|
|
15
|
+
|
|
16
|
+
const optionalString = z
|
|
17
|
+
.string()
|
|
18
|
+
.trim()
|
|
19
|
+
.transform((val) => (val === "" ? null : val))
|
|
20
|
+
.nullable()
|
|
21
|
+
.optional();
|
|
22
|
+
|
|
23
|
+
const profileSchema = z.object({
|
|
24
|
+
FirstName: z.string().trim().min(1, "First name is required"),
|
|
25
|
+
LastName: z.string().trim().min(1, "Last name is required"),
|
|
26
|
+
Email: emailSchema,
|
|
27
|
+
Phone: optionalString,
|
|
28
|
+
Street: optionalString,
|
|
29
|
+
City: optionalString,
|
|
30
|
+
State: optionalString,
|
|
31
|
+
PostalCode: optionalString,
|
|
32
|
+
Country: optionalString,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
type ProfileFormValues = z.infer<typeof profileSchema>;
|
|
36
|
+
|
|
37
|
+
export default function Profile() {
|
|
38
|
+
const user = getUser();
|
|
39
|
+
const [profile, setProfile] = useState<ProfileFormValues | null>(null);
|
|
40
|
+
const [loadError, setLoadError] = useState<string | null>(null);
|
|
41
|
+
const [success, setSuccess] = useState(false);
|
|
42
|
+
const [submitError, setSubmitError] = useState<string | null>(null);
|
|
43
|
+
|
|
44
|
+
const form = useAppForm({
|
|
45
|
+
defaultValues: {} as ProfileFormValues,
|
|
46
|
+
validators: { onChange: profileSchema, onSubmit: profileSchema },
|
|
47
|
+
onSubmit: async ({ value }) => {
|
|
48
|
+
setSubmitError(null);
|
|
49
|
+
setSuccess(false);
|
|
50
|
+
try {
|
|
51
|
+
// [Dev Note] updateRecord automatically handles the PATCH request to the UI API.
|
|
52
|
+
// It expects the Record ID (user.id) and an object of field values.
|
|
53
|
+
const record = await updateRecord(user.id, value);
|
|
54
|
+
|
|
55
|
+
// [Dev Note] We flatten the complex UI API response structure for easier local use.
|
|
56
|
+
setProfile(flattenUiApiRecord(record));
|
|
57
|
+
|
|
58
|
+
setSuccess(true);
|
|
59
|
+
// Scroll to top of page after successful update so user sees it
|
|
60
|
+
window.scrollTo({ top: 0, behavior: "smooth" });
|
|
61
|
+
} catch (err) {
|
|
62
|
+
setSubmitError(getErrorMessage(err, "Failed to update profile"));
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
onSubmitInvalid: () => {},
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
let mounted = true;
|
|
70
|
+
|
|
71
|
+
// [Dev Note] Fetch the user record fields. "layoutTypes: 'Full'" asks for the default layout fields.
|
|
72
|
+
// Ensure the authenticated user has Read access to these fields in Salesforce.
|
|
73
|
+
getRecord(user.id, { layoutTypes: "Full" })
|
|
74
|
+
.then((record: any) => mounted && setProfile(flattenUiApiRecord(record)))
|
|
75
|
+
.catch((err: any) => {
|
|
76
|
+
if (mounted) {
|
|
77
|
+
setLoadError(getErrorMessage(err, "Failed to load profile"));
|
|
78
|
+
} else {
|
|
79
|
+
console.error("Failed to load profile", err);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
return () => {
|
|
83
|
+
mounted = false;
|
|
84
|
+
};
|
|
85
|
+
}, [user.id]);
|
|
86
|
+
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
if (profile) {
|
|
89
|
+
const formData = profileSchema.parse(profile);
|
|
90
|
+
form.reset(formData);
|
|
91
|
+
}
|
|
92
|
+
}, [profile]);
|
|
93
|
+
|
|
94
|
+
if (!profile && !loadError) {
|
|
95
|
+
return <LoadingPage contentMaxWidth="md" loadingText="Loading profile…" />;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<CenteredPageLayout contentMaxWidth="md" title={ROUTES.PROFILE.TITLE}>
|
|
100
|
+
<form.AppForm>
|
|
101
|
+
<AuthForm
|
|
102
|
+
title="Profile"
|
|
103
|
+
description="Update your account information"
|
|
104
|
+
error={loadError ?? submitError}
|
|
105
|
+
success={success && "Profile updated!"}
|
|
106
|
+
submit={{ text: "Save Changes", loadingText: "Saving…" }}
|
|
107
|
+
footer={{ link: ROUTES.CHANGE_PASSWORD.PATH, linkText: "Change password" }}
|
|
108
|
+
>
|
|
109
|
+
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 items-start">
|
|
110
|
+
<form.AppField name="FirstName">
|
|
111
|
+
{(field) => <field.TextField label="First name" autoComplete="given-name" />}
|
|
112
|
+
</form.AppField>
|
|
113
|
+
<form.AppField name="LastName">
|
|
114
|
+
{(field) => <field.TextField label="Last name" autoComplete="family-name" />}
|
|
115
|
+
</form.AppField>
|
|
116
|
+
</div>
|
|
117
|
+
<form.AppField name="Email">
|
|
118
|
+
{(field) => <field.EmailField label="Email" />}
|
|
119
|
+
</form.AppField>
|
|
120
|
+
<form.AppField name="Phone">
|
|
121
|
+
{(field) => <field.TextField label="Phone" type="tel" autoComplete="tel" />}
|
|
122
|
+
</form.AppField>
|
|
123
|
+
<form.AppField name="Street">
|
|
124
|
+
{(field) => <field.TextField label="Street" autoComplete="street-address" />}
|
|
125
|
+
</form.AppField>
|
|
126
|
+
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 items-start">
|
|
127
|
+
<form.AppField name="City">
|
|
128
|
+
{(field) => <field.TextField label="City" autoComplete="address-level2" />}
|
|
129
|
+
</form.AppField>
|
|
130
|
+
<form.AppField name="State">
|
|
131
|
+
{(field) => <field.TextField label="State" autoComplete="address-level1" />}
|
|
132
|
+
</form.AppField>
|
|
133
|
+
</div>
|
|
134
|
+
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 items-start">
|
|
135
|
+
<form.AppField name="PostalCode">
|
|
136
|
+
{(field) => <field.TextField label="Postal Code" autoComplete="postal-code" />}
|
|
137
|
+
</form.AppField>
|
|
138
|
+
<form.AppField name="Country">
|
|
139
|
+
{(field) => <field.TextField label="Country" autoComplete="country-name" />}
|
|
140
|
+
</form.AppField>
|
|
141
|
+
</div>
|
|
142
|
+
</AuthForm>
|
|
143
|
+
</form.AppForm>
|
|
144
|
+
</CenteredPageLayout>
|
|
145
|
+
);
|
|
146
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { useNavigate, useSearchParams } from "react-router";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { baseClient } from "@salesforce/webapp-experimental/api";
|
|
5
|
+
import { CenteredPageLayout } from "../components/layout/centered-page-layout";
|
|
6
|
+
import { AuthForm } from "../components/forms/auth-form";
|
|
7
|
+
import { useAppForm } from "../hooks/form";
|
|
8
|
+
import { ROUTES, AUTH_PLACEHOLDERS } from "../utils/authenticationConfig";
|
|
9
|
+
import {
|
|
10
|
+
emailSchema,
|
|
11
|
+
passwordSchema,
|
|
12
|
+
getStartUrl,
|
|
13
|
+
handleApiResponse,
|
|
14
|
+
getErrorMessage,
|
|
15
|
+
} from "../utils/helpers";
|
|
16
|
+
|
|
17
|
+
const registerSchema = z
|
|
18
|
+
.object({
|
|
19
|
+
firstName: z.string().trim().min(1, "First name is required"),
|
|
20
|
+
lastName: z.string().trim().min(1, "Last name is required"),
|
|
21
|
+
email: emailSchema,
|
|
22
|
+
password: passwordSchema,
|
|
23
|
+
confirmPassword: z.string().min(1, "Please confirm your password"),
|
|
24
|
+
})
|
|
25
|
+
.refine((data) => data.password === data.confirmPassword, {
|
|
26
|
+
message: "Passwords do not match",
|
|
27
|
+
path: ["confirmPassword"],
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export default function Register() {
|
|
31
|
+
const navigate = useNavigate();
|
|
32
|
+
const [searchParams] = useSearchParams();
|
|
33
|
+
const [submitError, setSubmitError] = useState<string | null>(null);
|
|
34
|
+
|
|
35
|
+
const form = useAppForm({
|
|
36
|
+
defaultValues: { firstName: "", lastName: "", email: "", password: "", confirmPassword: "" },
|
|
37
|
+
validators: { onChange: registerSchema, onSubmit: registerSchema },
|
|
38
|
+
onSubmit: async ({ value }) => {
|
|
39
|
+
setSubmitError(null);
|
|
40
|
+
try {
|
|
41
|
+
// [Dev Note] Calls the custom Apex REST endpoint for user registration.
|
|
42
|
+
// Ensure your Apex logic handles duplicate checks and user creation (e.g., Site.createExternalUser).
|
|
43
|
+
const response = await baseClient.post("/services/apexrest/auth/register", {
|
|
44
|
+
firstName: value.firstName.trim(),
|
|
45
|
+
lastName: value.lastName.trim(),
|
|
46
|
+
email: value.email.trim().toLowerCase(),
|
|
47
|
+
password: value.password,
|
|
48
|
+
});
|
|
49
|
+
await handleApiResponse(response, "Registration failed");
|
|
50
|
+
navigate(getStartUrl(searchParams), { replace: true });
|
|
51
|
+
} catch (err) {
|
|
52
|
+
setSubmitError(getErrorMessage(err, "Registration failed"));
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
onSubmitInvalid: () => {},
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<CenteredPageLayout title={ROUTES.REGISTER.TITLE}>
|
|
60
|
+
<form.AppForm>
|
|
61
|
+
<AuthForm
|
|
62
|
+
title="Sign Up"
|
|
63
|
+
description="Enter your information to create an account"
|
|
64
|
+
error={submitError}
|
|
65
|
+
submit={{ text: "Create an account", loadingText: "Creating account…" }}
|
|
66
|
+
footer={{
|
|
67
|
+
text: "Already have an account?",
|
|
68
|
+
link: ROUTES.LOGIN.PATH,
|
|
69
|
+
linkText: "Sign in",
|
|
70
|
+
}}
|
|
71
|
+
>
|
|
72
|
+
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 items-start">
|
|
73
|
+
<form.AppField name="firstName">
|
|
74
|
+
{(field) => (
|
|
75
|
+
<field.TextField
|
|
76
|
+
label="First name"
|
|
77
|
+
placeholder={AUTH_PLACEHOLDERS.FIRST_NAME}
|
|
78
|
+
autoComplete="given-name"
|
|
79
|
+
/>
|
|
80
|
+
)}
|
|
81
|
+
</form.AppField>
|
|
82
|
+
<form.AppField name="lastName">
|
|
83
|
+
{(field) => (
|
|
84
|
+
<field.TextField
|
|
85
|
+
label="Last name"
|
|
86
|
+
placeholder={AUTH_PLACEHOLDERS.LAST_NAME}
|
|
87
|
+
autoComplete="family-name"
|
|
88
|
+
/>
|
|
89
|
+
)}
|
|
90
|
+
</form.AppField>
|
|
91
|
+
</div>
|
|
92
|
+
<form.AppField name="email">
|
|
93
|
+
{(field) => <field.EmailField label="Email" />}
|
|
94
|
+
</form.AppField>
|
|
95
|
+
<form.AppField name="password">
|
|
96
|
+
{(field) => (
|
|
97
|
+
<field.PasswordField
|
|
98
|
+
label="Password"
|
|
99
|
+
placeholder={AUTH_PLACEHOLDERS.PASSWORD_CREATE}
|
|
100
|
+
autoComplete="new-password"
|
|
101
|
+
/>
|
|
102
|
+
)}
|
|
103
|
+
</form.AppField>
|
|
104
|
+
<form.AppField name="confirmPassword">
|
|
105
|
+
{(field) => (
|
|
106
|
+
<field.PasswordField
|
|
107
|
+
label="Confirm Password"
|
|
108
|
+
placeholder={AUTH_PLACEHOLDERS.PASSWORD_CONFIRM}
|
|
109
|
+
autoComplete="new-password"
|
|
110
|
+
/>
|
|
111
|
+
)}
|
|
112
|
+
</form.AppField>
|
|
113
|
+
</AuthForm>
|
|
114
|
+
</form.AppForm>
|
|
115
|
+
</CenteredPageLayout>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { Link, useSearchParams } from "react-router";
|
|
3
|
+
import { baseClient } from "@salesforce/webapp-experimental/api";
|
|
4
|
+
import { CardLayout } from "../components/layout/card-layout";
|
|
5
|
+
import { CenteredPageLayout } from "../components/layout/centered-page-layout";
|
|
6
|
+
import { AuthForm } from "../components/forms/auth-form";
|
|
7
|
+
import { StatusAlert } from "../components/alerts/status-alert";
|
|
8
|
+
import { useAppForm } from "../hooks/form";
|
|
9
|
+
import { ROUTES, AUTH_PLACEHOLDERS } from "../utils/authenticationConfig";
|
|
10
|
+
import { newPasswordSchema, handleApiResponse, getErrorMessage } from "../utils/helpers";
|
|
11
|
+
|
|
12
|
+
export default function ResetPassword() {
|
|
13
|
+
const [searchParams] = useSearchParams();
|
|
14
|
+
const token = searchParams.get("token");
|
|
15
|
+
const [success, setSuccess] = useState(false);
|
|
16
|
+
const [submitError, setSubmitError] = useState<string | null>(null);
|
|
17
|
+
|
|
18
|
+
const form = useAppForm({
|
|
19
|
+
defaultValues: { newPassword: "", confirmPassword: "" },
|
|
20
|
+
validators: { onChange: newPasswordSchema, onSubmit: newPasswordSchema },
|
|
21
|
+
onSubmit: async ({ value }) => {
|
|
22
|
+
setSubmitError(null);
|
|
23
|
+
setSuccess(false);
|
|
24
|
+
try {
|
|
25
|
+
// [Dev Note] Custom Apex Endpoint: /auth/reset-password
|
|
26
|
+
// You must ensure this Apex class exists in your org
|
|
27
|
+
const response = await baseClient.post("/services/apexrest/auth/reset-password", {
|
|
28
|
+
token,
|
|
29
|
+
newPassword: value.newPassword,
|
|
30
|
+
});
|
|
31
|
+
await handleApiResponse(response, "Password reset failed");
|
|
32
|
+
setSuccess(true);
|
|
33
|
+
// Scroll to top of page after successful submission so user sees it
|
|
34
|
+
window.scrollTo({ top: 0, behavior: "smooth" });
|
|
35
|
+
} catch (err) {
|
|
36
|
+
setSubmitError(getErrorMessage(err, "Password reset failed"));
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
onSubmitInvalid: () => {},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
if (!token) {
|
|
43
|
+
return (
|
|
44
|
+
<CenteredPageLayout title={ROUTES.RESET_PASSWORD.TITLE}>
|
|
45
|
+
<CardLayout title="Reset Password">
|
|
46
|
+
<StatusAlert>
|
|
47
|
+
Reset token is invalid or expired.{" "}
|
|
48
|
+
<Link to={ROUTES.FORGOT_PASSWORD.PATH} className="underline underline-offset-4">
|
|
49
|
+
Request a new password reset link.
|
|
50
|
+
</Link>
|
|
51
|
+
</StatusAlert>
|
|
52
|
+
</CardLayout>
|
|
53
|
+
</CenteredPageLayout>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<CenteredPageLayout title={ROUTES.RESET_PASSWORD.TITLE}>
|
|
59
|
+
<form.AppForm>
|
|
60
|
+
<AuthForm
|
|
61
|
+
title="Reset Password"
|
|
62
|
+
description="Enter your new password below"
|
|
63
|
+
error={submitError}
|
|
64
|
+
success={
|
|
65
|
+
success && (
|
|
66
|
+
<>
|
|
67
|
+
Password reset successfully!{" "}
|
|
68
|
+
<Link to={ROUTES.LOGIN.PATH} className="underline">
|
|
69
|
+
Sign in
|
|
70
|
+
</Link>
|
|
71
|
+
</>
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
submit={{ text: "Reset Password", loadingText: "Resetting…" }}
|
|
75
|
+
footer={{ text: "Remember your password?", link: ROUTES.LOGIN.PATH, linkText: "Sign in" }}
|
|
76
|
+
>
|
|
77
|
+
<form.AppField name="newPassword">
|
|
78
|
+
{(field) => (
|
|
79
|
+
<field.PasswordField
|
|
80
|
+
label="New Password"
|
|
81
|
+
placeholder={AUTH_PLACEHOLDERS.PASSWORD_NEW}
|
|
82
|
+
autoComplete="new-password"
|
|
83
|
+
disabled={success}
|
|
84
|
+
/>
|
|
85
|
+
)}
|
|
86
|
+
</form.AppField>
|
|
87
|
+
<form.AppField name="confirmPassword">
|
|
88
|
+
{(field) => (
|
|
89
|
+
<field.PasswordField
|
|
90
|
+
label="Confirm Password"
|
|
91
|
+
placeholder={AUTH_PLACEHOLDERS.PASSWORD_NEW_CONFIRM}
|
|
92
|
+
autoComplete="new-password"
|
|
93
|
+
disabled={success}
|
|
94
|
+
/>
|
|
95
|
+
)}
|
|
96
|
+
</form.AppField>
|
|
97
|
+
</AuthForm>
|
|
98
|
+
</form.AppForm>
|
|
99
|
+
</CenteredPageLayout>
|
|
100
|
+
);
|
|
101
|
+
}
|