@@ -114,6 +114,42 @@ export default {
114
114
},
115
115
);
116
116
},
117
+ moveUpAppointmentType (appointmentTypeId ) {
118
+ const indexInArray = this .appointmentTypes .findIndex ((appointmentType ) => (appointmentType .id === appointmentTypeId));
119
+ if (indexInArray === 0 ) {
120
+ toast .error (' This is the first appointment type' , {timeout: 2000 });
121
+ return ;
122
+ }
123
+ const appointmentTypeToMoveUp = this .appointmentTypes [indexInArray];
124
+ const appointmentTypeToMoveDown = this .appointmentTypes [indexInArray - 1 ];
125
+ requests .swapAppointmentTypes (appointmentTypeToMoveUp .id , appointmentTypeToMoveDown .id )
126
+ .then ((response ) => {
127
+ this .appointmentTypes .splice (indexInArray - 1 , 2 , response .data [0 ], response .data [1 ]);
128
+ this .appointmentTypes .sort ((a , b ) => (a .orderIndex - b .orderIndex ));
129
+ toast .success (' Appointment Type moved' , {timeout: 2000 });
130
+ })
131
+ .catch ((error ) => {
132
+ toast .error (error .response .data .detail .description , {timeout: 2000 });
133
+ });
134
+ },
135
+ moveDownAppointmentType (appointmentTypeId ) {
136
+ const indexInArray = this .appointmentTypes .findIndex ((appointmentType ) => (appointmentType .id === appointmentTypeId));
137
+ if (indexInArray === this .appointmentTypes .length - 1 ) {
138
+ toast .error (' This is the last appointment type' , {timeout: 2000 });
139
+ return ;
140
+ }
141
+ const appointmentTypeToMoveDown = this .appointmentTypes [indexInArray];
142
+ const appointmentTypeToMoveUp = this .appointmentTypes [indexInArray + 1 ];
143
+ requests .swapAppointmentTypes (appointmentTypeToMoveDown .id , appointmentTypeToMoveUp .id )
144
+ .then ((response ) => {
145
+ this .appointmentTypes .splice (indexInArray, 2 , response .data [0 ], response .data [1 ]);
146
+ this .appointmentTypes .sort ((a , b ) => (a .orderIndex - b .orderIndex ));
147
+ toast .success (' Appointment Type moved' , {timeout: 2000 });
148
+ })
149
+ .catch ((error ) => {
150
+ toast .error (error .response .data .detail .description , {timeout: 2000 });
151
+ });
152
+ },
117
153
patchAppointmentType (appointmentTypeId , patchData ) {
118
154
requests .patchAppointmentType (appointmentTypeId, patchData)
119
155
.then ((response ) => {
@@ -136,6 +172,16 @@ export default {
136
172
icon: ' heroicons-outline:pencil-square' ,
137
173
func: this .openEditAppointmentTypeModal ,
138
174
},
175
+ {
176
+ label: ' Move Up' ,
177
+ icon: ' heroicons-outline:arrow-up' ,
178
+ func: this .moveUpAppointmentType ,
179
+ },
180
+ {
181
+ label: ' Move Down' ,
182
+ icon: ' heroicons-outline:arrow-down' ,
183
+ func: this .moveDownAppointmentType ,
184
+ },
139
185
],
140
186
appointmentTypesColumns: [
141
187
{
@@ -167,7 +213,7 @@ export default {
167
213
},
168
214
created () {
169
215
requests .getAppointmentTypes (true ).then ((response ) => {
170
- this .appointmentTypes = response .data ;
216
+ this .appointmentTypes = response .data . sort (( a , b ) => ( a . orderIndex - b . orderIndex )) ;
171
217
this .loadingAppointmentTypes = false ;
172
218
});
173
219
},
0 commit comments