Skip to content

Commit

Permalink
fix: merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
harjibbolar26 committed Aug 24, 2024
1 parent 1fd3f3e commit 0b1004c
Showing 1 changed file with 27 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
"use client";

import { zodResolver } from "@hookform/resolvers/zod";
import axios from "axios";
import { Eye, EyeOff } from "lucide-react";
import { useSession } from "next-auth/react";
import { useState } from "react";
import { useForm } from "react-hook-form";
import { ChangeEvent, useState } from "react";

import { getApiUrl } from "~/actions/getApiUrl";
import CustomButton from "~/components/common/common-button/common-button";
import CustomInput from "~/components/common/input/input";
import PasswordSuccessfulModal from "~/components/common/modals/password-successful";
import { toast } from "~/components/ui/use-toast";

Expand All @@ -18,6 +17,7 @@ const Password = () => {
const { data } = useSession();

const [open, setOpen] = useState<boolean>(false);

const [isPending, setIsPending] = useState(false);

const [showPassword, setShowPassword] = useState({
Expand All @@ -40,24 +40,34 @@ const Password = () => {
}));
};

const submitHandler = async (values: PasswordFormData) => {
const submit = async () => {
if (formData.password !== formData.confirmPassword) {
return toast({
title: "Warning!",
description: "Password does not match",
});
}
try {
setIsPending(true);
const baseUrl = await getApiUrl();
const API_URL = `${baseUrl}/api/v1/auth/change-password`;

const payload = {
old_password: values.currentPassword,
new_password: values.newPassword,
confirm_new_password: values.confirmPassword,
oldPassword: formData.oldPassword,
newPassword: formData.password,
};
const baseUrl = await getApiUrl();
const API_URL = `${baseUrl}/api/v1/auth/password`;

await axios.put(API_URL, payload, {
await axios.post(API_URL, payload, {
headers: {
Authorization: `Bearer ${data?.access_token}`,
},
});
setOpen(true);
reset({ currentPassword: "", newPassword: "", confirmPassword: "" });
setFormData({
oldPassword: "",
password: "",
confirmPassword: "",
});
} catch (error) {
const errorMessage = (error as HttpError)?.response?.data?.message;
toast({
Expand Down Expand Up @@ -90,7 +100,7 @@ const Password = () => {
Update password for enhanced account security
</p>
</div>
<form onSubmit={handleSubmit(submitHandler)}>
<div>
<div className="mb-6 grid gap-4">
<div className="relative">
<CustomInput
Expand Down Expand Up @@ -149,23 +159,19 @@ const Password = () => {
</div>
</div>
<div className="flex items-center justify-start gap-6">
<CustomButton
type="button"
variant="outline"
onClick={() => setOpen(false)}
>
<CustomButton variant="outline" onClick={() => setOpen(false)}>
Cancel
</CustomButton>
<CustomButton
isDisabled={!isValid}
type="submit"
className={`bg-primary ${isPending && "opacity-50"}`}
isDisabled={disabled}
onClick={submit}
className="bg-primary"
isLoading={isPending}
>
Update Password
</CustomButton>
</div>
</form>
</div>
<PasswordSuccessfulModal onClose={() => setOpen(!open)} show={open} />
</div>
);
Expand Down

0 comments on commit 0b1004c

Please sign in to comment.