Skip to content

Commit 28573f2

Browse files
committed
refactor(react): Align SignUpAuth{Screen,Form} with API spec
1 parent f04c478 commit 28573f2

File tree

5 files changed

+28
-25
lines changed

5 files changed

+28
-25
lines changed

packages/react/src/auth/forms/register-form.test.tsx renamed to packages/react/src/auth/forms/sign-up-auth-form.test.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import { describe, it, expect, vi, beforeEach, Mock } from "vitest";
1818
import { render, screen, fireEvent } from "@testing-library/react";
19-
import { RegisterForm } from "./register-form";
19+
import { SignUpAuthForm } from "./sign-up-auth-form";
2020
import { act } from "react";
2121

2222
// Mock the dependencies
@@ -113,7 +113,7 @@ describe("RegisterForm", () => {
113113
});
114114

115115
it("renders the form correctly", () => {
116-
render(<RegisterForm />);
116+
render(<SignUpAuthForm />);
117117

118118
expect(screen.getByRole("textbox", { name: /email address/i })).toBeInTheDocument();
119119
expect(screen.getByLabelText(/password/i)).toBeInTheDocument();
@@ -122,7 +122,7 @@ describe("RegisterForm", () => {
122122
});
123123

124124
it("submits the form when the button is clicked", async () => {
125-
render(<RegisterForm />);
125+
render(<SignUpAuthForm />);
126126

127127
// Get the submit button
128128
const submitButton = screen.getByTestId("submit-button");
@@ -151,7 +151,7 @@ describe("RegisterForm", () => {
151151
const mockError = new Error("Email already in use");
152152
(createUserWithEmailAndPassword as Mock).mockRejectedValueOnce(mockError);
153153

154-
render(<RegisterForm />);
154+
render(<SignUpAuthForm />);
155155

156156
// Get the submit button
157157
const submitButton = screen.getByTestId("submit-button");
@@ -180,7 +180,7 @@ describe("RegisterForm", () => {
180180
});
181181

182182
it("validates on blur for the first time", async () => {
183-
render(<RegisterForm />);
183+
render(<SignUpAuthForm />);
184184

185185
const emailInput = screen.getByRole("textbox", { name: /email address/i });
186186
const passwordInput = screen.getByDisplayValue("password123");
@@ -195,7 +195,7 @@ describe("RegisterForm", () => {
195195
});
196196

197197
it("validates on input after first blur", async () => {
198-
render(<RegisterForm />);
198+
render(<SignUpAuthForm />);
199199

200200
const emailInput = screen.getByRole("textbox", { name: /email address/i });
201201
const passwordInput = screen.getByDisplayValue("password123");
@@ -219,7 +219,7 @@ describe("RegisterForm", () => {
219219
// TODO: Fix this test
220220
it.skip("displays back to sign in button when provided", () => {
221221
const onBackToSignInClickMock = vi.fn();
222-
render(<RegisterForm onBackToSignInClick={onBackToSignInClickMock} />);
222+
render(<SignUpAuthForm onBackToSignInClick={onBackToSignInClickMock} />);
223223

224224
const backButton = document.querySelector(".fui-form__action")!;
225225
expect(backButton).toBeInTheDocument();

packages/react/src/auth/forms/register-form.tsx renamed to packages/react/src/auth/forms/sign-up-auth-form.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ import { useUI } from "~/hooks";
2929
import { Button } from "../../components/button";
3030
import { FieldInfo } from "../../components/field-info";
3131
import { Policies } from "../../components/policies";
32+
import { type UserCredential } from "firebase/auth";
3233

33-
export interface RegisterFormProps {
34+
export type SignUpAuthFormProps = {
35+
onSignUp?: (credential: UserCredential) => void;
3436
onBackToSignInClick?: () => void;
3537
}
3638

37-
export function RegisterForm({ onBackToSignInClick }: RegisterFormProps) {
39+
export function SignUpAuthForm({ onBackToSignInClick, onSignUp }: SignUpAuthFormProps) {
3840
const ui = useUI();
3941

4042
const [formError, setFormError] = useState<string | null>(null);
@@ -53,7 +55,8 @@ export function RegisterForm({ onBackToSignInClick }: RegisterFormProps) {
5355
onSubmit: async ({ value }) => {
5456
setFormError(null);
5557
try {
56-
await createUserWithEmailAndPassword(ui, value.email, value.password);
58+
const credential = await createUserWithEmailAndPassword(ui, value.email, value.password);
59+
onSignUp?.(credential);
5760
} catch (error) {
5861
if (error instanceof FirebaseUIError) {
5962
setFormError(error.message);

packages/react/src/auth/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export { ForgotPasswordAuthScreen, type ForgotPasswordAuthScreenProps } from "./
2828

2929
export { SignInAuthForm, type SignInAuthFormProps } from "./forms/sign-in-auth-form";
3030

31-
export { RegisterForm, type RegisterFormProps } from "./forms/register-form";
31+
export { SignUpAuthForm, type SignUpAuthFormProps } from "./forms/sign-up-auth-form";
3232

3333
/** Export Buttons */
3434
export { GoogleSignInButton } from "./oauth/google-sign-in-button";

packages/react/src/auth/screens/sign-up-auth-screen.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@
1717
import { PropsWithChildren } from "react";
1818
import { Divider } from "~/components/divider";
1919
import { useUI } from "~/hooks";
20-
import { Card, CardHeader, CardSubtitle, CardTitle } from "../../components/card";
21-
import { RegisterForm } from "../forms/register-form";
20+
import { Card, CardContent, CardHeader, CardSubtitle, CardTitle } from "../../components/card";
21+
import { SignUpAuthForm, type SignUpAuthFormProps } from "../forms/sign-up-auth-form";
2222
import { getTranslation } from "@firebase-ui/core";
2323

24-
export type SignUpAuthScreenProps = PropsWithChildren<{
25-
onBackToSignInClick?: () => void;
26-
}>;
24+
export type SignUpAuthScreenProps = PropsWithChildren<SignUpAuthFormProps>;
2725

28-
export function SignUpAuthScreen({ onBackToSignInClick, children }: SignUpAuthScreenProps) {
26+
export function SignUpAuthScreen({ children, ...props }: SignUpAuthScreenProps) {
2927
const ui = useUI();
3028

3129
const titleText = getTranslation(ui, "labels", "register");
@@ -38,13 +36,15 @@ export function SignUpAuthScreen({ onBackToSignInClick, children }: SignUpAuthSc
3836
<CardTitle>{titleText}</CardTitle>
3937
<CardSubtitle>{subtitleText}</CardSubtitle>
4038
</CardHeader>
41-
<RegisterForm onBackToSignInClick={onBackToSignInClick} />
42-
{children ? (
43-
<>
44-
<Divider>{getTranslation(ui, "messages", "dividerOr")}</Divider>
45-
<div className="space-y-4">{children}</div>
46-
</>
47-
) : null}
39+
<CardContent>
40+
<SignUpAuthForm {...props} />
41+
{children ? (
42+
<>
43+
<Divider>{getTranslation(ui, "messages", "dividerOr")}</Divider>
44+
<div className="space-y-4">{children}</div>
45+
</>
46+
) : null}
47+
</CardContent>
4848
</Card>
4949
</div>
5050
);

packages/react/tests/integration/auth/register.integration.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import { describe, it, expect, afterAll, beforeEach } from "vitest";
1818
import { screen, fireEvent, waitFor, act, render } from "@testing-library/react";
19-
import { RegisterForm } from "../../../src/auth/forms/register-form";
19+
import { RegisterForm } from "../../../src/auth/forms/sign-up-auth-form";
2020
import { initializeApp } from "firebase/app";
2121
import { getAuth, connectAuthEmulator, deleteUser, signOut, signInWithEmailAndPassword } from "firebase/auth";
2222
import { initializeUI } from "@firebase-ui/core";

0 commit comments

Comments
 (0)