forked from trent_larson/crowd-funder-for-time-pwa
refactor(claims): extract offer fulfillment logic to utility function
Created extractOfferFulfillment utility in libs/util.ts to handle both array and single object cases for fulfills field. Updated ClaimView and ConfirmGiftView to use the shared utility, eliminating code duplication and improving maintainability.
This commit is contained in:
@@ -718,32 +718,9 @@ export default class ConfirmGiftView extends Vue {
|
||||
* Extract offer fulfillment information from the fulfills array
|
||||
*/
|
||||
private extractOfferFulfillment() {
|
||||
if (!this.giveDetails?.fullClaim?.fulfills) {
|
||||
this.giveDetailsOfferFulfillment = null;
|
||||
return;
|
||||
}
|
||||
|
||||
const fulfills = this.giveDetails.fullClaim.fulfills;
|
||||
|
||||
// Handle both array and single object cases
|
||||
let offerFulfill = null;
|
||||
|
||||
if (Array.isArray(fulfills)) {
|
||||
// Find the Offer in the fulfills array
|
||||
offerFulfill = fulfills.find((item) => item["@type"] === "Offer");
|
||||
} else if (fulfills["@type"] === "Offer") {
|
||||
// fulfills is a single Offer object
|
||||
offerFulfill = fulfills;
|
||||
}
|
||||
|
||||
if (offerFulfill) {
|
||||
this.giveDetailsOfferFulfillment = {
|
||||
offerHandleId: offerFulfill.identifier,
|
||||
offerType: offerFulfill["@type"],
|
||||
};
|
||||
} else {
|
||||
this.giveDetailsOfferFulfillment = null;
|
||||
}
|
||||
this.giveDetailsOfferFulfillment = libsUtil.extractOfferFulfillment(
|
||||
this.giveDetails?.fullClaim?.fulfills
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user