Skip to content

Commit

Permalink
Merge pull request #3305 from LiteFarmOrg/LF-4221_2/Bug_fix_undefined…
Browse files Browse the repository at this point in the history
…_error_in_completion_flow

LF-4221 Update `formatSoilAmendmentTaskToFormStructure` to handle `FormSoilAmendmentTask type`
  • Loading branch information
kathyavini committed Jul 18, 2024
2 parents 7aca0f1 + 6bd490a commit c5fead3
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/webapp/src/util/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,20 @@ type FormSoilAmendmentTask = {
[key: string]: any;
};

// Type guard
function isFormSoilAmendmentTask(
task: DBSoilAmendmentTask | FormSoilAmendmentTask,
): task is FormSoilAmendmentTask {
return 'purposes' in task.soil_amendment_task_products[0];
}

export const formatSoilAmendmentTaskToFormStructure = (
task: DBSoilAmendmentTask,
task: DBSoilAmendmentTask | FormSoilAmendmentTask,
): FormSoilAmendmentTask => {
if (isFormSoilAmendmentTask(task)) {
return task as FormSoilAmendmentTask;
}

const taskClone = structuredClone(task);

const formattedTaskProducts = task.soil_amendment_task_products.map(
Expand Down

0 comments on commit c5fead3

Please sign in to comment.