|
@@ -3,8 +3,6 @@ import { useTranslation } from 'react-i18next';
|
|
|
import dateFnsFormat from 'date-fns/format';
|
|
import dateFnsFormat from 'date-fns/format';
|
|
|
import { TFunctionResult } from 'i18next';
|
|
import { TFunctionResult } from 'i18next';
|
|
|
|
|
|
|
|
-import { withUnstatedContainers } from '../../UnstatedUtils';
|
|
|
|
|
-import AppContainer from '~/client/services/AppContainer';
|
|
|
|
|
import { IUserGroup, IUserGroupHasId } from '~/interfaces/user';
|
|
import { IUserGroup, IUserGroupHasId } from '~/interfaces/user';
|
|
|
import { CustomWindow } from '~/interfaces/global';
|
|
import { CustomWindow } from '~/interfaces/global';
|
|
|
import Xss from '~/services/xss';
|
|
import Xss from '~/services/xss';
|
|
@@ -20,12 +18,14 @@ const UserGroupForm: FC<Props> = (props: Props) => {
|
|
|
|
|
|
|
|
const { t } = useTranslation();
|
|
const { t } = useTranslation();
|
|
|
|
|
|
|
|
|
|
+ const { userGroup, submitButtonLabel, onSubmit } = props;
|
|
|
|
|
+
|
|
|
/*
|
|
/*
|
|
|
* State
|
|
* State
|
|
|
*/
|
|
*/
|
|
|
- const [currentName, setName] = useState(props.userGroup != null ? props.userGroup.name : '');
|
|
|
|
|
- const [currentDescription, setDescription] = useState(props.userGroup != null ? props.userGroup.description : '');
|
|
|
|
|
- const [currentParent, setParent] = useState(props.userGroup != null ? props.userGroup.parent : '');
|
|
|
|
|
|
|
+ const [currentName, setName] = useState(userGroup != null ? userGroup.name : '');
|
|
|
|
|
+ const [currentDescription, setDescription] = useState(userGroup != null ? userGroup.description : '');
|
|
|
|
|
+ const [currentParent, setParent] = useState(userGroup != null ? userGroup.parent : '');
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
|
* Function
|
|
* Function
|
|
@@ -41,12 +41,12 @@ const UserGroupForm: FC<Props> = (props: Props) => {
|
|
|
const onSubmitHandler = useCallback(async(e) => {
|
|
const onSubmitHandler = useCallback(async(e) => {
|
|
|
e.preventDefault(); // no reload
|
|
e.preventDefault(); // no reload
|
|
|
|
|
|
|
|
- if (props.onSubmit == null) {
|
|
|
|
|
|
|
+ if (onSubmit == null) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- await props.onSubmit({ name: currentName, description: currentDescription, parent: currentParent });
|
|
|
|
|
- }, [currentName, currentDescription, currentParent, props.onSubmit]);
|
|
|
|
|
|
|
+ await onSubmit({ name: currentName, description: currentDescription, parent: currentParent });
|
|
|
|
|
+ }, [currentName, currentDescription, currentParent, onSubmit]);
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<form onSubmit={onSubmitHandler}>
|
|
<form onSubmit={onSubmitHandler}>
|
|
@@ -55,10 +55,10 @@ const UserGroupForm: FC<Props> = (props: Props) => {
|
|
|
<h2 className="admin-setting-header">{t('admin:user_group_management.basic_info')}</h2>
|
|
<h2 className="admin-setting-header">{t('admin:user_group_management.basic_info')}</h2>
|
|
|
{/* TODO 85062: improve style */}
|
|
{/* TODO 85062: improve style */}
|
|
|
{
|
|
{
|
|
|
- props.userGroup?.createdAt != null && (
|
|
|
|
|
|
|
+ userGroup?.createdAt != null && (
|
|
|
<div className="form-group row">
|
|
<div className="form-group row">
|
|
|
<p className="col-md-2 col-form-label">{t('Created')}</p>
|
|
<p className="col-md-2 col-form-label">{t('Created')}</p>
|
|
|
- <p className="col-md-4 my-auto">{dateFnsFormat(new Date(props.userGroup.createdAt), 'yyyy-MM-dd')}</p>
|
|
|
|
|
|
|
+ <p className="col-md-4 my-auto">{dateFnsFormat(new Date(userGroup.createdAt), 'yyyy-MM-dd')}</p>
|
|
|
</div>
|
|
</div>
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
@@ -92,7 +92,7 @@ const UserGroupForm: FC<Props> = (props: Props) => {
|
|
|
<div className="form-group row">
|
|
<div className="form-group row">
|
|
|
<div className="offset-md-2 col-md-10">
|
|
<div className="offset-md-2 col-md-10">
|
|
|
<button type="submit" className="btn btn-primary">
|
|
<button type="submit" className="btn btn-primary">
|
|
|
- {props.submitButtonLabel}
|
|
|
|
|
|
|
+ {submitButtonLabel}
|
|
|
</button>
|
|
</button>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
@@ -101,9 +101,4 @@ const UserGroupForm: FC<Props> = (props: Props) => {
|
|
|
);
|
|
);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-/**
|
|
|
|
|
- * Wrapper component for using unstated
|
|
|
|
|
- */
|
|
|
|
|
-const UserGroupFormWrapper = withUnstatedContainers<unknown, Props>(UserGroupForm, [AppContainer]);
|
|
|
|
|
-
|
|
|
|
|
-export default UserGroupFormWrapper;
|
|
|
|
|
|
|
+export default UserGroupForm;
|