1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-18 07:52:23 +01:00

linted profile-custom-fields

This commit is contained in:
Sylvain 2022-06-21 14:10:51 +02:00
parent 00fb384ba5
commit 18aba05f25
4 changed files with 92 additions and 22 deletions

View File

@ -7,6 +7,7 @@ import { Loader } from '../base/loader';
import { IApplication } from '../../models/application'; import { IApplication } from '../../models/application';
import { ProfileCustomField } from '../../models/profile-custom-field'; import { ProfileCustomField } from '../../models/profile-custom-field';
import ProfileCustomFieldAPI from '../../api/profile-custom-field'; import ProfileCustomFieldAPI from '../../api/profile-custom-field';
import { FabButton } from '../base/fab-button';
declare const Application: IApplication; declare const Application: IApplication;
@ -31,6 +32,9 @@ export const ProfileCustomFieldsList: React.FC<ProfileCustomFieldsListProps> = (
}); });
}, []); }, []);
/**
* Save the new state of the given custom field to the API
*/
const saveProfileCustomField = (profileCustomField: ProfileCustomField) => { const saveProfileCustomField = (profileCustomField: ProfileCustomField) => {
ProfileCustomFieldAPI.update(profileCustomField).then(data => { ProfileCustomFieldAPI.update(profileCustomField).then(data => {
const newFields = profileCustomFields.map(f => { const newFields = profileCustomFields.map(f => {
@ -43,9 +47,9 @@ export const ProfileCustomFieldsList: React.FC<ProfileCustomFieldsListProps> = (
if (profileCustomFieldToEdit) { if (profileCustomFieldToEdit) {
setProfileCustomFieldToEdit(null); setProfileCustomFieldToEdit(null);
} }
onSuccess(t('app.admin.settings.account.organization_profile_custom_field_successfully_updated')); onSuccess(t('app.admin.settings.account.profile_custom_fields_list.field_successfully_updated'));
}).catch(err => { }).catch(err => {
onError(t('app.admin.settings.account.organization_profile_custom_field_unable_to_update') + err); onError(t('app.admin.settings.account.profile_custom_fields_list.unable_to_update') + err);
}); });
}; };
@ -63,12 +67,19 @@ export const ProfileCustomFieldsList: React.FC<ProfileCustomFieldsListProps> = (
}; };
}; };
/**
* Callback triggered when the user clicks on the 'edit field' button.
* Opens the edition form for the given custom field
*/
const editProfileCustomFieldLabel = (profileCustomField: ProfileCustomField) => { const editProfileCustomFieldLabel = (profileCustomField: ProfileCustomField) => {
return () => { return () => {
setProfileCustomFieldToEdit(_.clone(profileCustomField)); setProfileCustomFieldToEdit(_.clone(profileCustomField));
}; };
}; };
/**
* Callback triggered when the input "label" is changed: updates the according state
*/
const onChangeProfileCustomFieldLabel = (e: BaseSyntheticEvent) => { const onChangeProfileCustomFieldLabel = (e: BaseSyntheticEvent) => {
const { value } = e.target; const { value } = e.target;
setProfileCustomFieldToEdit({ setProfileCustomFieldToEdit({
@ -77,16 +88,22 @@ export const ProfileCustomFieldsList: React.FC<ProfileCustomFieldsListProps> = (
}); });
}; };
/**
* Save the currently edited custom field
*/
const saveProfileCustomFieldLabel = () => { const saveProfileCustomFieldLabel = () => {
saveProfileCustomField(profileCustomFieldToEdit); saveProfileCustomField(profileCustomFieldToEdit);
}; };
/**
* Closes the edition form for the currently edited custom field
*/
const cancelEditProfileCustomFieldLabel = () => { const cancelEditProfileCustomFieldLabel = () => {
setProfileCustomFieldToEdit(null); setProfileCustomFieldToEdit(null);
}; };
return ( return (
<table className="table profile-custom-fields-list"> <table className="profile-custom-fields-list">
<thead> <thead>
<tr> <tr>
<th style={{ width: '50%' }}></th> <th style={{ width: '50%' }}></th>
@ -101,31 +118,44 @@ export const ProfileCustomFieldsList: React.FC<ProfileCustomFieldsListProps> = (
<td> <td>
{profileCustomFieldToEdit?.id !== field.id && field.label} {profileCustomFieldToEdit?.id !== field.id && field.label}
{profileCustomFieldToEdit?.id !== field.id && ( {profileCustomFieldToEdit?.id !== field.id && (
<button className="btn btn-default edit-profile-custom-field-label m-r-xs pull-right" onClick={editProfileCustomFieldLabel(field)}> <FabButton className="edit-field-button" onClick={editProfileCustomFieldLabel(field)}>
<i className="fa fa-edit"></i> <i className="fa fa-edit"></i>
</button> </FabButton>
)} )}
{profileCustomFieldToEdit?.id === field.id && ( {profileCustomFieldToEdit?.id === field.id && (
<div> <div>
<input className="profile-custom-field-label-input" style={{ width: '80%', height: '38px' }} type="text" value={profileCustomFieldToEdit.label} onChange={onChangeProfileCustomFieldLabel} /> <input className="edit-field-label-input"
<span className="buttons pull-right"> type="text" value={profileCustomFieldToEdit.label}
<button className="btn btn-success save-profile-custom-field-label m-r-xs" onClick={saveProfileCustomFieldLabel}> onChange={onChangeProfileCustomFieldLabel} />
<span className="buttons">
<FabButton className="save-field-label" onClick={saveProfileCustomFieldLabel}>
<i className="fa fa-check"></i> <i className="fa fa-check"></i>
</button> </FabButton>
<button className="btn btn-default delete-profile-custom-field-label m-r-xs" onClick={cancelEditProfileCustomFieldLabel}> <FabButton className="cancel-field-edition" onClick={cancelEditProfileCustomFieldLabel}>
<i className="fa fa-ban"></i> <i className="fa fa-ban"></i>
</button> </FabButton>
</span> </span>
</div> </div>
)} )}
</td> </td>
<td> <td className="activated">
<label htmlFor="profile-custom-field-actived" className="control-label m-r">{t('app.admin.settings.account.organization_profile_custom_field.actived')}</label> <label htmlFor="profile-custom-field-actived">
<Switch checked={field.actived} id="profile-custom-field-actived" onChange={handleSwitchChanged(field, 'actived')} className="v-middle"></Switch> {t('app.admin.settings.account.profile_custom_fields_list.actived')}
</label>
<Switch checked={field.actived}
id="profile-custom-field-actived"
onChange={handleSwitchChanged(field, 'actived')}
className="switch"></Switch>
</td> </td>
<td> <td className="required">
<label htmlFor="profile-custom-field-required" className="control-label m-r">{t('app.admin.settings.account.organization_profile_custom_field.required')}</label> <label htmlFor="profile-custom-field-required">
<Switch checked={field.required} disabled={!field.actived} id="profile-custom-field-required" onChange={handleSwitchChanged(field, 'required')} className="v-middle"></Switch> {t('app.admin.settings.account.profile_custom_fields_list.required')}
</label>
<Switch checked={field.required}
disabled={!field.actived}
id="profile-custom-field-required"
onChange={handleSwitchChanged(field, 'required')}
className="switch"></Switch>
</td> </td>
</tr> </tr>
); );

View File

@ -75,6 +75,7 @@
@import "modules/pricing/spaces/spaces-pricing"; @import "modules/pricing/spaces/spaces-pricing";
@import "modules/profile-completion/completion-header-info"; @import "modules/profile-completion/completion-header-info";
@import "modules/profile-completion/profile-form-option"; @import "modules/profile-completion/profile-form-option";
@import "modules/profile-custom-fields/profile-custom-fields-list";
@import "modules/select-gateway-modal"; @import "modules/select-gateway-modal";
@import "modules/settings/boolean-setting"; @import "modules/settings/boolean-setting";
@import "modules/settings/check-list-setting"; @import "modules/settings/check-list-setting";

View File

@ -0,0 +1,39 @@
.profile-custom-fields-list {
width: 100%;
margin-bottom: 20px;
.edit-field-button {
margin-right: 5px;
float: right;
}
.edit-field-label-input {
width: 80%;
height: 38px;
}
.buttons {
float: right;
.save-field-label {
color: #ffffff;
background-color: #5cb85c;
border-color: #4cae4c;
margin-right: 5px;
}
.cancel-field-edition {
margin-right: 5px;
}
}
td.activated > label,
td.required > label {
margin-right: 15px;
}
td.activated > .switch,
td.required > .switch {
vertical-align: middle;
}
}

View File

@ -1566,11 +1566,11 @@ en:
organization: "Organization" organization: "Organization"
organization_profile_custom_fields_info: "You can display additional fields for users who declare themselves to be an organization. You can also choose to make them mandatory at account creation." organization_profile_custom_fields_info: "You can display additional fields for users who declare themselves to be an organization. You can also choose to make them mandatory at account creation."
organization_profile_custom_fields_alert: "Attention: the activated fields will be automatically displayed on the issued invoices. Once configured, please do not modify them." organization_profile_custom_fields_alert: "Attention: the activated fields will be automatically displayed on the issued invoices. Once configured, please do not modify them."
organization_profile_custom_field: profile_custom_fields_list:
required: "Confirmation required" field_successfully_updated: "The organization field has been updated."
actived: "Activate the field" unable_to_update: "Impossible to modify the field : "
organization_profile_custom_field_successfully_updated: "The organization field has been updated." required: "Confirmation required"
organization_profile_custom_field_unable_to_update: "Impossible to modify the field : " actived: "Activate the field"
home: home:
show_upcoming_events: "Show upcoming events" show_upcoming_events: "Show upcoming events"
upcoming_events: upcoming_events: