147 lines
5.2 KiB
TypeScript
147 lines
5.2 KiB
TypeScript
// Metro module 12519 (f12520).
|
|
import SubscriptionStore from "../../../stores/billing/SubscriptionStore";
|
|
import { PremiumGroupAPIErrorCodes, TOTAL_PREMIUM_GROUP_MEMBER_SEATS } from "./PremiumGroupConstants";
|
|
import { NOOP_NULL } from "../../../Constants";
|
|
import Dispatcher from "../../../Dispatcher";
|
|
import { fetchSubscriptionGroupMembers, fetchPremiumGroupMembership } from "./PremiumGroupActionCreators";
|
|
import Module589 from "../../../_bundle/Module589";
|
|
let c8652_7;
|
|
const handleMutationStart = function handleMutationStart() {
|
|
c8652_7.membersData.isUpdating = true;
|
|
};
|
|
const handleMutationSuccess = function handleMutationSuccess({ subscriptionId }) {
|
|
Dispatcher.wait(() => fetchSubscriptionGroupMembers(subscriptionId).catch(NOOP_NULL));
|
|
c8652_7.membersData.isUpdating = false;
|
|
};
|
|
const handleMutationFailure = function handleMutationFailure() {
|
|
c8652_7.membersData.isUpdating = false;
|
|
};
|
|
c8652_7 = {
|
|
membersData: {
|
|
data: null,
|
|
isFetching: false,
|
|
isUpdating: false
|
|
},
|
|
membershipData: {
|
|
data: null,
|
|
isFetching: false,
|
|
hasFetched: false
|
|
}
|
|
};
|
|
class PremiumGroupStore extends Module589.Store {
|
|
static displayName = "PremiumGroupStore";
|
|
initialize() {
|
|
this.waitFor(SubscriptionStore);
|
|
}
|
|
getMembers() {
|
|
return c8652_7.membersData.data;
|
|
}
|
|
isFetchingMembers() {
|
|
return c8652_7.membersData.isFetching;
|
|
}
|
|
isUpdatingMembers() {
|
|
return c8652_7.membersData.isUpdating;
|
|
}
|
|
hasFetchedMembers() {
|
|
return c8652_7.membersData.data !== null;
|
|
}
|
|
getMembership() {
|
|
return c8652_7.membershipData.data;
|
|
}
|
|
isFetchingMembership() {
|
|
return c8652_7.membershipData.isFetching;
|
|
}
|
|
hasFetchedMembership() {
|
|
return c8652_7.membershipData.data !== null;
|
|
}
|
|
getNumUsedSeats() {
|
|
return c8652_7.membersData.data == null ? 0 : c8652_7.membersData.data.members.length;
|
|
}
|
|
getNumAvailableInvites() {
|
|
if (c8652_7.membersData.data == null) {
|
|
return TOTAL_PREMIUM_GROUP_MEMBER_SEATS;
|
|
}
|
|
return Math.max(0, TOTAL_PREMIUM_GROUP_MEMBER_SEATS - (c8652_7.membersData.data.members.length + c8652_7.membersData.data.invitedUsers.length));
|
|
}
|
|
getNumTotalSeats() {
|
|
return TOTAL_PREMIUM_GROUP_MEMBER_SEATS;
|
|
}
|
|
}
|
|
const premiumGroupStore = new PremiumGroupStore(Dispatcher, {
|
|
PREMIUM_GROUP_MEMBERS_REQUEST: function handleMembersRequest({ subscriptionId: subscriptionId2 }) {
|
|
const isFetching = c8652_7.membersData.isFetching;
|
|
let r0 = !isFetching;
|
|
if (!isFetching) {
|
|
Dispatcher.wait(() => fetchSubscriptionGroupMembers(subscriptionId2).catch(NOOP_NULL));
|
|
r0 = true;
|
|
}
|
|
return r0;
|
|
},
|
|
PREMIUM_GROUP_MEMBERS_FETCH_START: function handleMembersFetchStart() {
|
|
c8652_7.membersData.isFetching = true;
|
|
},
|
|
PREMIUM_GROUP_MEMBERS_FETCH_SUCCESS: function handleMembersFetchSuccess(a0) {
|
|
c8652_7.membersData.data = a0.members;
|
|
c8652_7.membersData.isFetching = false;
|
|
},
|
|
PREMIUM_GROUP_MEMBERS_FETCH_FAILURE: function handleMembersFetchFailure() {
|
|
c8652_7.membersData.isFetching = false;
|
|
},
|
|
PREMIUM_GROUP_MEMBERSHIP_REQUEST: function handleMembershipRequest() {
|
|
const isFetching = c8652_7.membershipData.isFetching;
|
|
let r0 = !isFetching;
|
|
if (!isFetching) {
|
|
Dispatcher.wait(() => fetchPremiumGroupMembership().catch(NOOP_NULL));
|
|
r0 = true;
|
|
}
|
|
return r0;
|
|
},
|
|
PREMIUM_GROUP_MEMBERSHIP_FETCH_START: function handleMembershipFetchStart() {
|
|
c8652_7.membershipData.isFetching = true;
|
|
},
|
|
PREMIUM_GROUP_MEMBERSHIP_FETCH_SUCCESS: function handleMembershipFetchSuccess(a0) {
|
|
c8652_7.membershipData.data = a0.membership;
|
|
c8652_7.membershipData.isFetching = false;
|
|
c8652_7.membershipData.hasFetched = true;
|
|
},
|
|
PREMIUM_GROUP_MEMBERSHIP_NOT_FOUND: function handleMembershipNotFound() {
|
|
c8652_7.membershipData.isFetching = false;
|
|
c8652_7.membershipData.hasFetched = true;
|
|
},
|
|
PREMIUM_GROUP_MEMBERSHIP_FETCH_FAILURE: function handleMembershipFetchFailure() {
|
|
c8652_7.membershipData.isFetching = false;
|
|
c8652_7.membershipData.hasFetched = true;
|
|
},
|
|
PREMIUM_GROUP_INVITE_USERS_START: handleMutationStart,
|
|
PREMIUM_GROUP_INVITE_USERS_SUCCESS: handleMutationSuccess,
|
|
PREMIUM_GROUP_INVITE_USERS_FAILURE: handleMutationFailure,
|
|
PREMIUM_GROUP_REMOVE_MEMBER_START: handleMutationStart,
|
|
PREMIUM_GROUP_REMOVE_MEMBER_SUCCESS: handleMutationSuccess,
|
|
PREMIUM_GROUP_REMOVE_MEMBER_FAILURE: handleMutationFailure,
|
|
PREMIUM_GROUP_REMOVE_INVITE_START: handleMutationStart,
|
|
PREMIUM_GROUP_REMOVE_INVITE_SUCCESS: handleMutationSuccess,
|
|
PREMIUM_GROUP_REMOVE_INVITE_FAILURE: function handleRemoveInviteFailure({ errorCode, subscriptionId: subscriptionId3 }) {
|
|
if (errorCode === PremiumGroupAPIErrorCodes.BILLING_SUBSCRIPTION_GROUP_INVITE_ALREADY_ACCEPTED) {
|
|
Dispatcher.wait(() => fetchSubscriptionGroupMembers(subscriptionId3).catch(NOOP_NULL));
|
|
c8652_7.membersData.isUpdating = false;
|
|
return true;
|
|
}
|
|
c8652_7.membersData.isUpdating = false;
|
|
},
|
|
LOGOUT: function reset() {
|
|
c8652_7 = {
|
|
membersData: {
|
|
data: null,
|
|
isFetching: false,
|
|
isUpdating: false
|
|
},
|
|
membershipData: {
|
|
data: null,
|
|
isFetching: false,
|
|
hasFetched: false
|
|
}
|
|
};
|
|
}
|
|
});
|
|
export default premiumGroupStore;
|