Skip to content

Commit

Permalink
license bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
albertfolch-redeemeum committed Apr 29, 2024
1 parent 3bfaffa commit 6fb56a9
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/lib/routing/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const BosonRoutes = addViewModePrefixToPaths(
SellerPage: `/seller/:${UrlParameters.sellerId}`,
LicenseLegacy: `/license/:${UrlParameters.uuid}`,
License: `/license/:${UrlParameters.sellerId}/:${UrlParameters.uuid}`,
LicenseBundle: `/license-bundle/:${UrlParameters.sellerId}/:${UrlParameters.uuid}`,
ContractualAgreement: `/contractualAgreement/:${UrlParameters.offerId}`,
DRAdmin: "/dr-admin",
DRAdminPage: `/dr-admin/:${UrlParameters.disputeResolverPageId}`,
Expand Down
8 changes: 6 additions & 2 deletions src/pages/create-product/CreateProductInner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,12 @@ function CreateProductInner({
const offerLicenseUrl = currentAssistant
? `${window.origin}/#/license/${currentAssistant.id}/${offerUuid}`
: `${window.origin}/#/license/${offerUuid}`;
const bundleExternalUrl = offerExternalUrl;
const bundleLicenseUrl = offerLicenseUrl;
const bundleExternalUrl = currentAssistant
? `${redemptionPointUrl}/#/bundles/${currentAssistant.id}/${bundleUuid}`
: `${redemptionPointUrl}/#/bundles/${bundleUuid}`;
const bundleLicenseUrl = currentAssistant
? `${redemptionPointUrl}/#/license-bundle/${currentAssistant.id}/${bundleUuid}`
: `${redemptionPointUrl}/#/license-bundle/${bundleUuid}`;

const offersToCreate: offers.CreateOfferArgs[] = [];
const productAnimation = values.productAnimation?.[0];
Expand Down
98 changes: 98 additions & 0 deletions src/pages/license/LicenseBundle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { hooks } from "@bosonprotocol/react-kit";
import { EmptyErrorMessage } from "components/error/EmptyErrorMessage";
import { isTruthy } from "lib/types/helpers";
import { getProductV1BundleItemsFilter } from "lib/utils/bundle/filter";
import { useCoreSDK } from "lib/utils/useCoreSdk";
import { VariantV1 } from "pages/products/types";
import { useMemo } from "react";
import { useParams } from "react-router-dom";
import styled from "styled-components";

import { LinkWithQuery } from "../../components/customNavigation/LinkWithQuery";
import LicenseComponent from "../../components/license/License";
import { Typography } from "../../components/ui/Typography";
import { UrlParameters } from "../../lib/routing/parameters";
import { BosonRoutes } from "../../lib/routing/routes";

const Container = styled.div`
display: block;
overflow: auto;
`;

export default function LicenseBundle() {
const { [UrlParameters.uuid]: uuid, [UrlParameters.sellerId]: sellerId } =
useParams();

// Note: ideally the license is referring to the tNFT token; However, the
// token only exists after a commit and the token metadata are built just
// before the offer creation. So, here we are referring to an offer
// identified by its uuid and sellerId (offerId is not even known before the offer is
// created)

const { data: bundleResult } = hooks.useBundleByUuid(
sellerId,
uuid,
useCoreSDK()
);
const variantsWithV1: VariantV1[] | undefined = useMemo(
() =>
bundleResult
?.flatMap((bundle) => {
const bundleItems = bundle.items;
const productV1Items = bundleItems
? getProductV1BundleItemsFilter(bundleItems)
: undefined;
if (!productV1Items) {
return null;
}
return productV1Items.map(
(productV1Item) =>
({
variations: productV1Item.variations,
offer: bundle.offer
}) as VariantV1
);
})
.filter(isTruthy),
[bundleResult]
);

const defaultVariant: VariantV1 | undefined =
variantsWithV1?.find((variant) => !variant.offer.voided) ??
variantsWithV1?.[0];
const offer = defaultVariant?.offer;
const offerId = offer?.id;
if (!offerId) {
return (
<EmptyErrorMessage
title="Not found"
message="This bundle does not exist"
/>
);
}

return (
<>
<Container>
<LicenseComponent
offerId={offerId}
offerData={undefined}
></LicenseComponent>
</Container>
<Typography tag="p">
Click&nbsp;
<LinkWithQuery
to={BosonRoutes.ContractualAgreement.replace(
`:${UrlParameters.offerId}`,
offerId
)}
target="_blank"
rel="noopener noreferrer"
>
{"here"}
</LinkWithQuery>
&nbsp;{"to read the Buyer & Seller Agreement"}
</Typography>
</>
);
}
6 changes: 6 additions & 0 deletions src/router/dappRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const PrivateAccountPage = lazy(
);
const ProfilePagePage = lazy(() => import("../pages/profile/ProfilePage"));
const LicensePage = lazy(() => import("../pages/license/License"));
const LicenseBundlePage = lazy(() => import("../pages/license/LicenseBundle"));
const ContractualAgreementPage = lazy(
() => import("../pages/contractualAgreement/ContractualAgreement")
);
Expand Down Expand Up @@ -241,6 +242,11 @@ export default [
path: BosonRoutes.LicenseLegacy,
component: LicensePage
},
{
...base,
path: BosonRoutes.LicenseBundle,
component: LicenseBundlePage
},
{
...base,
path: BosonRoutes.ContractualAgreement,
Expand Down

0 comments on commit 6fb56a9

Please sign in to comment.