Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/components/Dialogs/CreateProjectDialogContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useRef } from 'react';
import { useCallback, useEffect, useRef } from 'react';
import { useApiResourceMutation } from '../../lib/api/useApiResource';
import { ErrorDialogHandle } from '../Shared/ErrorMessageBox.tsx';
import { APIError } from '../../lib/api/error';
Expand Down Expand Up @@ -33,7 +33,7 @@ export function CreateProjectDialogContainer({
const {
register,
handleSubmit,
reset,
resetField,
setValue,
formState: { errors },
watch,
Expand All @@ -51,16 +51,22 @@ export function CreateProjectDialogContainer({

const { t } = useTranslation();

const clearForm = useCallback(() => {
resetField('name');
resetField('chargingTarget');
resetField('displayName');
}, [resetField]);

useEffect(() => {
if (username) {
setValue('members', [
{ name: username, roles: [MemberRoles.admin], kind: 'User' },
]);
}
return () => {
reset();
};
}, []);
if (!isOpen) {
clearForm();
}
}, [resetField, setValue, username, isOpen, clearForm]);

const toast = useToast();

Expand Down
16 changes: 11 additions & 5 deletions src/components/Dialogs/CreateWorkspaceDialogContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useRef } from 'react';
import { useCallback, useEffect, useRef } from 'react';
import {
useApiResourceMutation,
useRevalidateApiResource,
Expand Down Expand Up @@ -61,13 +61,22 @@ export function CreateWorkspaceDialogContainer({

const { t } = useTranslation();

const clearForm = useCallback(() => {
resetField('name');
resetField('chargingTarget');
resetField('displayName');
}, [resetField]);

useEffect(() => {
if (username) {
setValue('members', [
{ name: username, roles: [MemberRoles.admin], kind: 'User' },
]);
}
}, [username]);
if (!isOpen) {
clearForm();
}
}, [resetField, setValue, username, isOpen, clearForm]);
const namespace = projectnameToNamespace(project);
const toast = useToast();

Expand All @@ -94,9 +103,6 @@ export function CreateWorkspaceDialogContainer({
await revalidate();
setIsOpen(false);
toast.show(t('CreateWorkspaceDialog.toastMessage'));
resetField('name');
resetField('chargingTarget');
resetField('displayName');
return true;
} catch (e) {
console.error(e);
Expand Down
5 changes: 5 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,9 @@ body {

ui5-form-item {
margin-bottom: 24px;
}

ui5-toast {
width: 50ch;
max-width: 100%;
}