@salesforce/webapp-template-app-react-template-vibe-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.
Files changed (132) 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 +212 -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 +408 -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/skills/install-feature/SKILL.md +67 -0
  14. package/dist/.a4drules/skills/install-feature/scripts/copy-feature-assets.sh +36 -0
  15. package/dist/.a4drules/typescript.md +224 -0
  16. package/dist/.forceignore +15 -0
  17. package/dist/.husky/pre-commit +4 -0
  18. package/dist/.prettierignore +11 -0
  19. package/dist/.prettierrc +17 -0
  20. package/dist/CHANGELOG.md +533 -0
  21. package/dist/README.md +18 -0
  22. package/dist/config/project-scratch-def.json +13 -0
  23. package/dist/force-app/main/default/classes/WebAppAuthUtils.cls +68 -0
  24. package/dist/force-app/main/default/classes/WebAppAuthUtils.cls-meta.xml +5 -0
  25. package/dist/force-app/main/default/classes/WebAppChangePassword.cls +77 -0
  26. package/dist/force-app/main/default/classes/WebAppChangePassword.cls-meta.xml +5 -0
  27. package/dist/force-app/main/default/classes/WebAppForgotPassword.cls +71 -0
  28. package/dist/force-app/main/default/classes/WebAppForgotPassword.cls-meta.xml +5 -0
  29. package/dist/force-app/main/default/classes/WebAppLogin.cls +97 -0
  30. package/dist/force-app/main/default/classes/WebAppLogin.cls-meta.xml +5 -0
  31. package/dist/force-app/main/default/classes/WebAppRegistration.cls +162 -0
  32. package/dist/force-app/main/default/classes/WebAppRegistration.cls-meta.xml +5 -0
  33. package/dist/force-app/main/default/digitalExperienceConfigs/appreacttemplatevibe1.digitalExperienceConfig +8 -0
  34. package/dist/force-app/main/default/digitalExperiences/site/appreacttemplatevibe1/appreacttemplatevibe1.digitalExperience-meta.xml +11 -0
  35. package/dist/force-app/main/default/digitalExperiences/site/appreacttemplatevibe1/sfdc_cms__site/appreacttemplatevibe1/_meta.json +5 -0
  36. package/dist/force-app/main/default/digitalExperiences/site/appreacttemplatevibe1/sfdc_cms__site/appreacttemplatevibe1/content.json +10 -0
  37. package/dist/force-app/main/default/networks/appreacttemplatevibe.network +60 -0
  38. package/dist/force-app/main/default/package.xml +20 -0
  39. package/dist/force-app/main/default/sites/appreacttemplatevibe.site +31 -0
  40. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/.graphqlrc.yml +2 -0
  41. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/.prettierignore +9 -0
  42. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/.prettierrc +11 -0
  43. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/appreacttemplatevibe.webapplication-meta.xml +7 -0
  44. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/build/vite.config.d.ts +2 -0
  45. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/build/vite.config.js +94 -0
  46. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/codegen.yml +12 -0
  47. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/e2e/app.spec.ts +24 -0
  48. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/eslint.config.js +141 -0
  49. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/index.html +13 -0
  50. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/package-lock.json +13999 -0
  51. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/package.json +67 -0
  52. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/playwright.config.ts +24 -0
  53. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/scripts/get-graphql-schema.mjs +68 -0
  54. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/scripts/rewrite-e2e-assets.mjs +23 -0
  55. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/HomePage.tsx +231 -0
  56. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/api/graphql-operations-types.ts +129 -0
  57. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/api/utils/accounts.ts +33 -0
  58. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/api/utils/query/highRevenueAccountsQuery.graphql +29 -0
  59. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/app.tsx +16 -0
  60. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/appLayout.tsx +17 -0
  61. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/assets/icons/book.svg +3 -0
  62. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/assets/icons/copy.svg +4 -0
  63. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/assets/icons/rocket.svg +3 -0
  64. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/assets/icons/star.svg +3 -0
  65. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/assets/images/codey-1.png +0 -0
  66. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/assets/images/codey-2.png +0 -0
  67. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/assets/images/codey-3.png +0 -0
  68. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/assets/images/vibe-codey.svg +194 -0
  69. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/components/AccountsTable.tsx +134 -0
  70. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/components/AgentforceConversationClient.tsx +72 -0
  71. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/components/Footer.test.tsx +35 -0
  72. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/components/Footer.tsx +68 -0
  73. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/components/Hero.test.tsx +44 -0
  74. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/components/Hero.tsx +61 -0
  75. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/components/PromptCard.test.tsx +57 -0
  76. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/components/PromptCard.tsx +301 -0
  77. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/components/PromptHighlight.test.tsx +85 -0
  78. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/components/PromptHighlight.tsx +73 -0
  79. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/components/alerts/status-alert.tsx +45 -0
  80. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/components/auth/authentication-route.tsx +21 -0
  81. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/components/auth/private-route.tsx +36 -0
  82. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/components/footers/footer-link.tsx +36 -0
  83. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/components/forms/auth-form.tsx +81 -0
  84. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/components/forms/submit-button.tsx +49 -0
  85. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/components/layout/card-layout.tsx +23 -0
  86. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/components/layout/centered-page-layout.tsx +73 -0
  87. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/components/layout/loading-page.tsx +46 -0
  88. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/components/ui/alert.tsx +65 -0
  89. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/components/ui/button.tsx +54 -0
  90. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/components/ui/card.tsx +77 -0
  91. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/components/ui/field.tsx +111 -0
  92. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/components/ui/index.ts +71 -0
  93. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/components/ui/input.tsx +19 -0
  94. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/components/ui/label.tsx +19 -0
  95. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/components/ui/pagination.tsx +99 -0
  96. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/components/ui/select.tsx +151 -0
  97. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/components/ui/skeleton.tsx +7 -0
  98. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/components/ui/spinner.tsx +26 -0
  99. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/components/ui/table.tsx +114 -0
  100. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/components/ui/tabs.tsx +115 -0
  101. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/context/AuthContext.tsx +83 -0
  102. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/hooks/form.tsx +116 -0
  103. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/index.ts +6 -0
  104. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/lib/utils.ts +6 -0
  105. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/pages/ChangePassword.tsx +98 -0
  106. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/pages/ForgotPassword.tsx +67 -0
  107. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/pages/Home.tsx +12 -0
  108. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/pages/Login.tsx +89 -0
  109. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/pages/NotFound.tsx +18 -0
  110. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/pages/Profile.tsx +146 -0
  111. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/pages/Register.tsx +130 -0
  112. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/pages/ResetPassword.tsx +101 -0
  113. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/routes.tsx +71 -0
  114. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/styles/global.css +270 -0
  115. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/testCmp.tsx +9 -0
  116. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/types/conversation.ts +21 -0
  117. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/utils/authenticationConfig.ts +52 -0
  118. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/src/utils/helpers.ts +187 -0
  119. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/tsconfig.json +36 -0
  120. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/tsconfig.node.json +13 -0
  121. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/vite-env.d.ts +1 -0
  122. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/vite.config.ts +102 -0
  123. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/vitest-env.d.ts +2 -0
  124. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/vitest.config.ts +11 -0
  125. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/vitest.setup.ts +1 -0
  126. package/dist/force-app/main/default/webapplications/appreacttemplatevibe/webapplication.json +7 -0
  127. package/dist/jest.config.js +6 -0
  128. package/dist/package.json +38 -0
  129. package/dist/scripts/apex/hello.apex +10 -0
  130. package/dist/scripts/soql/account.soql +6 -0
  131. package/dist/sfdx-project.json +12 -0
  132. package/package.json +46 -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
+ /**
2
+ * feature-react-agentforce-conversation-client – ACC Conversation Client
3
+ */
4
+
5
+ export { AgentforceConversationClient } from "./components/AgentforceConversationClient";
6
+ export type { AgentforceConversationClientProps, ResolvedEmbedOptions } from "./types/conversation";
@@ -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,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
+ }
@@ -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
+ }
@@ -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
+ }