@salesforce/webapp-template-app-react-template-b2e-experimental 1.36.3
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/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 +212 -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 +408 -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/skills/install-feature/SKILL.md +67 -0
- package/dist/.a4drules/skills/install-feature/scripts/copy-feature-assets.sh +36 -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 +533 -0
- package/dist/README.md +18 -0
- package/dist/config/project-scratch-def.json +13 -0
- package/dist/force-app/main/default/classes/WebAppAuthUtils.cls +68 -0
- package/dist/force-app/main/default/classes/WebAppAuthUtils.cls-meta.xml +5 -0
- package/dist/force-app/main/default/classes/WebAppChangePassword.cls +77 -0
- package/dist/force-app/main/default/classes/WebAppChangePassword.cls-meta.xml +5 -0
- package/dist/force-app/main/default/classes/WebAppForgotPassword.cls +71 -0
- package/dist/force-app/main/default/classes/WebAppForgotPassword.cls-meta.xml +5 -0
- package/dist/force-app/main/default/classes/WebAppLogin.cls +97 -0
- package/dist/force-app/main/default/classes/WebAppLogin.cls-meta.xml +5 -0
- package/dist/force-app/main/default/classes/WebAppRegistration.cls +162 -0
- package/dist/force-app/main/default/classes/WebAppRegistration.cls-meta.xml +5 -0
- package/dist/force-app/main/default/digitalExperienceConfigs/appreacttemplateb2e1.digitalExperienceConfig +8 -0
- package/dist/force-app/main/default/digitalExperiences/site/appreacttemplateb2e1/appreacttemplateb2e1.digitalExperience-meta.xml +11 -0
- package/dist/force-app/main/default/digitalExperiences/site/appreacttemplateb2e1/sfdc_cms__site/appreacttemplateb2e1/_meta.json +5 -0
- package/dist/force-app/main/default/digitalExperiences/site/appreacttemplateb2e1/sfdc_cms__site/appreacttemplateb2e1/content.json +10 -0
- package/dist/force-app/main/default/networks/appreacttemplateb2e.network +60 -0
- package/dist/force-app/main/default/package.xml +20 -0
- package/dist/force-app/main/default/sites/appreacttemplateb2e.site +31 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/.graphqlrc.yml +2 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/.prettierignore +9 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/.prettierrc +11 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/appreacttemplateb2e.webapplication-meta.xml +7 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/build/vite.config.d.ts +2 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/build/vite.config.js +94 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/codegen.yml +12 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/e2e/app.spec.ts +24 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/eslint.config.js +141 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/index.html +13 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/package-lock.json +13980 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/package.json +66 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/playwright.config.ts +24 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/scripts/get-graphql-schema.mjs +68 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/scripts/rewrite-e2e-assets.mjs +23 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/api/graphql-operations-types.ts +129 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/api/utils/accounts.ts +33 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/api/utils/query/highRevenueAccountsQuery.graphql +29 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/app.tsx +16 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/appLayout.tsx +11 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/assets/icons/book.svg +3 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/assets/icons/copy.svg +4 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/assets/icons/rocket.svg +3 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/assets/icons/star.svg +3 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/assets/images/codey-1.png +0 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/assets/images/codey-2.png +0 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/assets/images/codey-3.png +0 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/assets/images/vibe-codey.svg +194 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/alerts/status-alert.tsx +45 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/auth/authentication-route.tsx +21 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/auth/private-route.tsx +36 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/footers/footer-link.tsx +36 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/forms/auth-form.tsx +81 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/forms/submit-button.tsx +49 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/layout/card-layout.tsx +23 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/layout/centered-page-layout.tsx +73 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/layout/loading-page.tsx +46 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/alert.tsx +65 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/button.tsx +54 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/card.tsx +77 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/field.tsx +111 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/index.ts +71 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/input.tsx +19 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/label.tsx +19 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/pagination.tsx +99 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/select.tsx +151 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/skeleton.tsx +7 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/spinner.tsx +26 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/table.tsx +114 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/tabs.tsx +115 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/context/AuthContext.tsx +83 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/hooks/form.tsx +116 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/lib/utils.ts +6 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/navigationMenu.tsx +81 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/About.tsx +12 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/ChangePassword.tsx +98 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/ForgotPassword.tsx +67 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/Home.tsx +12 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/Login.tsx +89 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/NotFound.tsx +18 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/Profile.tsx +146 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/Register.tsx +130 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/ResetPassword.tsx +101 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/new.tsx +10 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/router-utils.tsx +34 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/routes.tsx +88 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/styles/global.css +94 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/utils/authenticationConfig.ts +52 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/utils/helpers.ts +187 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/tsconfig.json +36 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/tsconfig.node.json +13 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/vite-env.d.ts +1 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/vite.config.ts +102 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/vitest-env.d.ts +2 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/vitest.config.ts +11 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/vitest.setup.ts +1 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/webapplication.json +7 -0
- package/dist/jest.config.js +6 -0
- package/dist/package.json +38 -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 +37 -0
package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/navigationMenu.tsx
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Link, useLocation } from "react-router";
|
|
2
|
+
import { getAllRoutes } from "./router-utils";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
|
|
5
|
+
export default function NavigationMenu() {
|
|
6
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
7
|
+
const location = useLocation();
|
|
8
|
+
|
|
9
|
+
const isActive = (path: string) => location.pathname === path;
|
|
10
|
+
|
|
11
|
+
const toggleMenu = () => setIsOpen(!isOpen);
|
|
12
|
+
|
|
13
|
+
// Get all route configs and filter by showInNavigation
|
|
14
|
+
const navigationRoutes: { path: string; label: string }[] = getAllRoutes()
|
|
15
|
+
.filter(
|
|
16
|
+
(route) =>
|
|
17
|
+
route.handle?.showInNavigation === true &&
|
|
18
|
+
route.fullPath !== undefined &&
|
|
19
|
+
route.handle?.label !== undefined,
|
|
20
|
+
)
|
|
21
|
+
.map(
|
|
22
|
+
(route) =>
|
|
23
|
+
({
|
|
24
|
+
path: route.fullPath,
|
|
25
|
+
label: route.handle?.label,
|
|
26
|
+
}) as { path: string; label: string },
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<nav className="bg-white border-b border-gray-200">
|
|
31
|
+
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
|
32
|
+
<div className="flex justify-between items-center h-16">
|
|
33
|
+
<Link to="/" className="text-xl font-semibold text-gray-900">
|
|
34
|
+
React App
|
|
35
|
+
</Link>
|
|
36
|
+
<button
|
|
37
|
+
onClick={toggleMenu}
|
|
38
|
+
className="p-2 rounded-md text-gray-700 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
39
|
+
aria-label="Toggle menu"
|
|
40
|
+
>
|
|
41
|
+
<div className="w-6 h-6 flex flex-col justify-center space-y-1.5">
|
|
42
|
+
<span
|
|
43
|
+
className={`block h-0.5 w-6 bg-current transition-all ${
|
|
44
|
+
isOpen ? "rotate-45 translate-y-2" : ""
|
|
45
|
+
}`}
|
|
46
|
+
/>
|
|
47
|
+
<span
|
|
48
|
+
className={`block h-0.5 w-6 bg-current transition-all ${isOpen ? "opacity-0" : ""}`}
|
|
49
|
+
/>
|
|
50
|
+
<span
|
|
51
|
+
className={`block h-0.5 w-6 bg-current transition-all ${
|
|
52
|
+
isOpen ? "-rotate-45 -translate-y-2" : ""
|
|
53
|
+
}`}
|
|
54
|
+
/>
|
|
55
|
+
</div>
|
|
56
|
+
</button>
|
|
57
|
+
</div>
|
|
58
|
+
{isOpen && (
|
|
59
|
+
<div className="pb-4">
|
|
60
|
+
<div className="flex flex-col space-y-2">
|
|
61
|
+
{navigationRoutes.map((item) => (
|
|
62
|
+
<Link
|
|
63
|
+
key={item.path}
|
|
64
|
+
to={item.path}
|
|
65
|
+
onClick={() => setIsOpen(false)}
|
|
66
|
+
className={`px-3 py-2 rounded-md text-sm font-medium transition-colors ${
|
|
67
|
+
isActive(item.path)
|
|
68
|
+
? "bg-blue-100 text-blue-700"
|
|
69
|
+
: "text-gray-700 hover:bg-gray-100"
|
|
70
|
+
}`}
|
|
71
|
+
>
|
|
72
|
+
{item.label}
|
|
73
|
+
</Link>
|
|
74
|
+
))}
|
|
75
|
+
</div>
|
|
76
|
+
</div>
|
|
77
|
+
)}
|
|
78
|
+
</div>
|
|
79
|
+
</nav>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
function About() {
|
|
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">About</h1>
|
|
6
|
+
<p className="text-lg text-gray-600">This is the about page.</p>
|
|
7
|
+
</div>
|
|
8
|
+
</div>
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default About;
|
package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/ChangePassword.tsx
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
|
|
11
|
+
const changePasswordSchema = z
|
|
12
|
+
.object({
|
|
13
|
+
currentPassword: z.string().min(1, "Current password is required"),
|
|
14
|
+
})
|
|
15
|
+
.and(newPasswordSchema);
|
|
16
|
+
|
|
17
|
+
export default function ChangePassword() {
|
|
18
|
+
const [success, setSuccess] = useState(false);
|
|
19
|
+
const [submitError, setSubmitError] = useState<string | null>(null);
|
|
20
|
+
|
|
21
|
+
const form = useAppForm({
|
|
22
|
+
defaultValues: { currentPassword: "", newPassword: "", confirmPassword: "" },
|
|
23
|
+
validators: { onChange: changePasswordSchema, onSubmit: changePasswordSchema },
|
|
24
|
+
onSubmit: async ({ value: formFieldValues }) => {
|
|
25
|
+
setSubmitError(null);
|
|
26
|
+
setSuccess(false);
|
|
27
|
+
try {
|
|
28
|
+
// [Dev Note] Custom Apex Endpoint: /auth/change-password
|
|
29
|
+
// You must ensure this Apex class exists in your org
|
|
30
|
+
const response = await baseClient.post("/sfdcapi/services/apexrest/auth/change-password", {
|
|
31
|
+
currentPassword: formFieldValues.currentPassword,
|
|
32
|
+
newPassword: formFieldValues.newPassword,
|
|
33
|
+
});
|
|
34
|
+
await handleApiResponse(response, "Password change failed");
|
|
35
|
+
setSuccess(true);
|
|
36
|
+
form.reset();
|
|
37
|
+
} catch (err) {
|
|
38
|
+
setSubmitError(getErrorMessage(err, "Password change failed"));
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
onSubmitInvalid: () => {},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<CenteredPageLayout title={ROUTES.CHANGE_PASSWORD.TITLE}>
|
|
46
|
+
<form.AppForm>
|
|
47
|
+
<AuthForm
|
|
48
|
+
title="Change Password"
|
|
49
|
+
description="Enter your current and new password below"
|
|
50
|
+
error={submitError}
|
|
51
|
+
success={
|
|
52
|
+
success && (
|
|
53
|
+
<>
|
|
54
|
+
Password changed successfully!{" "}
|
|
55
|
+
<Link to={ROUTES.PROFILE.PATH} className="underline">
|
|
56
|
+
Back to Profile
|
|
57
|
+
</Link>
|
|
58
|
+
</>
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
submit={{ text: "Change Password", loadingText: "Changing…", disabled: success }}
|
|
62
|
+
footer={{ link: ROUTES.PROFILE.PATH, linkText: "Back to Profile" }}
|
|
63
|
+
>
|
|
64
|
+
<form.AppField name="currentPassword">
|
|
65
|
+
{(field) => (
|
|
66
|
+
<field.PasswordField
|
|
67
|
+
label="Current Password"
|
|
68
|
+
placeholder={AUTH_PLACEHOLDERS.PASSWORD}
|
|
69
|
+
autoComplete="current-password"
|
|
70
|
+
disabled={success}
|
|
71
|
+
/>
|
|
72
|
+
)}
|
|
73
|
+
</form.AppField>
|
|
74
|
+
<form.AppField name="newPassword">
|
|
75
|
+
{(field) => (
|
|
76
|
+
<field.PasswordField
|
|
77
|
+
label="New Password"
|
|
78
|
+
placeholder={AUTH_PLACEHOLDERS.PASSWORD_NEW}
|
|
79
|
+
autoComplete="new-password"
|
|
80
|
+
disabled={success}
|
|
81
|
+
/>
|
|
82
|
+
)}
|
|
83
|
+
</form.AppField>
|
|
84
|
+
<form.AppField name="confirmPassword">
|
|
85
|
+
{(field) => (
|
|
86
|
+
<field.PasswordField
|
|
87
|
+
label="Confirm Password"
|
|
88
|
+
placeholder={AUTH_PLACEHOLDERS.PASSWORD_NEW_CONFIRM}
|
|
89
|
+
autoComplete="new-password"
|
|
90
|
+
disabled={success}
|
|
91
|
+
/>
|
|
92
|
+
)}
|
|
93
|
+
</form.AppField>
|
|
94
|
+
</AuthForm>
|
|
95
|
+
</form.AppForm>
|
|
96
|
+
</CenteredPageLayout>
|
|
97
|
+
);
|
|
98
|
+
}
|
package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/ForgotPassword.tsx
ADDED
|
@@ -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("/sfdcapi/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…", disabled: success }}
|
|
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
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
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
|
+
import type { AuthResponse } from "../utils/helpers";
|
|
11
|
+
|
|
12
|
+
const loginSchema = z.object({
|
|
13
|
+
email: emailSchema,
|
|
14
|
+
password: z.string().min(1, "Password is required"),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export default function Login() {
|
|
18
|
+
const navigate = useNavigate();
|
|
19
|
+
const [searchParams] = useSearchParams();
|
|
20
|
+
const [submitError, setSubmitError] = useState<string | null>(null);
|
|
21
|
+
|
|
22
|
+
const form = useAppForm({
|
|
23
|
+
defaultValues: { email: "", password: "" },
|
|
24
|
+
validators: { onChange: loginSchema, onSubmit: loginSchema },
|
|
25
|
+
onSubmit: async ({ value }) => {
|
|
26
|
+
setSubmitError(null);
|
|
27
|
+
try {
|
|
28
|
+
// [Dev Note] Salesforce Integration:
|
|
29
|
+
// We use 'baseClient.post' to make an authenticated (or guest) call to Salesforce.
|
|
30
|
+
// "/sfciapi/services/apexrest/auth/login" refers to a custom Apex Class exposed as a REST resource.
|
|
31
|
+
// You must ensure this Apex class exists in your org and handles the login logic
|
|
32
|
+
// (e.g., creating a session or returning a token).
|
|
33
|
+
const response = await baseClient.post("/sfdcapi/services/apexrest/auth/login", {
|
|
34
|
+
email: value.email.trim().toLowerCase(),
|
|
35
|
+
password: value.password,
|
|
36
|
+
startUrl: getStartUrl(searchParams),
|
|
37
|
+
});
|
|
38
|
+
const result = await handleApiResponse<AuthResponse>(response, "Login failed");
|
|
39
|
+
if (result?.redirectUrl) {
|
|
40
|
+
// Hard navigate to the URL which establishes the server session cookie
|
|
41
|
+
window.location.replace(result.redirectUrl);
|
|
42
|
+
} else {
|
|
43
|
+
// In case redirectUrl is null, navigate to home
|
|
44
|
+
navigate("/", { replace: true });
|
|
45
|
+
}
|
|
46
|
+
} catch (err) {
|
|
47
|
+
setSubmitError(getErrorMessage(err, "Login failed"));
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
onSubmitInvalid: () => {},
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<CenteredPageLayout title={ROUTES.LOGIN.TITLE}>
|
|
55
|
+
<form.AppForm>
|
|
56
|
+
<AuthForm
|
|
57
|
+
title="Login"
|
|
58
|
+
description="Enter your email below to login to your account"
|
|
59
|
+
error={submitError}
|
|
60
|
+
submit={{ text: "Login", loadingText: "Logging in…" }}
|
|
61
|
+
footer={{
|
|
62
|
+
text: "Don't have an account?",
|
|
63
|
+
link: ROUTES.REGISTER.PATH,
|
|
64
|
+
linkText: "Sign up",
|
|
65
|
+
}}
|
|
66
|
+
>
|
|
67
|
+
<form.AppField name="email">
|
|
68
|
+
{(field) => <field.EmailField label="Email" />}
|
|
69
|
+
</form.AppField>
|
|
70
|
+
<form.AppField name="password">
|
|
71
|
+
{(field) => (
|
|
72
|
+
<field.PasswordField
|
|
73
|
+
label="Password"
|
|
74
|
+
labelAction={
|
|
75
|
+
<Link
|
|
76
|
+
to={ROUTES.FORGOT_PASSWORD.PATH}
|
|
77
|
+
className="text-sm underline-offset-4 hover:underline"
|
|
78
|
+
>
|
|
79
|
+
Forgot your password?
|
|
80
|
+
</Link>
|
|
81
|
+
}
|
|
82
|
+
/>
|
|
83
|
+
)}
|
|
84
|
+
</form.AppField>
|
|
85
|
+
</AuthForm>
|
|
86
|
+
</form.AppForm>
|
|
87
|
+
</CenteredPageLayout>
|
|
88
|
+
);
|
|
89
|
+
}
|
package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/NotFound.tsx
ADDED
|
@@ -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
|
+
}
|
package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/Register.tsx
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
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
|
+
import type { AuthResponse } from "../utils/helpers";
|
|
17
|
+
|
|
18
|
+
const registerSchema = z
|
|
19
|
+
.object({
|
|
20
|
+
firstName: z.string().trim().min(1, "First name is required"),
|
|
21
|
+
lastName: z.string().trim().min(1, "Last name is required"),
|
|
22
|
+
email: emailSchema,
|
|
23
|
+
password: passwordSchema,
|
|
24
|
+
confirmPassword: z.string().min(1, "Please confirm your password"),
|
|
25
|
+
startUrl: z.string(),
|
|
26
|
+
})
|
|
27
|
+
.refine((data) => data.password === data.confirmPassword, {
|
|
28
|
+
message: "Passwords do not match",
|
|
29
|
+
path: ["confirmPassword"],
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export default function Register() {
|
|
33
|
+
const navigate = useNavigate();
|
|
34
|
+
const [searchParams] = useSearchParams();
|
|
35
|
+
const [submitError, setSubmitError] = useState<string | null>(null);
|
|
36
|
+
|
|
37
|
+
const form = useAppForm({
|
|
38
|
+
defaultValues: {
|
|
39
|
+
firstName: "",
|
|
40
|
+
lastName: "",
|
|
41
|
+
email: "",
|
|
42
|
+
password: "",
|
|
43
|
+
confirmPassword: "",
|
|
44
|
+
startUrl: getStartUrl(searchParams) || "",
|
|
45
|
+
},
|
|
46
|
+
validators: { onChange: registerSchema, onSubmit: registerSchema },
|
|
47
|
+
onSubmit: async ({ value: formFieldValues }) => {
|
|
48
|
+
setSubmitError(null);
|
|
49
|
+
try {
|
|
50
|
+
// [Dev Note] Calls the custom Apex REST endpoint for user registration.
|
|
51
|
+
// Ensure your Apex logic handles duplicate checks and user creation (e.g., Site.createExternalUser).
|
|
52
|
+
const { confirmPassword, ...request } = formFieldValues;
|
|
53
|
+
const response = await baseClient.post("/sfdcapi/services/apexrest/auth/register", {
|
|
54
|
+
request,
|
|
55
|
+
});
|
|
56
|
+
const result = await handleApiResponse<AuthResponse>(response, "Registration failed");
|
|
57
|
+
if (result?.redirectUrl) {
|
|
58
|
+
// Hard navigate to the URL which logs the new user in
|
|
59
|
+
window.location.replace(result.redirectUrl);
|
|
60
|
+
} else {
|
|
61
|
+
// In case redirectUrl is null, redirect to the login page
|
|
62
|
+
navigate(ROUTES.LOGIN.PATH, { replace: true });
|
|
63
|
+
}
|
|
64
|
+
} catch (err) {
|
|
65
|
+
setSubmitError(getErrorMessage(err, "Registration failed"));
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
onSubmitInvalid: () => {},
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<CenteredPageLayout title={ROUTES.REGISTER.TITLE}>
|
|
73
|
+
<form.AppForm>
|
|
74
|
+
<AuthForm
|
|
75
|
+
title="Sign Up"
|
|
76
|
+
description="Enter your information to create an account"
|
|
77
|
+
error={submitError}
|
|
78
|
+
submit={{ text: "Create an account", loadingText: "Creating account…" }}
|
|
79
|
+
footer={{
|
|
80
|
+
text: "Already have an account?",
|
|
81
|
+
link: ROUTES.LOGIN.PATH,
|
|
82
|
+
linkText: "Sign in",
|
|
83
|
+
}}
|
|
84
|
+
>
|
|
85
|
+
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 items-start">
|
|
86
|
+
<form.AppField name="firstName">
|
|
87
|
+
{(field) => (
|
|
88
|
+
<field.TextField
|
|
89
|
+
label="First name"
|
|
90
|
+
placeholder={AUTH_PLACEHOLDERS.FIRST_NAME}
|
|
91
|
+
autoComplete="given-name"
|
|
92
|
+
/>
|
|
93
|
+
)}
|
|
94
|
+
</form.AppField>
|
|
95
|
+
<form.AppField name="lastName">
|
|
96
|
+
{(field) => (
|
|
97
|
+
<field.TextField
|
|
98
|
+
label="Last name"
|
|
99
|
+
placeholder={AUTH_PLACEHOLDERS.LAST_NAME}
|
|
100
|
+
autoComplete="family-name"
|
|
101
|
+
/>
|
|
102
|
+
)}
|
|
103
|
+
</form.AppField>
|
|
104
|
+
</div>
|
|
105
|
+
<form.AppField name="email">
|
|
106
|
+
{(field) => <field.EmailField label="Email" />}
|
|
107
|
+
</form.AppField>
|
|
108
|
+
<form.AppField name="password">
|
|
109
|
+
{(field) => (
|
|
110
|
+
<field.PasswordField
|
|
111
|
+
label="Password"
|
|
112
|
+
placeholder={AUTH_PLACEHOLDERS.PASSWORD_CREATE}
|
|
113
|
+
autoComplete="new-password"
|
|
114
|
+
/>
|
|
115
|
+
)}
|
|
116
|
+
</form.AppField>
|
|
117
|
+
<form.AppField name="confirmPassword">
|
|
118
|
+
{(field) => (
|
|
119
|
+
<field.PasswordField
|
|
120
|
+
label="Confirm Password"
|
|
121
|
+
placeholder={AUTH_PLACEHOLDERS.PASSWORD_CONFIRM}
|
|
122
|
+
autoComplete="new-password"
|
|
123
|
+
/>
|
|
124
|
+
)}
|
|
125
|
+
</form.AppField>
|
|
126
|
+
</AuthForm>
|
|
127
|
+
</form.AppForm>
|
|
128
|
+
</CenteredPageLayout>
|
|
129
|
+
);
|
|
130
|
+
}
|