feat(reset-password): implement reset password functionality for admins and customers

- Added new ResetPasswordModalContent component for displaying generated passwords.
- Integrated reset password functionality in the AdminsTable and CustomersTable components, allowing users to reset passwords for admins and customers.
- Created useResetPasswordModalPresenter hook to manage password visibility and clipboard copying.
- Updated API services and hooks to support reset password requests for both admins and customers.
- Enhanced tooltip functionality for reset password actions in the tables.
This commit is contained in:
AmirReza Jamali
2026-05-30 12:09:57 +03:30
parent 746107e977
commit 5ef0298840
16 changed files with 480 additions and 9 deletions
@@ -5,6 +5,7 @@ import {
useCompanyFullList,
useCustomersQuery,
useDeleteCustomerQuery,
useResetCustomerPassword,
} from "@/hooks/queries";
import { useHybridPagination } from "@/hooks/useHybridPagination";
import { useTableSectionRowAnimations } from "@/hooks/useTableSectionRowAnimations";
@@ -27,6 +28,11 @@ const useCustomerListPresenter = () => {
);
const [isModalOpen, setIsModalOpen] = useState(false);
const [isResetPasswordModalOpen, setIsResetPasswordModalOpen] =
useState(false);
const [generatedPassword, setGeneratedPassword] = useState<string | null>(
null,
);
const pathName = usePathname();
const searchParams = useSearchParams();
const [params, setParams] = useState<Record<string, any>>({
@@ -90,6 +96,26 @@ const useCustomerListPresenter = () => {
},
);
const { mutate: resetCustomerPassword, isPending: isResettingPassword } =
useResetCustomerPassword({
successCallback: (password) => setGeneratedPassword(password),
});
const openResetPasswordModalForCustomer = useCallback(
(customer: TCustomer) => {
setCurrentCustomer(customer);
setGeneratedPassword(null);
setIsResetPasswordModalOpen(true);
resetCustomerPassword(customer.id);
},
[resetCustomerPassword],
);
const closeResetPasswordModal = useCallback(() => {
setIsResetPasswordModalOpen(false);
setGeneratedPassword(null);
}, []);
const search = (formData: any) => {
const newParams = buildFirstPageParams({ ...params, ...formData });
const cleanedParams = deleteEmptyKeys(newParams);
@@ -154,6 +180,11 @@ const useCustomerListPresenter = () => {
dataTbodyRef,
pagination,
handlePaginationChange,
isResetPasswordModalOpen,
closeResetPasswordModal,
openResetPasswordModalForCustomer,
generatedPassword,
isResettingPassword,
};
};