@salesforce/webapp-template-app-react-template-b2e-experimental 1.43.0 → 1.43.1

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 (68) hide show
  1. package/dist/.a4drules/skills/install-feature/SKILL.md +0 -1
  2. package/dist/CHANGELOG.md +11 -0
  3. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/e2e/app.spec.ts +0 -7
  4. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/package-lock.json +3589 -3223
  5. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/package.json +2 -10
  6. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/app.tsx +19 -13
  7. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/appLayout.tsx +9 -1
  8. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/AgentforceConversationClient.tsx +127 -0
  9. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/index.ts +6 -0
  10. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/navigationMenu.tsx +73 -74
  11. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/router-utils.tsx +24 -23
  12. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/routes.tsx +0 -66
  13. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/styles/global.css +10 -129
  14. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/types/conversation.ts +21 -0
  15. package/dist/package.json +1 -1
  16. package/package.json +2 -2
  17. package/dist/force-app/main/default/classes/WebAppAuthUtils.cls +0 -68
  18. package/dist/force-app/main/default/classes/WebAppAuthUtils.cls-meta.xml +0 -5
  19. package/dist/force-app/main/default/classes/WebAppChangePassword.cls +0 -77
  20. package/dist/force-app/main/default/classes/WebAppChangePassword.cls-meta.xml +0 -5
  21. package/dist/force-app/main/default/classes/WebAppForgotPassword.cls +0 -71
  22. package/dist/force-app/main/default/classes/WebAppForgotPassword.cls-meta.xml +0 -5
  23. package/dist/force-app/main/default/classes/WebAppLogin.cls +0 -97
  24. package/dist/force-app/main/default/classes/WebAppLogin.cls-meta.xml +0 -5
  25. package/dist/force-app/main/default/classes/WebAppRegistration.cls +0 -162
  26. package/dist/force-app/main/default/classes/WebAppRegistration.cls-meta.xml +0 -5
  27. package/dist/force-app/main/default/digitalExperienceConfigs/appreacttemplateb2e1.digitalExperienceConfig +0 -8
  28. package/dist/force-app/main/default/digitalExperiences/site/appreacttemplateb2e1/appreacttemplateb2e1.digitalExperience-meta.xml +0 -11
  29. package/dist/force-app/main/default/digitalExperiences/site/appreacttemplateb2e1/sfdc_cms__site/appreacttemplateb2e1/_meta.json +0 -5
  30. package/dist/force-app/main/default/digitalExperiences/site/appreacttemplateb2e1/sfdc_cms__site/appreacttemplateb2e1/content.json +0 -10
  31. package/dist/force-app/main/default/networks/appreacttemplateb2e.network +0 -60
  32. package/dist/force-app/main/default/package.xml +0 -20
  33. package/dist/force-app/main/default/sites/appreacttemplateb2e.site +0 -31
  34. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/alerts/status-alert.tsx +0 -45
  35. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/auth/authentication-route.tsx +0 -21
  36. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/auth/private-route.tsx +0 -36
  37. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/footers/footer-link.tsx +0 -36
  38. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/forms/auth-form.tsx +0 -81
  39. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/forms/submit-button.tsx +0 -49
  40. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/layout/card-layout.tsx +0 -23
  41. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/layout/card-skeleton.tsx +0 -38
  42. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/layout/centered-page-layout.tsx +0 -73
  43. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/alert.tsx +0 -65
  44. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/button.tsx +0 -54
  45. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/card.tsx +0 -77
  46. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/field.tsx +0 -111
  47. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/index.ts +0 -71
  48. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/input.tsx +0 -19
  49. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/label.tsx +0 -19
  50. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/pagination.tsx +0 -99
  51. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/select.tsx +0 -151
  52. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/skeleton.tsx +0 -13
  53. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/spinner.tsx +0 -26
  54. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/table.tsx +0 -114
  55. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/tabs.tsx +0 -115
  56. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/context/AuthContext.tsx +0 -83
  57. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/hooks/form.tsx +0 -116
  58. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/lib/utils.ts +0 -6
  59. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/About.tsx +0 -12
  60. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/ChangePassword.tsx +0 -98
  61. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/ForgotPassword.tsx +0 -67
  62. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/Login.tsx +0 -89
  63. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/Profile.tsx +0 -177
  64. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/Register.tsx +0 -130
  65. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/ResetPassword.tsx +0 -101
  66. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/new.tsx +0 -10
  67. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/utils/authenticationConfig.ts +0 -52
  68. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/utils/helpers.ts +0 -195
