Minor tweaks to sign up on frontend and database structure
This commit is contained in:
1 parent
d0690f2f06
commit
260bef98cd
10 files changed
+56
-1037
No files matched your search
Whitespace-only changes.
@@ -14,10 +14,9 @@ import {
|
||||
} from "@/components/ui/form";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { PasswordInput } from "@/components/password-input";
|
||||
import { registerUser } from "@/lib/api";
|
||||
import { ApiError } from "@/errors/api-error";
|
||||
import useAuth from "@/hooks/useAuth";
|
||||
import { PhoneInput } from "@/components/ui/phone-number-input";
|
||||
import { toast } from "@/hooks/useToast";
|
||||
|
||||
type SignUpFormProps = HTMLAttributes<HTMLDivElement>;
|
||||
|
||||
@@ -68,8 +67,6 @@ const formSchema = z
|
||||
export function SignUpForm({ className, ...props }: SignUpFormProps) {
|
||||
const { signUpMutation } = useAuth();
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [successMessage, setSuccessMessage] = useState<string | null>(null);
|
||||
|
||||
const form = useForm<z.infer<typeof formSchema>>({
|
||||
resolver: zodResolver(formSchema),
|
||||
@@ -84,17 +81,11 @@ export function SignUpForm({ className, ...props }: SignUpFormProps) {
|
||||
|
||||
async function onSubmit(data: z.infer<typeof formSchema>) {
|
||||
setIsLoading(true);
|
||||
setError(null);
|
||||
setSuccessMessage(null);
|
||||
|
||||
try {
|
||||
signUpMutation.mutate(data);
|
||||
setSuccessMessage("Account created successfully!");
|
||||
} catch (error: unknown) {
|
||||
setError(error instanceof ApiError ? error.response : "Something went wrong.");
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
signUpMutation.mutate(data);
|
||||
toast({
|
||||
title: "Successfully registered"
|
||||
});
|
||||
setIsLoading(false);
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -167,10 +158,6 @@ export function SignUpForm({ className, ...props }: SignUpFormProps) {
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
{error && <p className="text-red-500">{error}</p>}
|
||||
{successMessage && (
|
||||
<p className="text-green-500">{successMessage}</p>
|
||||
)}
|
||||
<Button className="mt-2" type="submit" disabled={isLoading}>
|
||||
{isLoading ? "Creating Account..." : "Create Account"}
|
||||
</Button>
|
||||
|
||||
Reference in new issue
Block a user