Skip to content

Commit

Permalink
Merge pull request #1121 from brave/master
Browse files Browse the repository at this point in the history
Production Release 2024-03-11
  • Loading branch information
tackley authored Mar 11, 2024
2 parents cb50b49 + 8aa1b8c commit 875d3a8
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/auth/hooks/mutations/useRegister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { useTrackMatomoEvent } from "hooks/useTrackWithMatomo";
import { t } from "@lingui/macro";
import { useHistory } from "react-router-dom";

export function useRegister(props: { legacy?: boolean } = {}) {
export function useRegister() {
const history = useHistory();
const [loading, setLoading] = useState(false);
const { trackMatomoEvent } = useTrackMatomoEvent();

const register = useCallback(
(form: RegistrationForm, type: "search" | "browser") => {
setLoading(true);
submitRegistration(form, type, props.legacy)
submitRegistration(form, type)
.then(() => {
if (form.marketingOptIn) {
void sendMarketingEmail({ ...form.user });
Expand All @@ -30,7 +30,7 @@ export function useRegister(props: { legacy?: boolean } = {}) {
})
.finally(() => setLoading(false));
},
[props.legacy],
[],
);

return { register, loading };
Expand Down
11 changes: 6 additions & 5 deletions src/auth/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { UserFragment } from "graphql/user.generated";
import { AdvertiserFragment } from "graphql/advertiser.generated";
import { PaymentType } from "graphql/types";
import { buildAdServerV2Endpoint } from "util/environment";
import {
buildAdServerEndpoint,
buildAdServerV2Endpoint,
} from "util/environment";
import { RegistrationForm } from "auth/registration/types";
import { t } from "@lingui/macro";

Expand Down Expand Up @@ -53,11 +56,9 @@ export const getCredentials = async (user: {
export async function submitRegistration(
form: RegistrationForm,
type: "search" | "browser",
legacy: boolean = false,
) {
let path = type === "search" ? "/register/search" : "/register";
path = legacy ? "/auth/register" : path;
const res = await fetch(buildAdServerV2Endpoint(path), {
const path = type === "search" ? "/register/search" : "/register";
const res = await fetch(buildAdServerEndpoint(path), {
method: "POST",
mode: "cors",
credentials: "include",
Expand Down
5 changes: 1 addition & 4 deletions src/auth/registration/BrowserRegister.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ export function BrowserRegister() {
documentTitle: `Browser Ads Registration`,
});

// TODO: Transition to new registration backend
const { register } = useRegister({
legacy: true,
});
const { register } = useRegister();

return (
<RegistrationContainer>
Expand Down
10 changes: 5 additions & 5 deletions src/auth/registration/Register.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { AdvertiserRegistered } from "auth/registration/AdvertiserRegistered";
import { Redirect, Route, Switch } from "react-router-dom";
import { Route, Switch } from "react-router-dom";
import { BrowserRegister } from "auth/registration/BrowserRegister";
import { SearchRegister } from "./SearchRegister";
import { AccountChoice } from "./AccountChoice";

export function Register() {
// TODO: uncomment search routes when back end is ready
return (
<Switch>
{/*<Route path="/register/search" component={SearchRegister} />*/}
<Route path="/register/search" component={SearchRegister} />
<Route path="/register/browser" component={BrowserRegister} />
<Route path="/register/complete" component={AdvertiserRegistered} />
<Redirect exact={true} to="/register/browser" />
{/*<Route exact={true} component={AccountChoice} />*/}
<Route exact={true} component={AccountChoice} />
</Switch>
);
}
5 changes: 5 additions & 0 deletions src/auth/registration/SearchRegister.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export function SearchRegister() {
initialValues={initialValues}
onSubmit={async (v: RegistrationForm, { setSubmitting }) => {
setSubmitting(true);

// quick fixes to capture last minute changes to form structure
v.mediaSpend = undefined;
v.advertiser.url = v.domain;

register(v, "search");
setSubmitting(false);
}}
Expand Down

0 comments on commit 875d3a8

Please sign in to comment.