@salesforce/webapp-template-app-react-byo-experimental 1.3.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.
Files changed (101) hide show
  1. package/LICENSE.txt +82 -0
  2. package/dist/.a4drules/build-validation.md +81 -0
  3. package/dist/.a4drules/code-quality.md +150 -0
  4. package/dist/.a4drules/graphql/tools/knowledge/lds-explore-graphql-schema.md +227 -0
  5. package/dist/.a4drules/graphql/tools/knowledge/lds-generate-graphql-mutationquery.md +211 -0
  6. package/dist/.a4drules/graphql/tools/knowledge/lds-generate-graphql-readquery.md +185 -0
  7. package/dist/.a4drules/graphql/tools/knowledge/lds-guide-graphql.md +205 -0
  8. package/dist/.a4drules/graphql/tools/schemas/shared.graphqls +1150 -0
  9. package/dist/.a4drules/graphql.md +98 -0
  10. package/dist/.a4drules/images.md +13 -0
  11. package/dist/.a4drules/react.md +361 -0
  12. package/dist/.a4drules/react_image_processing.md +45 -0
  13. package/dist/.a4drules/typescript.md +224 -0
  14. package/dist/.forceignore +15 -0
  15. package/dist/.husky/pre-commit +4 -0
  16. package/dist/.prettierignore +11 -0
  17. package/dist/.prettierrc +17 -0
  18. package/dist/CHANGELOG.md +11 -0
  19. package/dist/README.md +18 -0
  20. package/dist/config/project-scratch-def.json +13 -0
  21. package/dist/force-app/main/default/digitalExperienceConfigs/appreactbyo1.digitalExperienceConfig +8 -0
  22. package/dist/force-app/main/default/digitalExperiences/site/appreactbyo1/appreactbyo1.digitalExperience-meta.xml +11 -0
  23. package/dist/force-app/main/default/digitalExperiences/site/appreactbyo1/sfdc_cms__site/appreactbyo1/_meta.json +5 -0
  24. package/dist/force-app/main/default/digitalExperiences/site/appreactbyo1/sfdc_cms__site/appreactbyo1/content.json +10 -0
  25. package/dist/force-app/main/default/networks/appreactbyo.network +60 -0
  26. package/dist/force-app/main/default/package.xml +20 -0
  27. package/dist/force-app/main/default/sites/appreactbyo.site +31 -0
  28. package/dist/force-app/main/default/webapplications/appreactbyo/.prettierignore +9 -0
  29. package/dist/force-app/main/default/webapplications/appreactbyo/.prettierrc +11 -0
  30. package/dist/force-app/main/default/webapplications/appreactbyo/appreactbyo.webapplication-meta.xml +7 -0
  31. package/dist/force-app/main/default/webapplications/appreactbyo/eslint.config.js +113 -0
  32. package/dist/force-app/main/default/webapplications/appreactbyo/index.html +13 -0
  33. package/dist/force-app/main/default/webapplications/appreactbyo/package.json +42 -0
  34. package/dist/force-app/main/default/webapplications/appreactbyo/src/api/graphql-operations-types.ts +127 -0
  35. package/dist/force-app/main/default/webapplications/appreactbyo/src/api/utils/query/highRevenueAccountsQuery.graphql +29 -0
  36. package/dist/force-app/main/default/webapplications/appreactbyo/src/app.tsx +16 -0
  37. package/dist/force-app/main/default/webapplications/appreactbyo/src/appLayout.tsx +11 -0
  38. package/dist/force-app/main/default/webapplications/appreactbyo/src/assets/icons/book.svg +3 -0
  39. package/dist/force-app/main/default/webapplications/appreactbyo/src/assets/icons/copy.svg +4 -0
  40. package/dist/force-app/main/default/webapplications/appreactbyo/src/assets/icons/rocket.svg +3 -0
  41. package/dist/force-app/main/default/webapplications/appreactbyo/src/assets/icons/star.svg +3 -0
  42. package/dist/force-app/main/default/webapplications/appreactbyo/src/assets/images/codey-1.png +0 -0
  43. package/dist/force-app/main/default/webapplications/appreactbyo/src/assets/images/codey-2.png +0 -0
  44. package/dist/force-app/main/default/webapplications/appreactbyo/src/assets/images/codey-3.png +0 -0
  45. package/dist/force-app/main/default/webapplications/appreactbyo/src/assets/images/vibe-codey.svg +194 -0
  46. package/dist/force-app/main/default/webapplications/appreactbyo/src/components/alerts/status-alert.tsx +45 -0
  47. package/dist/force-app/main/default/webapplications/appreactbyo/src/components/auth/authentication-route.tsx +21 -0
  48. package/dist/force-app/main/default/webapplications/appreactbyo/src/components/auth/private-route.tsx +36 -0
  49. package/dist/force-app/main/default/webapplications/appreactbyo/src/components/footers/footer-link.tsx +36 -0
  50. package/dist/force-app/main/default/webapplications/appreactbyo/src/components/forms/auth-form.tsx +79 -0
  51. package/dist/force-app/main/default/webapplications/appreactbyo/src/components/forms/submit-button.tsx +49 -0
  52. package/dist/force-app/main/default/webapplications/appreactbyo/src/components/layout/card-layout.tsx +23 -0
  53. package/dist/force-app/main/default/webapplications/appreactbyo/src/components/layout/centered-page-layout.tsx +73 -0
  54. package/dist/force-app/main/default/webapplications/appreactbyo/src/components/layout/loading-page.tsx +46 -0
  55. package/dist/force-app/main/default/webapplications/appreactbyo/src/components/ui/alert.tsx +65 -0
  56. package/dist/force-app/main/default/webapplications/appreactbyo/src/components/ui/button.tsx +56 -0
  57. package/dist/force-app/main/default/webapplications/appreactbyo/src/components/ui/card.tsx +77 -0
  58. package/dist/force-app/main/default/webapplications/appreactbyo/src/components/ui/field.tsx +111 -0
  59. package/dist/force-app/main/default/webapplications/appreactbyo/src/components/ui/index.ts +71 -0
  60. package/dist/force-app/main/default/webapplications/appreactbyo/src/components/ui/input.tsx +19 -0
  61. package/dist/force-app/main/default/webapplications/appreactbyo/src/components/ui/label.tsx +19 -0
  62. package/dist/force-app/main/default/webapplications/appreactbyo/src/components/ui/pagination.tsx +99 -0
  63. package/dist/force-app/main/default/webapplications/appreactbyo/src/components/ui/select.tsx +151 -0
  64. package/dist/force-app/main/default/webapplications/appreactbyo/src/components/ui/skeleton.tsx +7 -0
  65. package/dist/force-app/main/default/webapplications/appreactbyo/src/components/ui/spinner.tsx +21 -0
  66. package/dist/force-app/main/default/webapplications/appreactbyo/src/components/ui/table.tsx +114 -0
  67. package/dist/force-app/main/default/webapplications/appreactbyo/src/components/ui/tabs.tsx +115 -0
  68. package/dist/force-app/main/default/webapplications/appreactbyo/src/context/AuthContext.tsx +83 -0
  69. package/dist/force-app/main/default/webapplications/appreactbyo/src/hooks/form.tsx +116 -0
  70. package/dist/force-app/main/default/webapplications/appreactbyo/src/lib/utils.ts +6 -0
  71. package/dist/force-app/main/default/webapplications/appreactbyo/src/navigationMenu.tsx +81 -0
  72. package/dist/force-app/main/default/webapplications/appreactbyo/src/pages/About.tsx +12 -0
  73. package/dist/force-app/main/default/webapplications/appreactbyo/src/pages/ChangePassword.tsx +105 -0
  74. package/dist/force-app/main/default/webapplications/appreactbyo/src/pages/ForgotPassword.tsx +67 -0
  75. package/dist/force-app/main/default/webapplications/appreactbyo/src/pages/Home.tsx +12 -0
  76. package/dist/force-app/main/default/webapplications/appreactbyo/src/pages/Login.tsx +84 -0
  77. package/dist/force-app/main/default/webapplications/appreactbyo/src/pages/NotFound.tsx +18 -0
  78. package/dist/force-app/main/default/webapplications/appreactbyo/src/pages/Profile.tsx +146 -0
  79. package/dist/force-app/main/default/webapplications/appreactbyo/src/pages/Register.tsx +117 -0
  80. package/dist/force-app/main/default/webapplications/appreactbyo/src/pages/ResetPassword.tsx +101 -0
  81. package/dist/force-app/main/default/webapplications/appreactbyo/src/pages/about.tsx +10 -0
  82. package/dist/force-app/main/default/webapplications/appreactbyo/src/pages/new.tsx +10 -0
  83. package/dist/force-app/main/default/webapplications/appreactbyo/src/router-utils.tsx +34 -0
  84. package/dist/force-app/main/default/webapplications/appreactbyo/src/routes.tsx +88 -0
  85. package/dist/force-app/main/default/webapplications/appreactbyo/src/styles/global.css +94 -0
  86. package/dist/force-app/main/default/webapplications/appreactbyo/src/utils/authenticationConfig.ts +52 -0
  87. package/dist/force-app/main/default/webapplications/appreactbyo/src/utils/helpers.ts +161 -0
  88. package/dist/force-app/main/default/webapplications/appreactbyo/tsconfig.json +36 -0
  89. package/dist/force-app/main/default/webapplications/appreactbyo/tsconfig.node.json +13 -0
  90. package/dist/force-app/main/default/webapplications/appreactbyo/vite-env.d.ts +1 -0
  91. package/dist/force-app/main/default/webapplications/appreactbyo/vite.config.ts +82 -0
  92. package/dist/force-app/main/default/webapplications/appreactbyo/vitest-env.d.ts +2 -0
  93. package/dist/force-app/main/default/webapplications/appreactbyo/vitest.config.ts +11 -0
  94. package/dist/force-app/main/default/webapplications/appreactbyo/vitest.setup.ts +1 -0
  95. package/dist/force-app/main/default/webapplications/appreactbyo/webapplication.json +7 -0
  96. package/dist/jest.config.js +6 -0
  97. package/dist/package.json +37 -0
  98. package/dist/scripts/apex/hello.apex +10 -0
  99. package/dist/scripts/soql/account.soql +6 -0
  100. package/dist/sfdx-project.json +12 -0
  101. package/package.json +28 -0
