remove setusername

This commit is contained in:
Nikita Pekin 2023-03-09 07:19:15 +02:00
parent 08a96d3796
commit 84721bcccd
4 changed files with 0 additions and 132 deletions

View File

@ -1,70 +0,0 @@
/** @file Container responsible for rendering and interactions in setting username flow, after
* registration. */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import * as React from "react";
import * as auth from "../providers/auth";
import withRouter from "../../navigation";
import * as hooks from "../../hooks";
import * as utils from "../../utils";
import * as Icons from "../../components/svg";
// ============================
// === setUsernameContainer ===
// ============================
const setUsernameContainer = () => {
const { setUsername } = auth.useAuth();
const { accessToken, email } = auth.usePartialUserSession();
const { value: username, bind: bindUsername } = hooks.useInput("");
return (
<div className="min-h-screen flex flex-col items-center justify-center bg-gray-300">
<div className="flex flex-col bg-white shadow-md px-4 sm:px-6 md:px-8 lg:px-10 py-8 rounded-md w-full max-w-md">
<div className="font-medium self-center text-xl sm:text-2xl uppercase text-gray-800">
Set your username
</div>
<div className="mt-10">
<form
onSubmit={utils.handleEvent(() =>
setUsername(accessToken, username, email)
)}
>
<div className="flex flex-col mb-6">
<div className="relative">
<div className="inline-flex items-center justify-center absolute left-0 top-0 h-full w-10 text-gray-400">
<Icons.Svg data={Icons.PATHS.at} />
</div>
<input
{...bindUsername}
id="username"
type="text"
name="username"
className="text-sm sm:text-base placeholder-gray-500 pl-10 pr-4 rounded-lg border border-gray-400 w-full py-2 focus:outline-none focus:border-blue-400"
placeholder="Username"
/>
</div>
</div>
<div className="flex w-full">
<button
type="submit"
className="flex items-center justify-center focus:outline-none text-white text-sm sm:text-base bg-blue-600 hover:bg-blue-700 rounded py-2 w-full transition duration-150 ease-in"
>
<span className="mr-2 uppercase">Set username</span>
<span>
<Icons.Svg data={Icons.PATHS.rightArrow} />
</span>
</button>
</div>
</form>
</div>
</div>
</div>
);
};
export default withRouter(setUsernameContainer);

View File

@ -23,7 +23,6 @@ import * as error from "../../error";
const MESSAGES = {
signUpSuccess: "We have sent you an email with further instructions!",
confirmSignUpSuccess: "Your account has been confirmed! Please log in.",
setUsernameSuccess: "Your username has been set!",
signInWithPasswordSuccess: "Successfully logged in!",
pleaseWait: "Please wait...",
};
@ -83,11 +82,6 @@ export interface PartialUserSession {
interface AuthContextType {
signUp: (email: string, password: string) => Promise<void>;
confirmSignUp: (email: string, code: string) => Promise<void>;
setUsername: (
accessToken: string,
username: string,
email: string
) => Promise<void>;
signInWithGoogle: () => Promise<null>;
signInWithGitHub: () => Promise<null>;
signInWithPassword: (email: string, password: string) => Promise<void>;
@ -238,25 +232,6 @@ export const AuthProvider = (props: AuthProviderProps) => {
navigate(app.LOGIN_PATH);
});
const setUsername = async (
accessToken: string,
username: string,
email: string
) => {
const body: backendService.SetUsernameRequestBody = {
userName: username,
userEmail: email,
};
// TODO [NP]: https://github.com/enso-org/cloud-v2/issues/343
// Don't create a new API client here, reuse the one from the context.
const backend = backendService.createBackend(accessToken, logger);
await backend.setUsername(body);
navigate(app.DASHBOARD_PATH);
toast.success(MESSAGES.setUsernameSuccess);
};
const signInWithPassword = async (email: string, password: string) =>
cognito.signInWithPassword(email, password).then((result) => {
if (result.ok) {
@ -274,7 +249,6 @@ export const AuthProvider = (props: AuthProviderProps) => {
const value = {
signUp: withLoadingToast(signUp),
confirmSignUp: withLoadingToast(confirmSignUp),
setUsername,
signInWithGoogle: cognito.signInWithGoogle,
signInWithGitHub: cognito.signInWithGitHub,
signInWithPassword: withLoadingToast(signInWithPassword),
@ -342,10 +316,6 @@ export const ProtectedLayout = () => {
export const GuestLayout = () => {
const { session } = useAuth();
if (session?.state == "partial") {
return <router.Navigate to={app.SET_USERNAME_PATH} />;
}
if (session?.state == "full") {
return <router.Navigate to={app.DASHBOARD_PATH} />;
}
@ -355,16 +325,6 @@ export const GuestLayout = () => {
// =============================
// === usePartialUserSession ===
// =============================
export const usePartialUserSession = () => {
return router.useOutletContext<PartialUserSession>();
};
// ==========================
// === useFullUserSession ===
// ==========================

View File

@ -9,7 +9,6 @@ import DashboardContainer from "../dashboard/components/dashboard";
import LoginContainer from "../authentication/components/login";
import RegistrationContainer from "../authentication/components/registration";
import ConfirmRegistrationContainer from "../authentication/components/confirmRegistration";
import SetUsernameContainer from "../authentication/components/setUsername";
import * as authService from "../authentication/service";
import withRouter from "../navigation";
import * as loggerProvider from "../providers/logger";
@ -29,8 +28,6 @@ export const LOGIN_PATH = "/login";
export const REGISTRATION_PATH = "/registration";
/** Path to the confirm registration page. */
export const CONFIRM_REGISTRATION_PATH = "/confirmation";
/** Path to the set username page. */
export const SET_USERNAME_PATH = "/set-username";
@ -124,10 +121,6 @@ const AppRouter = (props: AppProps) => {
<DashboardContainer />
}
/>
<router.Route
path={SET_USERNAME_PATH}
element={<SetUsernameContainer />}
/>
</router.Route>
{/* Other pages are visible to unauthenticated and authenticated users. */}
<router.Route

View File

@ -17,8 +17,6 @@ const DEFAULT_OPEN_PROJECT_BODY: OpenProjectRequestBody = {
forceCreate: false,
};
/** Relative HTTP path to the "set username" endpoint of the Cloud backend API. */
const SET_USER_NAME_PATH = "users";
/** Relative HTTP path to the "get user" endpoint of the Cloud backend API. */
const GET_USER_PATH = "users/me";
/** Relative HTTP path to the "list projects" endpoint of the Cloud backend API. */
@ -103,12 +101,6 @@ export interface Project {
// === Endpoints ===
// =================
/** HTTP request body for the "set username" endpoint. */
export interface SetUsernameRequestBody {
userName: string;
userEmail: string;
}
/** HTTP response body for the "list projects" endpoint. */
interface ListProjectsResponseBody {
projects: Project[];
@ -162,13 +154,6 @@ export class Backend {
throw new Error(message);
};
/** Sets the username of the current user, on the Cloud backend API. */
setUsername = (body: SetUsernameRequestBody): Promise<Organization> =>
this.post(SET_USER_NAME_PATH)
.json(body)
.send()
.then((response) => response.model());
/** Returns organization info for the current user, from the Cloud backend API.
*
* @returns `null` if status code 401 or 404 was received. */