Skip to content
Snippets Groups Projects
Commit 88ba3766 authored by Reinder Kraaij's avatar Reinder Kraaij :eye:
Browse files

Create,Edit

parent 0b7cbd1e
No related branches found
No related tags found
2 merge requests!1338Resolve TMSS-2950 "Front end only tweak reservations",!1334Resolve TMSS-2950
......@@ -512,9 +512,7 @@ export class ReservationCreate extends Component {
}
render() {
console.log( "Reservation at render",this.state.reservation)
if (this.state.redirect) {
if (this.state.redirect) {
return <Redirect to={{ pathname: this.state.redirect }}></Redirect>
}
const schema = this.state.paramsSchema;
......
......@@ -23,6 +23,7 @@ import { InputMask } from 'primereact/inputmask';
import UnitConverter from '../../utils/unit.converter';
import ParserUtility from '../../utils/parser.utility';
import FormActionbar from '../../components/FormActionbar';
import { MultiSelect } from 'primereact/multiselect';
export class ReservationEdit extends Component {
constructor(props) {
......@@ -112,7 +113,8 @@ export class ReservationEdit extends Component {
if (id) {
await ReservationService.getReservation(id)
.then(async (reservation) => {
if (reservation) {
if (reservation) {
console.log("retrieved reservation",reservation)
reservation.duration = reservation.duration || 0;
reservation.duration = UnitConverter.getSecsToDDHHmmss(reservation.duration); //this.secondsToHms(reservation.duration);
let reservationTemplate = this.reservationTemplates.find(reserTemplate => reserTemplate.id === reservation.specifications_template_id);
......@@ -120,7 +122,7 @@ export class ReservationEdit extends Component {
this.state.editorFunction();
}
// no project then allow to select project from dropdown list
this.hasProject = reservation.project ? true : false;
this.hasProject = reservation.projects?.length>0;
let schema = {
properties: {}
};
......@@ -128,8 +130,9 @@ export class ReservationEdit extends Component {
schema = reservationTemplate.schema;
schema = ParserUtility.updateReservationPropsOrder(schema, false);
}
let project = this.projects.find(project => project.name === reservation.project_id);
reservation['project'] = project ? project.name : null;
reservation['projects'] = reservation.projects_ids;
let strategyName = reservation.specifications_doc.activity.name;
let reservationStrategy = null;
if (strategyName) {
......@@ -420,10 +423,17 @@ export class ReservationEdit extends Component {
*/
async saveReservation() {
let reservation = this.state.reservation;
let project = this.projects.find(project => project.name === reservation.project);
const selectedProjectURLs = reservation.projects.map((selectedProject) => {
const matchingProject = this.projects.find((project) => project.name === selectedProject);
return matchingProject ? matchingProject.url : null;
});
reservation['start_time'] = moment(reservation['start_time']).format(UIConstants.CALENDAR_DATETIME_FORMAT);
reservation['stop_time'] = (reservation['stop_time'] && reservation['stop_time'] !== 'Invalid date') ? moment(reservation['stop_time']).format(UIConstants.CALENDAR_DATETIME_FORMAT) : null;
reservation['project'] = project ? project.url : null;
reservation['projects'] = selectedProjectURLs;
reservation['specifications_doc'] = this.paramsOutput;
reservation = await ReservationService.updateReservation(reservation);
if (reservation?.id) {
......@@ -438,6 +448,8 @@ export class ReservationEdit extends Component {
}
render() {
console.log("reservations",this.state.reservation)
if (this.state.redirect) {
return <Redirect to={{ pathname: this.state.redirect }}></Redirect>
}
......@@ -500,16 +512,16 @@ export class ReservationEdit extends Component {
<div className="p-field p-grid">
<label htmlFor="project" className="col-lg-2 col-md-2 col-sm-12">Project</label>
<div className="col-lg-3 col-md-3 col-sm-12" data-testid="project" >
<Dropdown inputId="project" optionLabel="name" optionValue="name"
tooltip="Project" tooltipOptions={this.tooltipOptions}
value={this.state.reservation.project}
<MultiSelect inputId="project" optionLabel="name" optionValue="name"
tooltip="Projects" tooltipOptions={this.tooltipOptions}
value={this.state.reservation.projects}
options={this.projects}
onChange={(e) => { this.setParams('project', e.value) }}
placeholder="Select Project"
disabled={this.hasProject}
onChange={(e) => { this.setParams('projects', e.value) }}
placeholder="Select Projects"
/>
<label className={(this.state.errors.project && this.state.touched.project) ? "error" : "info"}>
{(this.state.errors.project && this.state.touched.project) ? this.state.errors.project : "Select Project"}
<label className={(this.state.errors.projects && this.state.touched.projects) ? "error" : "info"}>
{(this.state.errors.projects && this.state.touched.projects) ? this.state.errors.projects : "Select Projects"}
</label>
</div>
</div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment