Commit b3899bcf authored by Alex Kakiris's avatar Alex Kakiris
Browse files

Reset create user form after successfull creation

parent aa1d54fe
Loading
Loading
Loading
Loading
+13 −8
Original line number Diff line number Diff line
@@ -35,6 +35,15 @@ const LinkStyled = styled(Link)(({ theme }) => ({
  color: theme.palette.primary.main,
}));

const EMPTY_USER = {
  username: '',
  password: '',
  enterprise: '',
  country: '',
  email: '',
  purpose: ''
};

const Users = () => {
  const queryClient = useQueryClient();
  const [selectedUsers, setSelectedUsers] = useState([]);
@@ -57,14 +66,7 @@ const Users = () => {
  const [isCreating, setIsCreating] = useState(false);
  const [isCreateDialogOpen, setCreateDialogOpen] = useState(false);
  
  const [userCreate, setUserCreate] = useState({
    username: '',
    password: '',
    enterprise: '',
    country: '',
    email: '',
    purpose: ''
  });
  const [userCreate, setUserCreate] = useState(EMPTY_USER);
  const [showCreateMessage, setShowCreateMessage] = useState(false);
  const [errorCreating, setErrorCreating] = useState(false);

@@ -183,9 +185,11 @@ const Users = () => {
    try {
      setIsCreating(true);
      setErrorCreating(false);

      await createUser(userCreate);
      await refetch(); // Refetch the users after creation
      setCreateDialogOpen(false);
      setUserCreate(EMPTY_USER); // Reset the form
      setShowCreateMessage(true);
    } catch (error) {
      setErrorCreating(true);
@@ -196,6 +200,7 @@ const Users = () => {

  const handleCreateCancel = () => {
    setCreateDialogOpen(false);
    setUserCreate(EMPTY_USER); // Reset the form on cancel
  };

  const handleCreateMessageAccept = () => {