@@ -1,115 +0,0 @@
1
- import * as React from "react";
2
- import { cn } from "../../lib/utils";
3
-
4
- interface TabsContextValue {
5
- value: string;
6
- onValueChange: (value: string) => void;
7
- }
8
-
9
- const TabsContext = React.createContext<TabsContextValue | undefined>(undefined);
10
-
11
- interface TabsProps extends React.ComponentProps<"div"> {
12
- value?: string;
13
- defaultValue?: string;
14
- onValueChange?: (value: string) => void;
15
- }
16
-
17
- function Tabs({ value, defaultValue, onValueChange, className, children, ...props }: TabsProps) {
18
- const [internalValue, setInternalValue] = React.useState(defaultValue || "");
19
- const controlled = value !== undefined;
20
- const currentValue = controlled ? value : internalValue;
21
-
22
- const handleValueChange = React.useCallback(
23
- (newValue: string) => {
24
- if (!controlled) {
25
- setInternalValue(newValue);
26
- }
27
- onValueChange?.(newValue);
28
- },
29
- [controlled, onValueChange],
30
- );
31
-
32
- return (
33
- <TabsContext.Provider value={{ value: currentValue, onValueChange: handleValueChange }}>
34
- <div data-slot="tabs" className={cn("w-full", className)} {...props}>
35
- {children}
36
- </div>
37
- </TabsContext.Provider>
38
- );
39
- }
40
-
41
- function useTabsContext() {
42
- const context = React.useContext(TabsContext);
43
- if (!context) {
44
- throw new Error("Tabs components must be used within a Tabs component");
45
- }
46
- return context;
47
- }
48
-
49
- function TabsList({ className, ...props }: React.ComponentProps<"div">) {
50
- return (
51
- <div
52
- data-slot="tabs-list"
53
- className={cn(
54
- "inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",
55
- className,
56
- )}
57
- {...props}
58
- />
59
- );
60
- }
61
-
62
- interface TabsTriggerProps extends React.ComponentProps<"button"> {
63
- value: string;
64
- }
65
-
66
- function TabsTrigger({ className, value, ...props }: TabsTriggerProps) {
67
- const { value: selectedValue, onValueChange } = useTabsContext();
68
- const isSelected = selectedValue === value;
69
-
70
- return (
71
- <button
72
- data-slot="tabs-trigger"
73
- data-selected={isSelected}
74
- type="button"
75
- role="tab"
76
- aria-selected={isSelected}
77
- className={cn(
78
- "inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
79
- isSelected
80
- ? "bg-background text-foreground shadow-sm"
81
- : "text-muted-foreground hover:bg-background/50",
82
- className,
83
- )}
84
- onClick={() => onValueChange(value)}
85
- {...props}
86
- />
87
- );
88
- }
89
-
90
- interface TabsContentProps extends React.ComponentProps<"div"> {
91
- value: string;
92
- }
93
-
94
- function TabsContent({ className, value, children, ...props }: TabsContentProps) {
95
- const { value: selectedValue } = useTabsContext();
96
- if (selectedValue !== value) {
97
- return null;
98
- }
99
-
100
- return (
101
- <div
102
- data-slot="tabs-content"
103
- role="tabpanel"
104
- className={cn(
105
- "mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
106
- className,
107
- )}
108
- {...props}
109
- >
110
- {children}
111
- </div>
112
- );
113
- }
114
-
115
- export { Tabs, TabsList, TabsTrigger, TabsContent };
@@ -1,83 +0,0 @@
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
- }
@@ -1,116 +0,0 @@
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
- });
@@ -1,6 +0,0 @@
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
- }
@@ -1,12 +0,0 @@
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;
@@ -1,98 +0,0 @@
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
- }
@@ -1,67 +0,0 @@
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
- }
@@ -1,89 +0,0 @@
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
- }