-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[admin] Allow credit adjustments #14594
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -15,24 +15,45 @@ import Label from "./Label"; | |||||
import Property from "./Property"; | ||||||
import { AttributionId } from "@gitpod/gitpod-protocol/lib/attribution"; | ||||||
import { BillingMode } from "@gitpod/gitpod-protocol/lib/billing-mode"; | ||||||
import { CostCenterJSON, CostCenter_BillingStrategy } from "@gitpod/gitpod-protocol/lib/usage"; | ||||||
import Modal from "../components/Modal"; | ||||||
|
||||||
export default function TeamDetail(props: { team: Team }) { | ||||||
const { team } = props; | ||||||
const [teamMembers, setTeamMembers] = useState<TeamMemberInfo[] | undefined>(undefined); | ||||||
const [billingMode, setBillingMode] = useState<BillingMode | undefined>(undefined); | ||||||
const [searchText, setSearchText] = useState<string>(""); | ||||||
const [costCenter, setCostCenter] = useState<CostCenterJSON>(); | ||||||
const [usageBalance, setUsageBalance] = useState<number>(0); | ||||||
const [usageLimit, setUsageLimit] = useState<number>(); | ||||||
const [editSpendingLimit, setEditSpendingLimit] = useState<boolean>(false); | ||||||
const [creditNote, setCreditNote] = useState<{ credits: number; note?: string }>({ credits: 0 }); | ||||||
const [editAddCreditNote, setEditAddCreditNote] = useState<boolean>(false); | ||||||
|
||||||
useEffect(() => { | ||||||
const initialize = () => { | ||||||
(async () => { | ||||||
const members = await getGitpodService().server.adminGetTeamMembers(team.id); | ||||||
if (members.length > 0) { | ||||||
setTeamMembers(members); | ||||||
} | ||||||
})(); | ||||||
getGitpodService() | ||||||
.server.adminGetBillingMode(AttributionId.render({ kind: "team", teamId: props.team.id })) | ||||||
.server.adminGetBillingMode(AttributionId.render({ kind: "team", teamId: team.id })) | ||||||
.then((bm) => setBillingMode(bm)); | ||||||
}, [team]); | ||||||
const attributionId = AttributionId.render(AttributionId.create(team)); | ||||||
getGitpodService().server.adminGetBillingMode(attributionId).then(setBillingMode); | ||||||
getGitpodService().server.adminGetCostCenter(attributionId).then(setCostCenter); | ||||||
getGitpodService().server.adminGetUsageBalance(attributionId).then(setUsageBalance); | ||||||
}; | ||||||
|
||||||
useEffect(initialize, [team]); | ||||||
|
||||||
useEffect(() => { | ||||||
if (!costCenter) { | ||||||
return; | ||||||
} | ||||||
setUsageLimit(costCenter.spendingLimit); | ||||||
}, [costCenter]); | ||||||
|
||||||
const filteredMembers = teamMembers?.filter((m) => { | ||||||
const memberSearchText = `${m.fullName || ""}${m.primaryEmail || ""}`.toLocaleLowerCase(); | ||||||
|
@@ -64,8 +85,53 @@ export default function TeamDetail(props: { team: Team }) { | |||||
</div> | ||||||
</div> | ||||||
<div className="flex mt-6"> | ||||||
{!team.markedDeleted && teamMembers && <Property name="Members">{teamMembers.length}</Property>} | ||||||
{!team.markedDeleted && <Property name="BillingMode">{billingMode?.mode || "---"}</Property>} | ||||||
{!team.markedDeleted && <Property name="Members">{teamMembers?.length || "?"}</Property>} | ||||||
{!team.markedDeleted && <Property name="Billing Mode">{billingMode?.mode || "---"}</Property>} | ||||||
{costCenter && ( | ||||||
<Property name="Stripe Subscription" actions={[]}> | ||||||
<span> | ||||||
{costCenter?.billingStrategy === CostCenter_BillingStrategy.BILLING_STRATEGY_STRIPE | ||||||
? "Active" | ||||||
: "Inactive"} | ||||||
</span> | ||||||
</Property> | ||||||
)} | ||||||
</div> | ||||||
<div className="flex mt-6"> | ||||||
{costCenter && ( | ||||||
<Property name="Current Cycle" actions={[]}> | ||||||
<span> | ||||||
{dayjs(costCenter?.billingCycleStart).format("MMM D")} -{" "} | ||||||
{dayjs(costCenter?.nextBillingTime).format("MMM D")} | ||||||
</span> | ||||||
</Property> | ||||||
)} | ||||||
{costCenter && ( | ||||||
<Property | ||||||
name="Available Credits" | ||||||
actions={[ | ||||||
{ | ||||||
label: "Add Credits", | ||||||
onClick: () => setEditAddCreditNote(true), | ||||||
}, | ||||||
]} | ||||||
> | ||||||
<span>{usageBalance * -1 + (costCenter?.spendingLimit || 0)} Credits</span> | ||||||
</Property> | ||||||
)} | ||||||
{costCenter && ( | ||||||
<Property | ||||||
name="Usage Limit" | ||||||
actions={[ | ||||||
{ | ||||||
label: "Change Usage Limit", | ||||||
onClick: () => setEditSpendingLimit(true), | ||||||
}, | ||||||
]} | ||||||
> | ||||||
<span>{costCenter?.spendingLimit} Credits</span> | ||||||
</Property> | ||||||
)} | ||||||
</div> | ||||||
<div className="flex mt-4"> | ||||||
<div className="flex"> | ||||||
|
@@ -151,6 +217,91 @@ export default function TeamDetail(props: { team: Team }) { | |||||
)) | ||||||
)} | ||||||
</ItemsList> | ||||||
<Modal | ||||||
visible={editSpendingLimit} | ||||||
onClose={() => setEditSpendingLimit(false)} | ||||||
title="Change Usage Limit" | ||||||
onEnter={() => false} | ||||||
buttons={[ | ||||||
<button | ||||||
disabled={usageLimit === costCenter?.spendingLimit} | ||||||
onClick={async () => { | ||||||
if (usageLimit !== undefined) { | ||||||
await getGitpodService().server.adminSetUsageLimit( | ||||||
AttributionId.render(AttributionId.create(team)), | ||||||
usageLimit || 0, | ||||||
); | ||||||
setUsageLimit(undefined); | ||||||
initialize(); | ||||||
setEditSpendingLimit(false); | ||||||
} | ||||||
}} | ||||||
> | ||||||
Change | ||||||
</button>, | ||||||
]} | ||||||
> | ||||||
<p className="pb-4 text-gray-500 text-base">Change the usage limit in credits per month.</p> | ||||||
<label>Credits</label> | ||||||
<div className="flex flex-col"> | ||||||
<input | ||||||
type="number" | ||||||
svenefftinge marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
className="w-full" | ||||||
min={Math.max(usageBalance, 0)} | ||||||
max={500000} | ||||||
title="Change Usage Limit" | ||||||
value={usageLimit} | ||||||
onChange={(event) => setUsageLimit(Number.parseInt(event.target.value))} | ||||||
/> | ||||||
</div> | ||||||
</Modal> | ||||||
<Modal | ||||||
onEnter={() => false} | ||||||
visible={editAddCreditNote} | ||||||
onClose={() => setEditAddCreditNote(false)} | ||||||
title="Add Credits" | ||||||
buttons={[ | ||||||
<button | ||||||
disabled={creditNote.credits === 0 || !creditNote.note} | ||||||
onClick={async () => { | ||||||
if (creditNote.credits !== 0 && !!creditNote.note) { | ||||||
await getGitpodService().server.adminAddUsageCreditNote( | ||||||
AttributionId.render(AttributionId.create(team)), | ||||||
creditNote.credits, | ||||||
creditNote.note, | ||||||
); | ||||||
setEditAddCreditNote(false); | ||||||
setCreditNote({ credits: 0 }); | ||||||
initialize(); | ||||||
} | ||||||
}} | ||||||
> | ||||||
Add Credits | ||||||
</button>, | ||||||
]} | ||||||
> | ||||||
<p>Adds or subtracts the amount of credits from this account.</p> | ||||||
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. thought: An info alert at the top of this modal to explain what's happening or when and how to use this could help, as we do with
|
||||||
<div className="flex flex-col"> | ||||||
<label className="mt-4">Credits</label> | ||||||
<input | ||||||
className="w-full" | ||||||
type="number" | ||||||
svenefftinge marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
min={-50000} | ||||||
max={50000} | ||||||
title="Credits" | ||||||
value={creditNote.credits} | ||||||
onChange={(event) => | ||||||
setCreditNote({ credits: Number.parseInt(event.target.value), note: creditNote.note }) | ||||||
} | ||||||
/> | ||||||
<label className="mt-4">Note</label> | ||||||
<textarea | ||||||
className="w-full" | ||||||
title="Note" | ||||||
svenefftinge marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
onChange={(event) => setCreditNote({ credits: creditNote.credits, note: event.target.value })} | ||||||
/> | ||||||
</div> | ||||||
</Modal> | ||||||
</> | ||||||
); | ||||||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.