Skip to content

Commit

Permalink
feat(4870): improve admin billing page
Browse files Browse the repository at this point in the history
  • Loading branch information
junminahn committed Feb 10, 2025
1 parent 6bd386f commit 759b65a
Show file tree
Hide file tree
Showing 10 changed files with 247 additions and 267 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ install:
.PHONY: asdf-install
asdf-install:
cat .tool-versions | cut -f 1 -d ' ' | xargs -n 1 asdf plugin-add || true
asdf plugin-update --all
asdf plugin update --all
asdf install
asdf reshim

Expand Down
52 changes: 51 additions & 1 deletion app/app/api/billing/search/route.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,63 @@
import { DecisionStatus, RequestType } from '@prisma/client';
import { GlobalPermissions } from '@/constants';
import createApiHandler from '@/core/api-handler';
import prisma from '@/core/prisma';
import { OkResponse } from '@/core/responses';
import { searchBilling } from '@/services/db/billing';
import { BillingSearchResponsePayload } from '@/types/billing';
import { billingSearchBodySchema } from '@/validation-schemas/billing';

export const POST = createApiHandler({
permissions: [GlobalPermissions.ViewBilling],
validations: { body: billingSearchBodySchema },
})(async ({ body }) => {
const result = await searchBilling(body);
const { data, totalCount } = await searchBilling(body);

const billingIds = data.map(({ id }) => id);

const [publicProducts, publicCreateRequests] = await Promise.all([
prisma.publicCloudProject.findMany({
where: { billingId: { in: billingIds } },
select: { id: true, licencePlate: true, name: true, billingId: true, provider: true },
}),
prisma.publicCloudRequest.findMany({
where: {
type: RequestType.CREATE,
decisionStatus: DecisionStatus.PENDING,
decisionData: { billingId: { in: billingIds } },
},
select: {
id: true,
licencePlate: true,
decisionData: { select: { name: true, billingId: true, provider: true } },
},
}),
]);

const result: BillingSearchResponsePayload = {
data,
totalCount,
metadata: {
publicProducts: publicProducts.map(({ id, licencePlate, name, provider, billingId }) => ({
type: 'product',
url: `/public-cloud/products/${licencePlate}/edit`,
id,
licencePlate,
name,
context: provider,
billingId,
})),
publicRequests: publicCreateRequests.map(({ id, licencePlate, decisionData }) => ({
type: 'request',
url: `/public-cloud/requests/${id}/summary`,
id,
licencePlate,
name: decisionData.name,
context: decisionData.provider,
billingId: decisionData.billingId,
})),
},
};

return OkResponse(result);
});
15 changes: 1 addition & 14 deletions app/app/billing/all/FilterPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function FilterPanel({ isLoading = false }: { isLoading?: boolean
loaderProps={{ color: 'pink', type: 'bars' }}
/>
<div className="grid grid-cols-1 gap-y-2 md:grid-cols-12 md:gap-x-3">
<div className="col-span-12">
<div className="col-span-6">
<FormMultiSelect
name="roles"
label="Billing status"
Expand All @@ -33,19 +33,6 @@ export default function FilterPanel({ isLoading = false }: { isLoading?: boolean
}}
classNames={{ wrapper: '' }}
/>
<div className="text-right">
<Button
color="primary"
size="compact-md"
className="mt-1"
onClick={() => {
pageState.billings = billingTypeOptions.map((option) => option.value);
pageState.page = 1;
}}
>
Select All
</Button>
</div>
</div>
</div>
</Box>
Expand Down
Loading

0 comments on commit 759b65a

Please sign in to comment.