@salesforce/webapp-template-app-react-vibe-coding-starter-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.
- 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 +211 -0
- package/dist/.a4drules/graphql/tools/knowledge/lds-generate-graphql-readquery.md +185 -0
- package/dist/.a4drules/graphql/tools/knowledge/lds-guide-graphql.md +205 -0
- package/dist/.a4drules/graphql/tools/schemas/shared.graphqls +1150 -0
- package/dist/.a4drules/graphql.md +98 -0
- package/dist/.a4drules/images.md +13 -0
- package/dist/.a4drules/react.md +361 -0
- package/dist/.a4drules/react_image_processing.md +45 -0
- package/dist/.a4drules/typescript.md +224 -0
- package/dist/.forceignore +15 -0
- package/dist/.husky/pre-commit +4 -0
- package/dist/.prettierignore +11 -0
- package/dist/.prettierrc +17 -0
- package/dist/CHANGELOG.md +11 -0
- package/dist/README.md +18 -0
- package/dist/config/project-scratch-def.json +13 -0
- package/dist/force-app/main/default/digitalExperienceConfigs/appreactvibecodingstarter1.digitalExperienceConfig +8 -0
- package/dist/force-app/main/default/digitalExperiences/site/appreactvibecodingstarter1/appreactvibecodingstarter1.digitalExperience-meta.xml +11 -0
- package/dist/force-app/main/default/digitalExperiences/site/appreactvibecodingstarter1/sfdc_cms__site/appreactvibecodingstarter1/_meta.json +5 -0
- package/dist/force-app/main/default/digitalExperiences/site/appreactvibecodingstarter1/sfdc_cms__site/appreactvibecodingstarter1/content.json +10 -0
- package/dist/force-app/main/default/networks/appreactvibecodingstarter.network +60 -0
- package/dist/force-app/main/default/package.xml +20 -0
- package/dist/force-app/main/default/sites/appreactvibecodingstarter.site +31 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/.prettierignore +9 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/.prettierrc +11 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/appreactvibecodingstarter.webapplication-meta.xml +7 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/eslint.config.js +113 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/index.html +13 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/package.json +42 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/api/graphql-operations-types.ts +127 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/api/utils/query/highRevenueAccountsQuery.graphql +29 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/app.tsx +16 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/appLayout.tsx +9 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/assets/icons/book.svg +3 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/assets/icons/copy.svg +4 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/assets/icons/rocket.svg +3 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/assets/icons/star.svg +3 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/assets/images/codey-1.png +0 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/assets/images/codey-2.png +0 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/assets/images/codey-3.png +0 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/assets/images/vibe-codey.svg +194 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/components/AccountsTable.tsx +134 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/components/Footer.test.tsx +35 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/components/Footer.tsx +68 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/components/Hero.test.tsx +44 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/components/Hero.tsx +61 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/components/PromptCard.test.tsx +57 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/components/PromptCard.tsx +301 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/components/PromptHighlight.test.tsx +85 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/components/PromptHighlight.tsx +73 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/components/alerts/status-alert.tsx +45 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/components/auth/authentication-route.tsx +21 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/components/auth/private-route.tsx +36 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/components/footers/footer-link.tsx +36 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/components/forms/auth-form.tsx +79 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/components/forms/submit-button.tsx +49 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/components/layout/card-layout.tsx +23 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/components/layout/centered-page-layout.tsx +73 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/components/layout/loading-page.tsx +46 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/components/ui/alert.tsx +65 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/components/ui/button.tsx +56 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/components/ui/card.tsx +77 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/components/ui/field.tsx +111 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/components/ui/index.ts +71 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/components/ui/input.tsx +19 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/components/ui/label.tsx +19 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/components/ui/pagination.tsx +99 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/components/ui/select.tsx +151 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/components/ui/skeleton.tsx +7 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/components/ui/spinner.tsx +21 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/components/ui/table.tsx +114 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/components/ui/tabs.tsx +115 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/context/AuthContext.tsx +83 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/hooks/form.tsx +116 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/index.tsx +229 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/lib/utils.ts +6 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/pages/ChangePassword.tsx +105 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/pages/ForgotPassword.tsx +67 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/pages/Home.tsx +12 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/pages/Login.tsx +84 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/pages/NotFound.tsx +18 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/pages/Profile.tsx +146 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/pages/Register.tsx +117 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/pages/ResetPassword.tsx +101 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/routes.tsx +71 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/styles/global.css +270 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/testCmp.tsx +9 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/utils/authenticationConfig.ts +52 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/src/utils/helpers.ts +161 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/tsconfig.json +36 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/tsconfig.node.json +13 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/vite-env.d.ts +1 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/vite.config.ts +82 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/vitest-env.d.ts +2 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/vitest.config.ts +11 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/vitest.setup.ts +1 -0
- package/dist/force-app/main/default/webapplications/appreactvibecodingstarter/webapplication.json +7 -0
- package/dist/jest.config.js +6 -0
- package/dist/package.json +37 -0
- package/dist/scripts/apex/hello.apex +10 -0
- package/dist/scripts/soql/account.soql +6 -0
- package/dist/sfdx-project.json +12 -0
- package/package.json +34 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import PromptHighlight from "./PromptHighlight";
|
|
4
|
+
|
|
5
|
+
describe("PromptHighlight", () => {
|
|
6
|
+
const defaultProps = {
|
|
7
|
+
image: "/test-image.png",
|
|
8
|
+
imageAlt: "Test Image",
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
it("renders children and image", () => {
|
|
12
|
+
render(
|
|
13
|
+
<PromptHighlight {...defaultProps}>
|
|
14
|
+
<div>Test Content</div>
|
|
15
|
+
</PromptHighlight>,
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
expect(screen.getByText("Test Content")).toBeInTheDocument();
|
|
19
|
+
expect(screen.getByAltText("Test Image")).toBeInTheDocument();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("positions image on the right by default", () => {
|
|
23
|
+
const { container } = render(
|
|
24
|
+
<PromptHighlight {...defaultProps}>
|
|
25
|
+
<div data-testid="content">Content</div>
|
|
26
|
+
</PromptHighlight>,
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const layout = container.firstChild as HTMLElement;
|
|
30
|
+
const children = Array.from(layout.children);
|
|
31
|
+
|
|
32
|
+
expect(children[0]).toContainElement(screen.getByTestId("content"));
|
|
33
|
+
expect(children[1]).toContainElement(screen.getByAltText("Test Image"));
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("positions image on the left when specified", () => {
|
|
37
|
+
const { container } = render(
|
|
38
|
+
<PromptHighlight {...defaultProps} imagePosition="left">
|
|
39
|
+
<div data-testid="content">Content</div>
|
|
40
|
+
</PromptHighlight>,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const layout = container.firstChild as HTMLElement;
|
|
44
|
+
const children = Array.from(layout.children);
|
|
45
|
+
|
|
46
|
+
expect(children[0]).toContainElement(screen.getByAltText("Test Image"));
|
|
47
|
+
expect(children[1]).toContainElement(screen.getByTestId("content"));
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("supports landscape and square image sizes", () => {
|
|
51
|
+
const { rerender } = render(
|
|
52
|
+
<PromptHighlight {...defaultProps} imageSize="landscape">
|
|
53
|
+
<div>Content</div>
|
|
54
|
+
</PromptHighlight>,
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
let img = screen.getByAltText("Test Image");
|
|
58
|
+
expect(img.parentElement).toBeInTheDocument();
|
|
59
|
+
|
|
60
|
+
rerender(
|
|
61
|
+
<PromptHighlight {...defaultProps} imageSize="square">
|
|
62
|
+
<div>Content</div>
|
|
63
|
+
</PromptHighlight>,
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
img = screen.getByAltText("Test Image");
|
|
67
|
+
expect(img.parentElement).toBeInTheDocument();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("renders complex children content", () => {
|
|
71
|
+
render(
|
|
72
|
+
<PromptHighlight {...defaultProps}>
|
|
73
|
+
<div>
|
|
74
|
+
<h2>Heading</h2>
|
|
75
|
+
<p>Paragraph</p>
|
|
76
|
+
<button type="button">Click me</button>
|
|
77
|
+
</div>
|
|
78
|
+
</PromptHighlight>,
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
expect(screen.getByText("Heading")).toBeInTheDocument();
|
|
82
|
+
expect(screen.getByText("Paragraph")).toBeInTheDocument();
|
|
83
|
+
expect(screen.getByRole("button", { name: "Click me" })).toBeInTheDocument();
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type React from "react";
|
|
2
|
+
|
|
3
|
+
interface PromptHighlightProps {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
image: string | React.ReactNode;
|
|
6
|
+
imageAlt: string;
|
|
7
|
+
imagePosition?: "left" | "right";
|
|
8
|
+
imageSize?: "landscape" | "square";
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default function PromptHighlight({
|
|
12
|
+
children,
|
|
13
|
+
image,
|
|
14
|
+
imageAlt,
|
|
15
|
+
imagePosition = "right",
|
|
16
|
+
imageSize = "landscape",
|
|
17
|
+
}: PromptHighlightProps) {
|
|
18
|
+
const imageContainerStyle =
|
|
19
|
+
imageSize === "square" ? styles.promptImageContainerSquare : styles.promptImageContainer;
|
|
20
|
+
|
|
21
|
+
const imageElement =
|
|
22
|
+
typeof image === "string" ? (
|
|
23
|
+
<div style={imageContainerStyle}>
|
|
24
|
+
<img src={image} alt={imageAlt} style={styles.promptImage} />
|
|
25
|
+
</div>
|
|
26
|
+
) : (
|
|
27
|
+
<div style={imageContainerStyle}>{image}</div>
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<div style={styles.layout}>
|
|
32
|
+
{imagePosition === "left" ? (
|
|
33
|
+
<>
|
|
34
|
+
{imageElement}
|
|
35
|
+
{children}
|
|
36
|
+
</>
|
|
37
|
+
) : (
|
|
38
|
+
<>
|
|
39
|
+
{children}
|
|
40
|
+
{imageElement}
|
|
41
|
+
</>
|
|
42
|
+
)}
|
|
43
|
+
</div>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const styles: Record<string, React.CSSProperties> = {
|
|
48
|
+
layout: {
|
|
49
|
+
display: "flex",
|
|
50
|
+
alignItems: "center",
|
|
51
|
+
gap: "20px",
|
|
52
|
+
width: "100%",
|
|
53
|
+
},
|
|
54
|
+
promptImageContainer: {
|
|
55
|
+
flexShrink: 0,
|
|
56
|
+
width: "480px",
|
|
57
|
+
height: "250px",
|
|
58
|
+
overflow: "hidden",
|
|
59
|
+
borderRadius: "8px",
|
|
60
|
+
},
|
|
61
|
+
promptImageContainerSquare: {
|
|
62
|
+
flexShrink: 0,
|
|
63
|
+
width: "371px",
|
|
64
|
+
height: "371px",
|
|
65
|
+
overflow: "hidden",
|
|
66
|
+
borderRadius: "8px",
|
|
67
|
+
},
|
|
68
|
+
promptImage: {
|
|
69
|
+
width: "100%",
|
|
70
|
+
height: "100%",
|
|
71
|
+
objectFit: "contain",
|
|
72
|
+
},
|
|
73
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
2
|
+
import { AlertCircleIcon, CheckCircle2Icon } from "lucide-react";
|
|
3
|
+
import { Alert, AlertDescription } from "../ui/alert";
|
|
4
|
+
import { useId } from "react";
|
|
5
|
+
|
|
6
|
+
const statusAlertVariants = cva("", {
|
|
7
|
+
variants: {
|
|
8
|
+
variant: {
|
|
9
|
+
error: "",
|
|
10
|
+
success: "",
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
defaultVariants: {
|
|
14
|
+
variant: "error",
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
interface StatusAlertProps extends VariantProps<typeof statusAlertVariants> {
|
|
19
|
+
children?: React.ReactNode;
|
|
20
|
+
/** Alert variant type. @default "error" */
|
|
21
|
+
variant?: "error" | "success";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Status alert component for displaying error or success messages.
|
|
26
|
+
* Returns null if no children are provided.
|
|
27
|
+
*/
|
|
28
|
+
export function StatusAlert({ children, variant = "error" }: StatusAlertProps) {
|
|
29
|
+
if (!children) return null;
|
|
30
|
+
|
|
31
|
+
const isError = variant === "error";
|
|
32
|
+
const descriptionId = useId();
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<Alert
|
|
36
|
+
variant={isError ? "destructive" : "default"}
|
|
37
|
+
className={statusAlertVariants({ variant })}
|
|
38
|
+
aria-describedby={descriptionId}
|
|
39
|
+
role={isError ? "alert" : "status"}
|
|
40
|
+
>
|
|
41
|
+
{isError ? <AlertCircleIcon aria-hidden="true" /> : <CheckCircle2Icon aria-hidden="true" />}
|
|
42
|
+
<AlertDescription id={descriptionId}>{children}</AlertDescription>
|
|
43
|
+
</Alert>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Navigate, Outlet, useSearchParams } from "react-router";
|
|
2
|
+
import { useAuth } from "../../context/AuthContext";
|
|
3
|
+
import { getStartUrl } from "../../utils/helpers";
|
|
4
|
+
import { LoadingPage } from "../layout/loading-page";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* [Dev Note] "Public Only" Route Guard:
|
|
8
|
+
* This component protects routes that should NOT be accessible if the user is already logged in
|
|
9
|
+
* (e.g., Login, Register, Forgot Password).
|
|
10
|
+
* If an authenticated user tries to access these pages, they are automatically redirected
|
|
11
|
+
* to the default authenticated view (e.g., Home or Profile) to prevent confusion.
|
|
12
|
+
*/
|
|
13
|
+
export default function AuthenticationRoute() {
|
|
14
|
+
const { isAuthenticated, loading } = useAuth();
|
|
15
|
+
const [searchParams] = useSearchParams();
|
|
16
|
+
|
|
17
|
+
if (loading) return <LoadingPage contentMaxWidth="md" />;
|
|
18
|
+
if (isAuthenticated) return <Navigate to={getStartUrl(searchParams)} replace />;
|
|
19
|
+
|
|
20
|
+
return <Outlet />;
|
|
21
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Navigate, Outlet, useLocation } from "react-router";
|
|
2
|
+
import { useAuth } from "../../context/AuthContext";
|
|
3
|
+
import { AUTH_REDIRECT_PARAM, ROUTES } from "../../utils/authenticationConfig";
|
|
4
|
+
import { LoadingPage } from "../layout/loading-page";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* [Dev Note] Route Guard:
|
|
8
|
+
* Renders the child route (Outlet) if the user is authenticated.
|
|
9
|
+
* Otherwise, redirects to Login with a 'startUrl' parameter so the user can be
|
|
10
|
+
* returned to this page after successful login.
|
|
11
|
+
*/
|
|
12
|
+
export default function PrivateRoute() {
|
|
13
|
+
const { isAuthenticated, loading } = useAuth();
|
|
14
|
+
const location = useLocation();
|
|
15
|
+
|
|
16
|
+
if (loading) return <LoadingPage contentMaxWidth="md" />;
|
|
17
|
+
|
|
18
|
+
if (!isAuthenticated) {
|
|
19
|
+
const searchParams = new URLSearchParams();
|
|
20
|
+
|
|
21
|
+
// [Dev Note] Capture current location to return after login
|
|
22
|
+
const destination = location.pathname + location.search;
|
|
23
|
+
searchParams.set(AUTH_REDIRECT_PARAM, destination);
|
|
24
|
+
return (
|
|
25
|
+
<Navigate // Navigate accepts an object to safely construct the URL
|
|
26
|
+
to={{
|
|
27
|
+
pathname: ROUTES.LOGIN.PATH,
|
|
28
|
+
search: searchParams.toString(),
|
|
29
|
+
}}
|
|
30
|
+
replace
|
|
31
|
+
/>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return <Outlet />;
|
|
36
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Link } from "react-router";
|
|
2
|
+
import { cn } from "../../lib/utils";
|
|
3
|
+
|
|
4
|
+
interface FooterLinkProps extends Omit<React.ComponentProps<typeof Link>, "children"> {
|
|
5
|
+
/** Link text prefix (e.g., "Don't have an account?") */
|
|
6
|
+
text?: string;
|
|
7
|
+
/** Link label (e.g., "Sign up") */
|
|
8
|
+
linkText: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Footer link component.
|
|
13
|
+
*/
|
|
14
|
+
export function FooterLink({ text, to, linkText, className, ...props }: FooterLinkProps) {
|
|
15
|
+
return (
|
|
16
|
+
<p className={cn("w-full text-center text-sm text-muted-foreground", className)}>
|
|
17
|
+
{text && (
|
|
18
|
+
<>
|
|
19
|
+
{text}
|
|
20
|
+
{/* Robustness: Explicit space ensures formatting tools don't strip it */}
|
|
21
|
+
{"\u00A0"}
|
|
22
|
+
</>
|
|
23
|
+
)}
|
|
24
|
+
<Link
|
|
25
|
+
to={to}
|
|
26
|
+
className={cn(
|
|
27
|
+
"font-medium underline hover:text-primary transition-colors",
|
|
28
|
+
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
|
29
|
+
)}
|
|
30
|
+
{...props}
|
|
31
|
+
>
|
|
32
|
+
{linkText}
|
|
33
|
+
</Link>
|
|
34
|
+
</p>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { FieldGroup } from "../ui/field";
|
|
2
|
+
import { StatusAlert } from "../alerts/status-alert";
|
|
3
|
+
import { FooterLink } from "../footers/footer-link";
|
|
4
|
+
import { SubmitButton } from "./submit-button";
|
|
5
|
+
import { CardLayout } from "../layout/card-layout";
|
|
6
|
+
import { useFormContext } from "../../hooks/form";
|
|
7
|
+
import { useId } from "react";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* [Dev Note] A wrapper component that enforces consistent layout (Card) and error/success alert positioning
|
|
11
|
+
* for all authentication forms.
|
|
12
|
+
*/
|
|
13
|
+
interface AuthFormProps extends Omit<React.ComponentProps<"form">, "onSubmit"> {
|
|
14
|
+
title: string;
|
|
15
|
+
description: string;
|
|
16
|
+
error?: React.ReactNode;
|
|
17
|
+
success?: React.ReactNode;
|
|
18
|
+
submit: {
|
|
19
|
+
text: string;
|
|
20
|
+
loadingText?: string;
|
|
21
|
+
};
|
|
22
|
+
footer?: {
|
|
23
|
+
text?: string;
|
|
24
|
+
link: string;
|
|
25
|
+
linkText: string;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* [Dev Note] Standardized Authentication Layout:
|
|
31
|
+
* Wraps the specific logic of Login/Register forms with a consistent visual frame (Card),
|
|
32
|
+
* title, and error alert placement. Extends form element props for flexibility.
|
|
33
|
+
* This ensures all auth-related pages look and behave similarly.
|
|
34
|
+
*/
|
|
35
|
+
export function AuthForm({
|
|
36
|
+
id: providedId,
|
|
37
|
+
title,
|
|
38
|
+
description,
|
|
39
|
+
error,
|
|
40
|
+
success,
|
|
41
|
+
children,
|
|
42
|
+
submit,
|
|
43
|
+
footer,
|
|
44
|
+
...props
|
|
45
|
+
}: AuthFormProps) {
|
|
46
|
+
const form = useFormContext();
|
|
47
|
+
const generatedId = useId();
|
|
48
|
+
const id = providedId ?? generatedId;
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<CardLayout title={title} description={description}>
|
|
52
|
+
<div className="space-y-6">
|
|
53
|
+
{/* [Dev Note] Global form error alert (e.g. "Invalid Credentials") */}
|
|
54
|
+
{error && <StatusAlert variant="error">{error}</StatusAlert>}
|
|
55
|
+
{success && <StatusAlert variant="success">{success}</StatusAlert>}
|
|
56
|
+
|
|
57
|
+
<form
|
|
58
|
+
id={id}
|
|
59
|
+
onSubmit={(e) => {
|
|
60
|
+
e.preventDefault();
|
|
61
|
+
e.stopPropagation();
|
|
62
|
+
form.handleSubmit();
|
|
63
|
+
}}
|
|
64
|
+
{...props}
|
|
65
|
+
>
|
|
66
|
+
<FieldGroup>{children}</FieldGroup>
|
|
67
|
+
<SubmitButton
|
|
68
|
+
form={id}
|
|
69
|
+
label={submit.text}
|
|
70
|
+
loadingLabel={submit.loadingText}
|
|
71
|
+
className="mt-6"
|
|
72
|
+
/>
|
|
73
|
+
</form>
|
|
74
|
+
{/* [Dev Note] Navigation links (e.g. "Forgot Password?") */}
|
|
75
|
+
{footer && <FooterLink text={footer.text} to={footer.link} linkText={footer.linkText} />}
|
|
76
|
+
</div>
|
|
77
|
+
</CardLayout>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Button } from "../ui/button";
|
|
2
|
+
import { Spinner } from "../ui/spinner";
|
|
3
|
+
import { cn } from "../../lib/utils";
|
|
4
|
+
import { useFormContext } from "../../hooks/form";
|
|
5
|
+
|
|
6
|
+
interface SubmitButtonProps extends Omit<React.ComponentProps<typeof Button>, "type" | "disabled"> {
|
|
7
|
+
/** Button text when not submitting */
|
|
8
|
+
label: string;
|
|
9
|
+
/** Button text while submitting */
|
|
10
|
+
loadingLabel?: string;
|
|
11
|
+
/** Form id to associate with (for buttons outside form element) */
|
|
12
|
+
form?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const isSubmittingSelector = (state: { isSubmitting: boolean }) => state.isSubmitting;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Submit button that subscribes to form submission state.
|
|
19
|
+
* UX Best Practice:
|
|
20
|
+
* 1. Disables interaction immediately upon click (via isLoading) to prevent
|
|
21
|
+
* accidental double-submissions which can cause race conditions in Auth APIs.
|
|
22
|
+
* 2. Provides immediate visual feedback (Spinner) because Auth calls (e.g. hashing passwords,
|
|
23
|
+
* generating sessions) can have variable latency.
|
|
24
|
+
*/
|
|
25
|
+
export function SubmitButton({
|
|
26
|
+
label,
|
|
27
|
+
loadingLabel = "Submitting…",
|
|
28
|
+
className,
|
|
29
|
+
form: formId,
|
|
30
|
+
...props
|
|
31
|
+
}: SubmitButtonProps) {
|
|
32
|
+
const form = useFormContext();
|
|
33
|
+
return (
|
|
34
|
+
<form.Subscribe selector={isSubmittingSelector}>
|
|
35
|
+
{(isSubmitting: boolean) => (
|
|
36
|
+
<Button
|
|
37
|
+
type="submit"
|
|
38
|
+
form={formId}
|
|
39
|
+
className={cn("w-full", className)}
|
|
40
|
+
disabled={isSubmitting}
|
|
41
|
+
{...props}
|
|
42
|
+
>
|
|
43
|
+
{isSubmitting && <Spinner className="mr-2" aria-hidden="true" />}
|
|
44
|
+
{isSubmitting ? loadingLabel : label}
|
|
45
|
+
</Button>
|
|
46
|
+
)}
|
|
47
|
+
</form.Subscribe>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "../ui/card";
|
|
2
|
+
|
|
3
|
+
interface CardLayoutProps {
|
|
4
|
+
title: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Card layout component for authentication pages.
|
|
11
|
+
* Provides CardHeader with title and optional description, and CardContent.
|
|
12
|
+
*/
|
|
13
|
+
export function CardLayout({ title, description, children }: CardLayoutProps) {
|
|
14
|
+
return (
|
|
15
|
+
<Card>
|
|
16
|
+
<CardHeader>
|
|
17
|
+
<CardTitle className="text-2xl">{title}</CardTitle>
|
|
18
|
+
{description && <CardDescription>{description}</CardDescription>}
|
|
19
|
+
</CardHeader>
|
|
20
|
+
<CardContent>{children}</CardContent>
|
|
21
|
+
</Card>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
2
|
+
import { cn } from "../../lib/utils";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Variant styles for the content container's maximum width.
|
|
6
|
+
* Controls the maximum width of the inner content area within the page layout.
|
|
7
|
+
*/
|
|
8
|
+
const contentContainerVariants = cva("w-full", {
|
|
9
|
+
variants: {
|
|
10
|
+
contentMaxWidth: {
|
|
11
|
+
sm: "max-w-sm",
|
|
12
|
+
md: "max-w-md",
|
|
13
|
+
lg: "max-w-lg",
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
defaultVariants: {
|
|
17
|
+
contentMaxWidth: "sm",
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Props for the CenteredPageLayout component.
|
|
23
|
+
*/
|
|
24
|
+
interface CenteredPageLayoutProps
|
|
25
|
+
extends React.ComponentProps<"div">,
|
|
26
|
+
VariantProps<typeof contentContainerVariants> {
|
|
27
|
+
/** The content to be displayed within the page layout */
|
|
28
|
+
children: React.ReactNode;
|
|
29
|
+
/**
|
|
30
|
+
* Maximum width of the content container.
|
|
31
|
+
* @default "sm"
|
|
32
|
+
*/
|
|
33
|
+
contentMaxWidth?: "sm" | "md" | "lg";
|
|
34
|
+
/**
|
|
35
|
+
* Optional page title. If provided, will render a <title> component that React will place in the document head.
|
|
36
|
+
*/
|
|
37
|
+
title?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* CenteredPageLayout component that provides consistent page structure and spacing.
|
|
42
|
+
*
|
|
43
|
+
* This component creates a full-viewport-height container that centers its content
|
|
44
|
+
* both horizontally and vertically. The inner content area has a configurable maximum width
|
|
45
|
+
* to prevent content from becoming too wide on large screens.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```tsx
|
|
49
|
+
* <CenteredPageLayout contentMaxWidth="md">
|
|
50
|
+
* <YourPageContent />
|
|
51
|
+
* </CenteredPageLayout>
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export function CenteredPageLayout({
|
|
55
|
+
contentMaxWidth,
|
|
56
|
+
className,
|
|
57
|
+
children,
|
|
58
|
+
title,
|
|
59
|
+
...props
|
|
60
|
+
}: CenteredPageLayoutProps) {
|
|
61
|
+
return (
|
|
62
|
+
<>
|
|
63
|
+
{title && <title>{title}</title>}
|
|
64
|
+
<main
|
|
65
|
+
className={cn("flex min-h-svh w-full items-center justify-center p-6 md:p-10", className)}
|
|
66
|
+
data-slot="page-layout"
|
|
67
|
+
{...props}
|
|
68
|
+
>
|
|
69
|
+
<div className={contentContainerVariants({ contentMaxWidth })}>{children}</div>
|
|
70
|
+
</main>
|
|
71
|
+
</>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
2
|
+
import { CenteredPageLayout } from "./centered-page-layout";
|
|
3
|
+
import { Spinner } from "../ui/spinner";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Spinner size variants based on content width.
|
|
7
|
+
*/
|
|
8
|
+
const spinnerVariants = cva("", {
|
|
9
|
+
variants: {
|
|
10
|
+
contentMaxWidth: {
|
|
11
|
+
sm: "size-6",
|
|
12
|
+
md: "size-8",
|
|
13
|
+
lg: "size-10",
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
defaultVariants: {
|
|
17
|
+
contentMaxWidth: "sm",
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
interface LoadingPageProps extends VariantProps<typeof spinnerVariants> {
|
|
22
|
+
/**
|
|
23
|
+
* Maximum width of the content container. Also scales the spinner size.
|
|
24
|
+
* @default "sm"
|
|
25
|
+
*/
|
|
26
|
+
contentMaxWidth?: "sm" | "md" | "lg";
|
|
27
|
+
/**
|
|
28
|
+
* Accessible label for screen readers.
|
|
29
|
+
* @default "Loading…"
|
|
30
|
+
*/
|
|
31
|
+
loadingText?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Full-page loading indicator with centered spinner.
|
|
36
|
+
*/
|
|
37
|
+
export function LoadingPage({ contentMaxWidth, loadingText = "Loading…" }: LoadingPageProps) {
|
|
38
|
+
return (
|
|
39
|
+
<CenteredPageLayout contentMaxWidth={contentMaxWidth}>
|
|
40
|
+
<div className="flex justify-center" role="status" aria-live="polite">
|
|
41
|
+
<Spinner className={spinnerVariants({ contentMaxWidth })} aria-hidden="true" />
|
|
42
|
+
<span className="sr-only">{loadingText}</span>
|
|
43
|
+
</div>
|
|
44
|
+
</CenteredPageLayout>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
2
|
+
|
|
3
|
+
import { cn } from "../../lib/utils";
|
|
4
|
+
|
|
5
|
+
const alertVariants = cva(
|
|
6
|
+
"relative w-full rounded-lg border px-4 py-3 text-sm grid has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] grid-cols-[0_1fr] has-[>svg]:gap-x-3 gap-y-0.5 items-start [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current",
|
|
7
|
+
{
|
|
8
|
+
variants: {
|
|
9
|
+
variant: {
|
|
10
|
+
default: "bg-card text-card-foreground",
|
|
11
|
+
destructive:
|
|
12
|
+
"text-destructive bg-card [&>svg]:text-current *:data-[slot=alert-description]:text-destructive/90",
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
defaultVariants: {
|
|
16
|
+
variant: "default",
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
function Alert({
|
|
22
|
+
className,
|
|
23
|
+
variant,
|
|
24
|
+
role,
|
|
25
|
+
...props
|
|
26
|
+
}: React.ComponentProps<"div"> & VariantProps<typeof alertVariants>) {
|
|
27
|
+
return (
|
|
28
|
+
<div
|
|
29
|
+
data-slot="alert"
|
|
30
|
+
role={role ?? (variant === "destructive" ? "alert" : "status")}
|
|
31
|
+
className={cn(alertVariants({ variant }), className)}
|
|
32
|
+
{...props}
|
|
33
|
+
/>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Maintenance/A11y: Added 'asChild' pattern or a simple 'as' prop
|
|
38
|
+
// to allow rendering semantic headings (h1-h6).
|
|
39
|
+
interface AlertTitleProps extends React.ComponentProps<"div"> {
|
|
40
|
+
as?: "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "div" | "p";
|
|
41
|
+
}
|
|
42
|
+
function AlertTitle({ className, as: Component = "div", ...props }: AlertTitleProps) {
|
|
43
|
+
return (
|
|
44
|
+
<div
|
|
45
|
+
data-slot="alert-title"
|
|
46
|
+
className={cn("col-start-2 line-clamp-1 min-h-4 font-medium tracking-tight", className)}
|
|
47
|
+
{...props}
|
|
48
|
+
/>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function AlertDescription({ className, ...props }: React.ComponentProps<"div">) {
|
|
53
|
+
return (
|
|
54
|
+
<div
|
|
55
|
+
data-slot="alert-description"
|
|
56
|
+
className={cn(
|
|
57
|
+
"col-start-2 grid justify-items-start gap-1 text-sm [&_p]:leading-relaxed",
|
|
58
|
+
className,
|
|
59
|
+
)}
|
|
60
|
+
{...props}
|
|
61
|
+
/>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export { Alert, AlertTitle, AlertDescription };
|