Skip to content

Commit

Permalink
Merge pull request #2590 from glific/feature/org-status-suspended
Browse files Browse the repository at this point in the history
Show banner if org is suspended for tier issues
  • Loading branch information
mdshamoon authored Oct 11, 2023
2 parents e186c34 + c61c7d9 commit 5e3d067
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
33 changes: 16 additions & 17 deletions src/containers/Chat/ChatMessages/StatusBar/StatusBar.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
import { useQuery } from '@apollo/client';

import { getUserSession } from 'services/AuthService';
import { BSPBALANCE } from 'graphql/queries/Organization';
import { BSPBALANCE, GET_ORGANIZATION_STATUS } from 'graphql/queries/Organization';
import styles from './StatusBar.module.css';

const StatusBar = () => {
const variables = { organizationId: getUserSession('organizationId') };

// get gupshup balance
const { data: orgStatus } = useQuery(GET_ORGANIZATION_STATUS);

const { data: balanceData } = useQuery(BSPBALANCE, {
variables,
fetchPolicy: 'cache-only',
});

if (!balanceData) {
if (!balanceData && !orgStatus) {
return null;
}

const { balance } = JSON.parse(balanceData.bspbalance);

let statusMessage;
if (balance < 1 && balance > 0) {
statusMessage =
'Please recharge your Gupshup wallet immediately to continue sending messages. Users will not receive the messages that get stuck during this time.';
} else if (balance <= 0) {

if (orgStatus && orgStatus.organization.organization.isSuspended) {
statusMessage =
'All the outgoing messages have been suspended. Please note: on recharging, the messages that were stuck will not be sent.';
'You have reached today’s rate limit for sending HSM templates to your users. Your rate limit will be refreshed tomorrow. Please check again later.';
} else if (balanceData) {
const { balance } = JSON.parse(balanceData.bspbalance);
if (balance < 1 && balance > 0) {
statusMessage =
'Please recharge your Gupshup wallet immediately to continue sending messages. Users will not receive the messages that get stuck during this time.';
} else if (balance <= 0) {
statusMessage =
'All the outgoing messages have been suspended. Please note: on recharging, the messages that were stuck will not be sent.';
}
}

// TODOS: need to implement this once backend implements this feature
// const limitReached = false;

// if (limitReached) {
// statusMessage =
// 'You have reached today’s rate limit for sending HSM templates to your users. Your rate limit will be refreshed tomorrow. Please check again later.';
// }

if (statusMessage) {
return (
<div className={styles.StatusMessage}>
Expand Down
10 changes: 10 additions & 0 deletions src/graphql/queries/Organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,13 @@ export const GET_QUALITY_RATING = gql`
}
}
`;

export const GET_ORGANIZATION_STATUS = gql`
query organizationState {
organization {
organization {
isSuspended
}
}
}
`;

0 comments on commit 5e3d067

Please sign in to comment.