-
Notifications
You must be signed in to change notification settings - Fork 17
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
Fix subscriptions #2261
Fix subscriptions #2261
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,6 +118,7 @@ export const MyProducts: React.FC = () => { | |
userId={userId} | ||
product={product} | ||
onToggleSubscription={(userProduct) => { | ||
console.debug(userProduct); | ||
selectProduct(product, userProduct); | ||
toggle(); | ||
}} | ||
|
@@ -140,7 +141,7 @@ export const MyProducts: React.FC = () => { | |
{products | ||
.filter((product) => | ||
// products which the user *IS NOT* unsubscribed to | ||
product.subscribers.some( | ||
product.subscribers.every( | ||
(s) => | ||
!s.isSubscribed && s.status !== ProductRequestStatusName.RequestSubscription, | ||
), | ||
|
@@ -152,6 +153,7 @@ export const MyProducts: React.FC = () => { | |
userId={userInfo?.id} | ||
product={product} | ||
onToggleSubscription={(userProduct) => { | ||
console.debug(userProduct); | ||
selectProduct(product, userProduct); | ||
toggle(); | ||
}} | ||
|
@@ -163,27 +165,11 @@ export const MyProducts: React.FC = () => { | |
</PageSection> | ||
<Modal | ||
headerText={`Confirm change`} | ||
body={ | ||
(active?.userProduct.status === ProductRequestStatusName.RequestSubscription | ||
? `Are you sure you wish to ${ | ||
active.userProduct.isSubscribed ? 'unsubscribe from' : 'subscribe to' | ||
}` | ||
: `Are you sure you wish to cancel your pending request to ${ | ||
active?.userProduct.isSubscribed ? 'unsubscribe from' : 'subscribe to' | ||
}`) + `"${active?.product.name}"?` | ||
} | ||
body={active && modalBody(active)} | ||
isShowing={isShowing} | ||
hide={toggle} | ||
type="default" | ||
confirmText={ | ||
active?.userProduct.status === ProductRequestStatusName.RequestSubscription | ||
? `Yes, ${ | ||
active.userProduct.isSubscribed ? 'request to unsubscribe' : 'request to subscribe' | ||
}` | ||
: `Yes, cancel my pending request to ${ | ||
active?.userProduct.isSubscribed ? 'unsubscribe' : 'subscribe' | ||
}` | ||
} | ||
confirmText={active && modalConfirmText(active)} | ||
onConfirm={() => { | ||
if (active) handleToggleSubscription(active.product, active.userProduct); | ||
toggle(); | ||
|
@@ -192,3 +178,39 @@ export const MyProducts: React.FC = () => { | |
</styled.MyProducts> | ||
); | ||
}; | ||
|
||
const modalBody = (active: ISelectedProduct) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed text based on status. This all got messy due to distribution lists. |
||
if (active.userProduct.isSubscribed) { | ||
switch (active.userProduct.status) { | ||
case ProductRequestStatusName.RequestUnsubscribe: | ||
return `Are you sure you wish to unsubscribe to ${active.product.name}`; | ||
default: | ||
return `Are you sure you wish to cancel your pending request to unsubscribe to ${active.product.name}`; | ||
} | ||
} else { | ||
switch (active.userProduct.status) { | ||
case ProductRequestStatusName.RequestSubscription: | ||
return `Are you sure you wish to subscribe to ${active.product.name}`; | ||
default: | ||
return `Are you sure you wish to cancel your pending request to subscribe to ${active.product.name}`; | ||
} | ||
} | ||
}; | ||
|
||
const modalConfirmText = (active: ISelectedProduct) => { | ||
if (active.userProduct.isSubscribed) { | ||
switch (active.userProduct.status) { | ||
case ProductRequestStatusName.RequestUnsubscribe: | ||
return `Yes, request to unsubscribe`; | ||
default: | ||
return `Yes, cancel my pending request to unsubscribe`; | ||
} | ||
} else { | ||
switch (active.userProduct.status) { | ||
case ProductRequestStatusName.RequestSubscription: | ||
return `Yes, request to subscribe`; | ||
default: | ||
return `Yes, cancel my pending request to subscribe`; | ||
} | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,7 @@ public UserProductModel() { } | |
|
||
/// <summary> | ||
/// Creates a new instance of an UserProductModel, initializes with specified parameter. | ||
/// An assumption is made in this model. If a subscription exists for either the user or a distribution group, we assume the user is subscribed. | ||
/// </summary> | ||
/// <param name="entity"></param> | ||
public UserProductModel(Entities.UserProduct entity) : base(entity) | ||
|
@@ -109,15 +110,13 @@ public UserProductModel(Entities.UserProduct entity) : base(entity) | |
else if (entity.Product.ProductType == Entities.ProductType.Notification) | ||
{ | ||
var subscription = entity.User.NotificationSubscriptionsManyToMany | ||
.FirstOrDefault(s => s.UserId == entity.UserId && | ||
s.NotificationId == entity.Product!.TargetProductId); | ||
.FirstOrDefault(s => s.IsSubscribed && s.NotificationId == entity.Product!.TargetProductId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't love this, but since a user can be subscribed through a distribution list it's currently necessary. |
||
this.IsSubscribed = subscription?.IsSubscribed ?? false; | ||
} | ||
else if (entity.Product.ProductType == Entities.ProductType.EveningOverview) | ||
{ | ||
var subscription = entity.User.AVOverviewSubscriptionsManyToMany | ||
.FirstOrDefault(s => s.UserId == entity.UserId && | ||
(int)s.TemplateType == entity.Product!.TargetProductId); | ||
.FirstOrDefault(s => s.IsSubscribed && (int)s.TemplateType == entity.Product!.TargetProductId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't love this, but since a user can be subscribed through a distribution list it's currently necessary. |
||
this.IsSubscribed = subscription?.IsSubscribed ?? false; | ||
this.SendTo = subscription?.SendTo; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a warning as the code will take a lot longer to write.