if (query.id) {
if (query.id !== 'new') {
const dietId = parseInt(query.id, 10);
const matchedDiet = AllDiets.data.find((findDiet) => findDiet.dietId === dietId);
if (!matchedDiet) {
return {
Animals: AllAnimals.data,
DeliveryContainers: AllDeliveryContainers.data,
Diets: AllDiets.data,
FoodPrepTables: AllFoodPrepTables.data,
LifeStages: AllLifeStages.data,
Species: AllSpecies.data,
Subenclosures: AllSubenclosures.data,
Foods: AllFoods.data,
Units: AllUnits.data,
Users: AllUsers.data,
serverError: 'Diet in URL could not be found.',
};
}
const serverMatchedDietQuery = { where: { dietId } };
const [matchedCaseNotes, matchedDietChanges, matchedDietHistory, matchedDietPlans, matchedPrepNotes] = await Promise.all([
serverCaseNotesAPI.getCaseNotes(serverMatchedDietQuery),
serverDietChangesAPI.getDietChanges(serverMatchedDietQuery),
serverDietHistoryAPI.getDietHistories(serverMatchedDietQuery),
serverDietPlansAPI.getDietPlans(serverMatchedDietQuery),
serverPrepNotesAPI.getPrepNotes(serverMatchedDietQuery),
]);
return {
Animals: AllAnimals.data,
CaseNotes: matchedCaseNotes.data,
DeliveryContainers: AllDeliveryContainers.data,
DietChanges: matchedDietChanges.data,
DietHistory: matchedDietHistory.data,
DietPlans: matchedDietPlans.data,
oldDietPlan: matchedDietPlans.data,
Diets: AllDiets.data,
FoodPrepTables: AllFoodPrepTables.data,
LifeStages: AllLifeStages.data,
PrepNotes: matchedPrepNotes.data,
Species: AllSpecies.data,
Subenclosures: AllSubenclosures.data,
Foods: AllFoods.data,
Units: AllUnits.data,
Users: AllUsers.data,
selectedDiet: matchedDiet,
};
}
return {
Animals: AllAnimals.data,
DeliveryContainers: AllDeliveryContainers.data,
Diets: AllDiets.data,
FoodPrepTables: AllFoodPrepTables.data,
LifeStages: AllLifeStages.data,
Species: AllSpecies.data,
Subenclosures: AllSubenclosures.data,
Foods: AllFoods.data,
Units: AllUnits.data,
Users: AllUsers.data,
new: true,
};
}
return {
Animals: AllAnimals.data,
DeliveryContainers: AllDeliveryContainers.data,
Diets: AllDiets.data,
FoodPrepTables: AllFoodPrepTables.data,
LifeStages: AllLifeStages.data,
Species: AllSpecies.data,
Subenclosures: AllSubenclosures.data,
Foods: AllFoods.data,
Units: AllUnits.data,
Users: AllUsers.data,
};
}
constructor(props) {
super(props);
let editDisabled = false;
if (this.props.account && this.props.account.role) {
const { role } = this.props.account;
if (role !== Roles.ADMIN && role !== Roles.NUTRITIONIST) {
editDisabled = true;
}
}
this.state = {
newDietOpen: props.new,
dietSelectDialogOpen: !props.new && !props.selectedDiet,
dietDeleteDialogOpen: false,
Diets: props.Diets,
selectedDiet: props.selectedDiet || null,
dietChangeDialogOpen: false,