fix(auth, customers): Refresh page on logout and rename form field

This commit introduces two main improvements: ensuring a clean state after user logout and enhancing the clarity of the customer creation form.

The logout function in the `UserContext` now calls `router.refresh()`. This forces a page reload, preventing the user from seeing stale, authenticated data after logging out.

Additionally, the form field for assigning companies to a customer has been renamed from `company_ids` to `companies` in both the form component and the Zod validation schema. This refactoring improves code clarity and consistency. A related `console.log` statement was also removed.
This commit is contained in:
AmirReza Jamali
2025-09-21 09:58:27 +03:30
parent 17ef40eed7
commit b8175e3b63
5 changed files with 10 additions and 11 deletions
@@ -110,7 +110,6 @@ export function UserInfo() {
onClick={() => { onClick={() => {
setIsOpen(false); setIsOpen(false);
logout(); logout();
}} }}
> >
<LogOutIcon /> <LogOutIcon />
@@ -63,7 +63,7 @@ const CreateCustomer = ({ defaultValues, editMode, id }: IProps) => {
: [] : []
} }
placeholder="Select companies to assign" placeholder="Select companies to assign"
{...register("company_ids", { {...register("companies", {
required: "Please select at least one interest", required: "Please select at least one interest",
})} })}
errors={errors} errors={errors}
@@ -41,7 +41,6 @@ const useCreateCustomerPresenter = ({
credentials: data, credentials: data,
}); });
} else { } else {
console.log(data.company_ids);
createCustomer({ createCustomer({
...data, ...data,
+8 -7
View File
@@ -1,20 +1,20 @@
"use client"; "use client";
import Cookies from "js-cookie";
import React, { import React, {
createContext, createContext,
useState, ReactNode,
useCallback,
useContext, useContext,
useEffect, useEffect,
useCallback,
useMemo, useMemo,
ReactNode, useState,
} from "react"; } from "react";
import Cookies from "js-cookie";
import { z } from "zod";
import { UserSchema, ILoginResponse } from "../lib/api/types";
import { COOKIE_KEYS } from "../lib/shared/cookies";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
import { z } from "zod";
import { ILoginResponse, UserSchema } from "../lib/api/types";
import { COOKIE_KEYS } from "../lib/shared/cookies";
type User = z.infer<typeof UserSchema>; type User = z.infer<typeof UserSchema>;
@@ -77,6 +77,7 @@ export const UserProvider: React.FC<UserProviderProps> = ({ children }) => {
Cookies.remove(COOKIE_KEYS.access_token); Cookies.remove(COOKIE_KEYS.access_token);
Cookies.remove(COOKIE_KEYS.refresh_token); Cookies.remove(COOKIE_KEYS.refresh_token);
Cookies.remove(COOKIE_KEYS.user); Cookies.remove(COOKIE_KEYS.user);
router.refresh();
}, []); }, []);
const value = useMemo( const value = useMemo(
+1 -1
View File
@@ -48,7 +48,7 @@ const createCustomerCredentials = z.object({
.optional(), .optional(),
annual_revenue: z.number().min(0).max(999999999999).optional(), annual_revenue: z.number().min(0).max(999999999999).optional(),
business_type: z.string().min(2).max(100).optional(), business_type: z.string().min(2).max(100).optional(),
company_ids: z.array(z.string()).optional(), companies: z.array(z.string()).optional(),
contact_person: z contact_person: z
.object({ .object({
email: z.string(), email: z.string(),