fix/premium-username-user-state-overriden (#7099)

This commit is contained in:
alannnc 2023-02-15 11:40:29 -07:00 committed by GitHub
parent ab6758194b
commit 0f76530c11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,3 +1,5 @@
import { useRouter } from "next/router";
import { useState } from "react";
import { Controller, useForm } from "react-hook-form";
import { IS_SELF_HOSTED } from "@calcom/lib/constants";
@ -22,7 +24,13 @@ export const UsernameAvailabilityField = ({
onErrorMutation,
user,
}: UsernameAvailabilityFieldProps) => {
const { username: currentUsername, setQuery: setCurrentUsername } = useRouterQuery("username");
const router = useRouter();
const [currentUsernameState, setCurrentUsernameState] = useState(user.username || "");
const { username: usernameFromQuery, setQuery: setUsernameFromQuery } = useRouterQuery("username");
const { username: currentUsername, setQuery: setCurrentUsername } =
router.query["username"] && user.username === null
? { username: usernameFromQuery, setQuery: setUsernameFromQuery }
: { username: currentUsernameState || "", setQuery: setCurrentUsernameState };
const formMethods = useForm({
defaultValues: {
username: currentUsername,