From 2648f4f0020f5f457e48e76e4a1e41d19958bbe2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 9 Feb 2026 08:24:31 +0000 Subject: [PATCH] Refactor create user validation into useMemo for better readability Co-authored-by: cadtoolbox <12723486+cadtoolbox@users.noreply.github.com> --- frontend/src/pages/UsersPage.tsx | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/frontend/src/pages/UsersPage.tsx b/frontend/src/pages/UsersPage.tsx index 2415e90b6..470ab27d8 100644 --- a/frontend/src/pages/UsersPage.tsx +++ b/frontend/src/pages/UsersPage.tsx @@ -1,4 +1,4 @@ -import { useState, useEffect } from 'react'; +import { useState, useEffect, useMemo } from 'react'; import { useNavigate } from 'react-router-dom'; import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; import { useTranslation } from 'react-i18next'; @@ -123,6 +123,26 @@ export function UsersPage() { }, }); + // Validation for create user button + const isCreateButtonDisabled = useMemo(() => { + if (createMutation.isPending || !formData.username) { + return true; + } + if (advancedAuthStatus?.advanced_auth_enabled) { + // When advanced auth is enabled, require email (password is auto-generated) + return !formData.email; + } + // When advanced auth is disabled, require valid password + return !formData.password || formData.password !== formData.confirmPassword || formData.password.length < 6; + }, [ + createMutation.isPending, + formData.username, + formData.email, + formData.password, + formData.confirmPassword, + advancedAuthStatus?.advanced_auth_enabled + ]); + const handleCreate = () => { // Use the status from the query hook const advancedAuthEnabled = advancedAuthStatus?.advanced_auth_enabled || false; @@ -527,7 +547,7 @@ export function UsersPage() {