@@ -0,0 +1,83 @@
1
+ import { createContext, useContext, useState, useEffect, useCallback, type ReactNode } from "react";
2
+ import { getCurrentUser } from "@salesforce/webapp-experimental/api";
3
+
4
+ interface User {
5
+ readonly id: string;
6
+ readonly name: string;
7
+ }
8
+
9
+ interface AuthContextType {
10
+ user: User | null;
11
+ isAuthenticated: boolean;
12
+ loading: boolean;
13
+ error: string | null;
14
+ checkAuth: () => Promise<void>;
15
+ }
16
+
17
+ const AuthContext = createContext<AuthContextType | undefined>(undefined);
18
+
19
+ interface AuthProviderProps {
20
+ children: ReactNode;
21
+ }
22
+
23
+ export function AuthProvider({ children }: AuthProviderProps) {
24
+ const [user, setUser] = useState<User | null>(null);
25
+ const [loading, setLoading] = useState(true);
26
+ const [error, setError] = useState<string | null>(null);
27
+
28
+ const checkAuth = useCallback(async () => {
29
+ setLoading(true);
30
+ setError(null);
31
+
32
+ try {
33
+ const userData = await getCurrentUser();
34
+ setUser(userData);
35
+ } catch (err) {
36
+ const errorMessage = err instanceof Error ? err.message : "Authentication failed";
37
+ setError(errorMessage);
38
+ setUser(null);
39
+ } finally {
40
+ setLoading(false);
41
+ }
42
+ }, []);
43
+
44
+ useEffect(() => {
45
+ checkAuth();
46
+ }, [checkAuth]);
47
+
48
+ const value: AuthContextType = {
49
+ user,
50
+ isAuthenticated: user !== null,
51
+ loading,
52
+ error,
53
+ checkAuth,
54
+ };
55
+
56
+ return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
57
+ }
58
+
59
+ /**
60
+ * Hook to access the authentication context.
61
+ * @returns {AuthContextType} Authentication state (user, isAuthenticated, loading, error, checkAuth)
62
+ * @throws {Error} If used outside of an AuthProvider
63
+ */
64
+ export function useAuth(): AuthContextType {
65
+ const context = useContext(AuthContext);
66
+ if (context === undefined) {
67
+ throw new Error("useAuth must be used within an AuthProvider");
68
+ }
69
+ return context;
70
+ }
71
+
72
+ /**
73
+ * Returns the current authenticated user.
74
+ * @returns {User} The authenticated user object
75
+ * @throws {Error} If not used within AuthProvider or user is not authenticated
76
+ */
77
+ export function getUser(): User {
78
+ const context = useAuth();
79
+ if (!context.user) {
80
+ throw new Error("Authenticated context not established");
81
+ }
82
+ return context.user;
83
+ }
@@ -0,0 +1,116 @@
1
+ import { useId } from "react";
2
+ import { createFormHookContexts, createFormHook } from "@tanstack/react-form";
3
+ import { Field, FieldDescription, FieldError, FieldLabel } from "../components/ui/field";
4
+ import { Input } from "../components/ui/input";
5
+ import { cn } from "../lib/utils";
6
+ import { AUTH_PLACEHOLDERS } from "../utils/authenticationConfig";
7
+
8
+ // Create form hook contexts
9
+ export const { fieldContext, formContext, useFieldContext, useFormContext } =
10
+ createFormHookContexts();
11
+
12
+ // ============================================================================
13
+ // Field Components
14
+ // ============================================================================
15
+
16
+ interface TextFieldProps
17
+ extends Omit<
18
+ React.ComponentProps<typeof Input>,
19
+ "name" | "value" | "onBlur" | "onChange" | "aria-invalid"
20
+ > {
21
+ label: string;
22
+ labelAction?: React.ReactNode;
23
+ description?: React.ReactNode;
24
+ }
25
+
26
+ function TextField({
27
+ label,
28
+ id: providedId,
29
+ labelAction,
30
+ description,
31
+ type = "text",
32
+ ...props
33
+ }: TextFieldProps) {
34
+ const field = useFieldContext<string>();
35
+ const generatedId = useId();
36
+ const id = providedId ?? generatedId;
37
+ const descriptionId = `${id}-description`;
38
+ const errorId = `${id}-error`;
39
+ const isInvalid = field.state.meta.isTouched && field.state.meta.errors.length > 0;
40
+
41
+ // Deduplicate errors by message
42
+ const errors = field.state.meta.errors;
43
+ const uniqueErrors = [...new Map(errors.map((item: any) => [item["message"], item])).values()];
44
+
45
+ return (
46
+ <Field data-invalid={isInvalid}>
47
+ <div className="flex items-center">
48
+ <FieldLabel htmlFor={id}>{label}</FieldLabel>
49
+ {labelAction && <div className="ml-auto">{labelAction}</div>}
50
+ </div>
51
+ {description && <FieldDescription id={descriptionId}>{description}</FieldDescription>}
52
+ <Input
53
+ id={id}
54
+ name={field.name as string}
55
+ type={type}
56
+ value={field.state.value ?? ""}
57
+ onBlur={field.handleBlur}
58
+ onChange={(e: React.ChangeEvent<HTMLInputElement>) => field.handleChange(e.target.value)}
59
+ aria-invalid={isInvalid}
60
+ aria-describedby={cn(description && descriptionId, isInvalid && errorId)}
61
+ {...props}
62
+ />
63
+ {isInvalid && uniqueErrors.length > 0 && <FieldError errors={uniqueErrors} />}
64
+ </Field>
65
+ );
66
+ }
67
+
68
+ /** Password field with preset type and autocomplete */
69
+ function PasswordField({
70
+ label,
71
+ autoComplete = "current-password",
72
+ placeholder = AUTH_PLACEHOLDERS.PASSWORD,
73
+ ...props
74
+ }: Omit<TextFieldProps, "type">) {
75
+ return (
76
+ <TextField
77
+ label={label}
78
+ type="password"
79
+ autoComplete={autoComplete}
80
+ placeholder={placeholder}
81
+ {...props}
82
+ />
83
+ );
84
+ }
85
+
86
+ /** Email field with preset type and autocomplete */
87
+ function EmailField({
88
+ label,
89
+ placeholder = AUTH_PLACEHOLDERS.EMAIL,
90
+ ...props
91
+ }: Omit<TextFieldProps, "type">) {
92
+ return (
93
+ <TextField
94
+ label={label}
95
+ type="email"
96
+ autoComplete="username"
97
+ placeholder={placeholder}
98
+ {...props}
99
+ />
100
+ );
101
+ }
102
+
103
+ // ============================================================================
104
+ // Create Form Hook
105
+ // ============================================================================
106
+
107
+ export const { useAppForm } = createFormHook({
108
+ fieldContext,
109
+ formContext,
110
+ fieldComponents: {
111
+ TextField,
112
+ PasswordField,
113
+ EmailField,
114
+ },
115
+ formComponents: {},
116
+ });
@@ -0,0 +1,6 @@
1
+ import { clsx, type ClassValue } from "clsx";
2
+ import { twMerge } from "tailwind-merge";
3
+
4
+ export function cn(...inputs: ClassValue[]) {
5
+ return twMerge(clsx(inputs));
6
+ }
@@ -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;
@@ -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
+ }
@@ -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,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
+ }