Skip to content

Commit

Permalink
bug: multiple adjustments on the customer usage (#1738)
Browse files Browse the repository at this point in the history
  • Loading branch information
ansmonjol committed Sep 17, 2024
1 parent 3704927 commit 8e9b2b5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
22 changes: 18 additions & 4 deletions src/components/subscriptions/SubscriptionCurrentUsageTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ gql`
name
code
}
customer {
id
applicableTimezone
}
}
}
Expand Down Expand Up @@ -107,6 +111,7 @@ export const SubscriptionCurrentUsageTable = ({
error: customerError,
} = useCustomerForSubscriptionUsageQuery({
variables: { customerId },
skip: !customerId,
})

const {
Expand All @@ -126,14 +131,21 @@ export const SubscriptionCurrentUsageTable = ({
context: {
silentErrorCodes: [LagoApiError.UnprocessableEntity],
},
variables: { customerId: customerId, subscriptionId: subscription?.id || '' },
variables: {
customerId: (customerId || subscription?.customer.id) as string,
subscriptionId: subscription?.id || '',
},
skip: !customerId || !subscription,
// Fixes https://github.com/getlago/lago-front/pull/1243
fetchPolicy: 'no-cache',
})
const currency = usageData?.customerUsage?.currency || CurrencyEnum.Usd
const isLoading = subscriptionLoading || usageLoading || customerLoading
const hasError = !!subscriptionError || !!usageError || !!customerError
const customerTimezone = customerData?.customer?.applicableTimezone || TimezoneEnum.TzUtc
const customerTimezone =
customerData?.customer?.applicableTimezone ||
subscription?.customer.applicableTimezone ||
TimezoneEnum.TzUtc

return (
<section>
Expand Down Expand Up @@ -200,7 +212,7 @@ export const SubscriptionCurrentUsageTable = ({
) : (
<GenericPlaceholder
title={translate('text_62c3f3fca8a1625624e83379')}
subtitle={translate('text_62c3f3fca8a1625624e8337e')}
subtitle={translate('text_1726498444629i1fpjyvh0kg')}
buttonTitle={translate('text_1725983967306qz0npfuhlo1')}
buttonVariant="primary"
buttonAction={() => refetchUsage()}
Expand Down Expand Up @@ -339,7 +351,9 @@ export const SubscriptionCurrentUsageTable = ({
minWidth: 100,
content: (row) => (
<Typography variant="bodyHl" color="grey700">
{intlFormatNumber(row.amountCents)}
{intlFormatNumber(deserializeAmount(row.amountCents, currency), {
currency,
})}
</Typography>
),
},
Expand Down
24 changes: 23 additions & 1 deletion src/generated/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,7 @@ export type CreditNote = {
currency: CurrencyEnum;
customer: Customer;
description?: Maybe<Scalars['String']['output']>;
errorDetails?: Maybe<Array<ErrorDetail>>;
externalIntegrationId?: Maybe<Scalars['String']['output']>;
fileUrl?: Maybe<Scalars['String']['output']>;
id: Scalars['ID']['output'];
Expand All @@ -1326,6 +1327,7 @@ export type CreditNote = {
refundedAt?: Maybe<Scalars['ISO8601DateTime']['output']>;
sequentialId: Scalars['ID']['output'];
subTotalExcludingTaxesAmountCents: Scalars['BigInt']['output'];
taxProviderSyncable: Scalars['Boolean']['output'];
taxesAmountCents: Scalars['BigInt']['output'];
taxesRate: Scalars['Float']['output'];
totalAmountCents: Scalars['BigInt']['output'];
Expand Down Expand Up @@ -2519,6 +2521,7 @@ export enum IntegrationItemTypeEnum {
export enum IntegrationTypeEnum {
Anrok = 'anrok',
Dunning = 'dunning',
Hubspot = 'hubspot',
Netsuite = 'netsuite',
Okta = 'okta',
ProgressiveBilling = 'progressive_billing',
Expand Down Expand Up @@ -3022,6 +3025,8 @@ export type Mutation = {
retryInvoicePayment?: Maybe<Invoice>;
/** Retry voided invoice sync */
retryTaxProviderVoiding?: Maybe<Invoice>;
/** Retry tax reporting */
retryTaxReporting?: Maybe<CreditNote>;
/** Retry a Webhook */
retryWebhook?: Maybe<Webhook>;
/** Revokes an invite */
Expand Down Expand Up @@ -3425,6 +3430,11 @@ export type MutationRetryTaxProviderVoidingArgs = {
};


export type MutationRetryTaxReportingArgs = {
input: RetryTaxReportingInput;
};


export type MutationRetryWebhookArgs = {
input: RetryWebhookInput;
};
Expand Down Expand Up @@ -3882,6 +3892,7 @@ export type PlanOverridesInput = {

export enum PremiumIntegrationTypeEnum {
Dunning = 'dunning',
Hubspot = 'hubspot',
Netsuite = 'netsuite',
Okta = 'okta',
ProgressiveBilling = 'progressive_billing',
Expand Down Expand Up @@ -4530,6 +4541,13 @@ export type RetryTaxProviderVoidingInput = {
id: Scalars['ID']['input'];
};

/** Autogenerated input type of RetryTaxReporting */
export type RetryTaxReportingInput = {
/** A unique identifier for the client performing the mutation. */
clientMutationId?: InputMaybe<Scalars['String']['input']>;
id: Scalars['ID']['input'];
};

/** Autogenerated input type of RetryWebhook */
export type RetryWebhookInput = {
/** A unique identifier for the client performing the mutation. */
Expand Down Expand Up @@ -7040,7 +7058,7 @@ export type SubscrptionForSubscriptionUsageQueryVariables = Exact<{
}>;


export type SubscrptionForSubscriptionUsageQuery = { __typename?: 'Query', subscription?: { __typename?: 'Subscription', id: string, name?: string | null, plan: { __typename?: 'Plan', id: string, name: string, code: string } } | null };
export type SubscrptionForSubscriptionUsageQuery = { __typename?: 'Query', subscription?: { __typename?: 'Subscription', id: string, name?: string | null, plan: { __typename?: 'Plan', id: string, name: string, code: string }, customer: { __typename?: 'Customer', id: string, applicableTimezone: TimezoneEnum } } | null };

export type UsageForSubscriptionUsageQueryVariables = Exact<{
customerId: Scalars['ID']['input'];
Expand Down Expand Up @@ -17059,6 +17077,10 @@ export const SubscrptionForSubscriptionUsageDocument = gql`
name
code
}
customer {
id
applicableTimezone
}
}
}
`;
Expand Down
3 changes: 2 additions & 1 deletion translations/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -2428,5 +2428,6 @@
"text_1725983967306c736sdyjohn": "See breakdown",
"text_1725983967306cei92rkdtvb": "Usage",
"text_1726044816685r61awuydvji": "Close details",
"text_1726158292600r2xetfumq5t": "Item name"
"text_1726158292600r2xetfumq5t": "Item name",
"text_1726498444629i1fpjyvh0kg": "Please refresh this section or contact us if the error persists."
}

0 comments on commit 8e9b2b5

Please sign in to comment.