Skip to content

Commit 8f7b28c

Browse files
author
Brijesh
committed
Newly created plan not displayed
When creating a new plan attachments are not provided which was causing problem loading the plan.
1 parent 2718b08 commit 8f7b28c

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

src/api/plan.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,14 @@ export const savePlan = async (plan, user = {}) => {
109109
await saveMinisterIssues(planId, ministerIssues, newPastures);
110110
await saveAdditionalRequirements(planId, additionalRequirements);
111111

112-
// Only save attachments that haven't been saved individually
113-
// (attachments with UUID ids haven't been saved to database yet)
114-
if ((isUserAgrologist(user) && canUserAddAttachments(plan, user)) || isUserAdmin(user)) {
115-
const unsavedAttachments = files.filter((file) => uuid.isUUID(file.id));
116-
if (unsavedAttachments.length > 0) {
117-
await saveAttachments(planId, unsavedAttachments);
112+
if (files && files.length > 0) {
113+
// Only save attachments that haven't been saved individually
114+
// (attachments with UUID ids haven't been saved to database yet)
115+
if ((isUserAgrologist(user) && canUserAddAttachments(plan, user)) || isUserAdmin(user)) {
116+
const unsavedAttachments = files.filter((file) => uuid.isUUID(file.id));
117+
if (unsavedAttachments.length > 0) {
118+
await saveAttachments(planId, unsavedAttachments);
119+
}
118120
}
119121
}
120122

src/providers/PlanProvider.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,14 @@ export const PlanProvider = ({ children, storePlan }) => {
7878
const savePlan = async (plan) => {
7979
try {
8080
setSavingPlan(true);
81-
82-
const planId = await API.savePlan(plan, user);
83-
await fetchPlan(planId);
81+
let planId;
82+
try {
83+
planId = await API.savePlan(plan, user);
84+
await fetchPlan(planId);
85+
} catch (e) {
86+
console.error('Error saving plan:', e);
87+
throw e;
88+
}
8489

8590
return planId;
8691
} catch (e) {

src/utils/helper/plan.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@ export const getPlanTypeDescription = (plan = {}, amendmentTypes) => {
2929
};
3030

3131
export const scrollIntoView = (elementId) => {
32-
document.getElementById(elementId).scrollIntoView({
33-
behavior: 'smooth',
34-
block: 'start',
35-
inline: 'nearest',
36-
});
32+
const element = document.getElementById(elementId);
33+
if (element) {
34+
element.scrollIntoView({
35+
behavior: 'smooth',
36+
block: 'start',
37+
inline: 'nearest',
38+
});
39+
}
3740
};
3841

3942
// for plans extending past agreement date, extend usage

0 commit comments

Comments
 (0)