-
+
diff --git a/src/components/ManageCache/Sections/RevalidateBrandsAndModels.tsx b/src/components/ManageCache/Sections/RevalidateBrandsAndModels.tsx
deleted file mode 100644
index 723fa95..0000000
--- a/src/components/ManageCache/Sections/RevalidateBrandsAndModels.tsx
+++ /dev/null
@@ -1,18 +0,0 @@
-"use client";
-
-import { useMutation } from "@tanstack/react-query";
-import { toast } from "react-hot-toast";
-import { revalidateBrandsAndModelsAction } from "@/actions/cacheActions";
-
-export const RevalidateBrandsAndModels = () => {
- const { mutate, isLoading } = useMutation(async () => revalidateBrandsAndModelsAction(), {
- onSuccess: () => toast.success(`Successfully revalidated brands & models`),
- onError: () => toast.error(`Failed to revalidate brands & models`),
- });
-
- return (
-
- );
-};
diff --git a/src/components/ManageCache/Sections/RevalidateVehicleBrands.tsx b/src/components/ManageCache/Sections/RevalidateVehicleBrands.tsx
new file mode 100644
index 0000000..17c8c6f
--- /dev/null
+++ b/src/components/ManageCache/Sections/RevalidateVehicleBrands.tsx
@@ -0,0 +1,18 @@
+"use client";
+
+import { useMutation } from "@tanstack/react-query";
+import { toast } from "react-hot-toast";
+import { revalidateBrandsAction } from "@/actions/cacheActions";
+
+export const RevalidateVehicleBrands = () => {
+ const { mutate, isLoading } = useMutation(async () => revalidateBrandsAction(), {
+ onSuccess: () => toast.success(`Successfully revalidated vehicle brands`),
+ onError: () => toast.error(`Failed to revalidate vehicle brands`),
+ });
+
+ return (
+
+ );
+};
diff --git a/src/components/Modals/ProfileUpdateModal.tsx b/src/components/Modals/ProfileUpdateModal.tsx
index b36d960..7ff4dc4 100644
--- a/src/components/Modals/ProfileUpdateModal.tsx
+++ b/src/components/Modals/ProfileUpdateModal.tsx
@@ -1,11 +1,13 @@
import { zodResolver } from "@hookform/resolvers/zod";
import { useMutation } from "@tanstack/react-query";
-import { useRef } from "react";
+import { useParams } from "next/navigation";
+import { useEffect, useMemo, useRef } from "react";
import { useForm } from "react-hook-form";
import { toast } from "react-hot-toast";
import { editProfileAction } from "@/actions/profileActions";
import { Modal, ModalFooter } from "@/components/Common";
import { ProfileForm } from "@/components/Forms/Profile/ProfileForm";
+import { COUNTRIES } from "@/utils/countries";
import { UpdateProfileSchema } from "@/utils/schemas";
import { ListingUser, UpdateProfileReq } from "@/utils/types";
@@ -18,28 +20,43 @@ interface Props {
export const ProfileUpdateModal = (props: Props) => {
const { userData, visible, setVisible = () => {}, onSuccess = () => {} } = props;
+ const params = useParams();
const toastId = useRef
();
- const form = useForm({
- resolver: zodResolver(UpdateProfileSchema),
- defaultValues: {
+ const defaultValues = useMemo(
+ () => ({
address: {
city: userData?.address?.city || "",
state: userData?.address?.state || "",
- country: userData?.address?.country || "LK",
+ country: userData?.address?.country ? COUNTRIES[userData?.address?.country]?.[0] : COUNTRIES[params.locale as string]?.[0],
postalCode: userData?.address?.postalCode || "",
},
isDealership: userData.isDealership,
- phoneNumber: userData.phone,
+ phoneNumber: userData?.phone,
userId: userData.userId,
- },
+ }),
+ [userData, params.locale],
+ );
+
+ const form = useForm({
+ resolver: zodResolver(UpdateProfileSchema),
+ defaultValues,
mode: "all",
});
+ const country = form.watch("address.country");
+ const countryCode = Object.keys(COUNTRIES).find((item) => COUNTRIES[item]?.[0] === country);
+
const { mutate: updateSubscriptionMutation, isLoading: isMutating } = useMutation(
async (formValues: UpdateProfileReq) => {
- return editProfileAction(formValues);
+ editProfileAction({
+ ...formValues,
+ address: {
+ ...formValues.address,
+ country: Object.keys(COUNTRIES).find((item) => COUNTRIES[item]?.[0] === country)!,
+ },
+ });
},
{
onSuccess,
@@ -58,26 +75,37 @@ export const ProfileUpdateModal = (props: Props) => {
},
);
+ useEffect(() => {
+ if (visible) {
+ form.reset(defaultValues);
+ }
+ }, [visible, form, defaultValues]);
+
return (
<>
-
-