-
Notifications
You must be signed in to change notification settings - Fork 334
FUI - Product Subscriptions list #2510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/components/products/product-subscriptions/ko/productSubscriptions.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
<!-- ko if: isRedesignEnabled --> | ||
<fui-product-subscriptions-runtime></fui-product-subscriptions-runtime> | ||
<!-- /ko --> | ||
|
||
<!-- ko ifnot: isRedesignEnabled --> | ||
<product-subscriptions-runtime></product-subscriptions-runtime> | ||
<!-- /ko --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/components/products/product-subscriptions/productSubscriptions.runtime.module.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { IInjector, IInjectorModule } from "@paperbits/common/injection"; | ||
import { ProductSubscriptionsRuntime } from "./react/ProductSubscriptionsRuntime"; | ||
import { registerCustomElement } from "@paperbits/react/customElements"; | ||
|
||
export class ProductSubscriptionsRuntimeModule implements IInjectorModule { | ||
public register(injector: IInjector): void { | ||
injector.bind("productSubscriptionsRuntime", ProductSubscriptionsRuntime); | ||
registerCustomElement(ProductSubscriptionsRuntime, "fui-product-subscriptions-runtime", injector); | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
src/components/products/product-subscriptions/react/ProductSubscriptionsRuntime.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import * as React from "react"; | ||
import { useEffect, useState } from "react"; | ||
import { FluentProvider } from "@fluentui/react-components"; | ||
import { Resolve } from "@paperbits/react/decorators"; | ||
import { Router } from "@paperbits/common/routing"; | ||
import * as Constants from "../../../../constants"; | ||
import { RouteHelper } from "../../../../routing/routeHelper"; | ||
import { UsersService } from "../../../../services"; | ||
import { ProductService } from "../../../../services/productService"; | ||
import { Subscription } from "../../../../models/subscription"; | ||
import { ProductSubscriptionsTable } from "./ProductSubscriptionsTable"; | ||
|
||
type ProductSubscriptionsProps = {} | ||
type ProductSubscriptionsFCProps = ProductSubscriptionsProps & { | ||
usersService: UsersService; | ||
productService: ProductService; | ||
productName: string; | ||
}; | ||
|
||
const loadSubscriptions = async (usersService: UsersService, productService: ProductService, productName: string) => { | ||
const userId = await usersService.getCurrentUserId(); | ||
const { value: subscriptions } = | ||
await productService.getSubscriptionsForProduct(userId, `/products/${productName}`); | ||
|
||
return { userId, subscriptions }; | ||
}; | ||
|
||
const ProductSubscriptionsRuntimeFC = ({ usersService, productService, productName }: ProductSubscriptionsFCProps) => { | ||
const [working, setWorking] = useState(false); | ||
const [subscriptions, setSubscriptions] = useState<Subscription[]>(); | ||
|
||
useEffect(() => { | ||
setWorking(true); | ||
loadSubscriptions(usersService, productService, productName) | ||
.then(({ subscriptions }) => setSubscriptions(subscriptions)) | ||
.catch((error) => { | ||
if (error.code === "Unauthorized") { | ||
usersService.navigateToSignin(); | ||
return; | ||
} | ||
// TODO better error handling & logging | ||
if (error.code === "ResourceNotFound") return; | ||
|
||
throw new Error(`Could not load product subscriptions. Error: ${error.message}`); | ||
}) | ||
.finally(() => setWorking(false)); | ||
}, [usersService, productService, productName]); | ||
|
||
return <ProductSubscriptionsTable subscriptions={subscriptions} working={working} />; | ||
}; | ||
|
||
export class ProductSubscriptionsRuntime extends React.Component< | ||
ProductSubscriptionsProps, | ||
{ productName?: string | null } | ||
> { | ||
@Resolve("usersService") | ||
public usersService: UsersService; | ||
|
||
@Resolve("productService") | ||
public productService: ProductService; | ||
|
||
@Resolve("routeHelper") | ||
public routeHelper: RouteHelper; | ||
|
||
@Resolve("router") | ||
public router: Router; | ||
|
||
constructor(props: ProductSubscriptionsProps) { | ||
super(props); | ||
|
||
this.state = { productName: undefined }; | ||
} | ||
|
||
componentDidMount() { | ||
this.setProductName(); | ||
this.router.addRouteChangeListener(this.setProductName.bind(this)); | ||
} | ||
|
||
componentWillUnmount() { | ||
this.router.removeRouteChangeListener(this.setProductName.bind(this)); | ||
} | ||
|
||
setProductName() { | ||
this.setState({ productName: this.routeHelper.getProductName() }); | ||
} | ||
|
||
render() { | ||
if (!this.state.productName) return <>Please select a product</>; | ||
jsorohova marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return ( | ||
<FluentProvider theme={Constants.fuiTheme}> | ||
<ProductSubscriptionsRuntimeFC | ||
{...this.props} | ||
usersService={this.usersService} | ||
productService={this.productService} | ||
productName={this.state.productName} | ||
/> | ||
</FluentProvider> | ||
); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/components/products/product-subscriptions/react/ProductSubscriptionsTable.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import * as React from "react"; | ||
import { | ||
Body1Strong, | ||
Spinner, | ||
Table, | ||
TableBody, | ||
TableCell, | ||
TableHeader, | ||
TableHeaderCell, | ||
TableRow, | ||
} from "@fluentui/react-components"; | ||
import { Subscription } from "../../../../models/subscription"; | ||
|
||
export const ProductSubscriptionsTable = ({ | ||
subscriptions, | ||
working, | ||
}: { | ||
subscriptions: Subscription[]; | ||
working: boolean; | ||
}) => | ||
working ? ( | ||
<Spinner | ||
label="Loading Subsriptions" | ||
labelPosition="below" | ||
size="small" | ||
/> | ||
) : !subscriptions || subscriptions.length === 0 ? ( | ||
<Body1Strong>You don't have subscriptions yet.</Body1Strong> | ||
) : ( | ||
<Table className={"fui-table"} size={"small"} aria-label={"Your Subscriptions list"}> | ||
<TableHeader> | ||
<TableRow className={"fui-table-headerRow"}> | ||
<TableHeaderCell> | ||
<Body1Strong>Name</Body1Strong> | ||
</TableHeaderCell> | ||
<TableHeaderCell> | ||
<Body1Strong>Status</Body1Strong> | ||
</TableHeaderCell> | ||
</TableRow> | ||
</TableHeader> | ||
|
||
<TableBody> | ||
{subscriptions?.map((sub) => ( | ||
<TableRow key={sub.id}> | ||
<TableCell>{sub.name}</TableCell> | ||
<TableCell>{sub.state}</TableCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.