Skip to content

Commit

Permalink
client: fix signup workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Shubham-Lal committed Apr 2, 2024
1 parent c9cae3a commit cb9ecf5
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions client/src/components/modal/brief-info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { GrCloudUpload } from "react-icons/gr";
const BriefInfo: React.FC<RegisterDataProps> = ({ registerData, setRegisterData }) => {
const navigate = useNavigate();

const { setAuthTab, isAuthenticated, setIsAuthenticated, setUser } = useAuthStore();
const { setAuthTab, setUser, setIsAuthenticated } = useAuthStore();
const { clearTempUser } = useTempStore();

const [term, setTerm] = useState<boolean>(false);
Expand All @@ -22,6 +22,7 @@ const BriefInfo: React.FC<RegisterDataProps> = ({ registerData, setRegisterData
isFirstNameValid: true,
isLastNameValid: true
});
const [loading, setLoading] = useState<boolean>(false);

const handleInputChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
const { name, value } = e.target;
Expand Down Expand Up @@ -70,7 +71,7 @@ const BriefInfo: React.FC<RegisterDataProps> = ({ registerData, setRegisterData
if (!term) return;

if (trimmedUsername && trimmedFirstName && trimmedLastName) {
setIsAuthenticated(AuthStatus.Authenticating);
setLoading(true);
await fetch(`${import.meta.env.VITE_SERVER_URL}/api/auth/register`, {
method: 'POST',
headers: {
Expand All @@ -92,9 +93,9 @@ const BriefInfo: React.FC<RegisterDataProps> = ({ registerData, setRegisterData
toast.success(response.message);

setUser(response.data.user);
setIsAuthenticated(AuthStatus.Authenticated);
localStorage.setItem('token', response.data.token);
setAuthTab(AuthTab.Closed);
setIsAuthenticated(AuthStatus.Authenticated);

navigate('/');
}
Expand All @@ -106,7 +107,10 @@ const BriefInfo: React.FC<RegisterDataProps> = ({ registerData, setRegisterData
toast.error(response.message)
}
})
.catch(() => setIsAuthenticated(AuthStatus.Failed));
.catch(() => {
setLoading(false);
setIsAuthenticated(AuthStatus.Failed);
});
}
};

Expand Down Expand Up @@ -189,8 +193,8 @@ const BriefInfo: React.FC<RegisterDataProps> = ({ registerData, setRegisterData
</div>
<p>Accept <span>Terms & Conditions</span></p>
</div>
<button type='submit' disabled={isAuthenticated === AuthStatus.Authenticating}>
{isAuthenticated === AuthStatus.Authenticating ? <LoadingSVG size={23} /> : 'Create my Account'}
<button type='submit' disabled={loading}>
{loading ? <LoadingSVG size={23} /> : 'Create my Account'}
</button>
</form>
</div>
Expand Down

0 comments on commit cb9ecf5

Please sign in to comment.