Skip to content
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

free plan migration: allow 1 domain on free account #745

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,9 @@ export function AddDomainModal() {
});

const { data: canAddDomain, isLoading } =
platform.org.iCanHaz.domain.useQuery(
{
orgShortcode: orgShortcode
},
{
staleTime: 1000
}
);
platform.org.iCanHaz.domain.useQuery({
orgShortcode: orgShortcode
});

const [open, setOpen] = useState(false);
const [domain, setDomain] = useState('');
Expand Down
39 changes: 24 additions & 15 deletions ee/apps/billing/trpc/routers/iCanHazRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,30 @@ export const iCanHazRouter = router({
const { db } = ctx;

const orgId = input.orgId;
const allowedDomainsOnFreePlan = 1;

const orgBillingResponse = await db.query.orgBilling.findFirst({
where: eq(orgBilling.orgId, orgId),
columns: {
plan: true
}
});

// if pro, has unlimited domains
if (orgBillingResponse && orgBillingResponse.plan === 'pro') {
return true;
}

//for skiff users
// get existing org domain count
const domainQuery = await db.query.domains.findMany({
where: and(eq(domains.orgId, orgId), eq(domains.disabled, false)),
columns: {
id: true
}
});
const existingOrgDomainCount = domainQuery?.length || 0;

// check if org has bonus domains
const orgQuery = await db.query.orgs.findFirst({
where: eq(orgs.id, orgId),
columns: {
Expand All @@ -41,25 +53,22 @@ export const iCanHazRouter = router({
const orgMetadata = orgQuery.metadata;

// get the bonus where item matches domain
const domainBonus = orgMetadata?.bonuses?.find(
const domainBonusMetadataEntry = orgMetadata?.bonuses?.find(
(bonus) => bonus.item === 'domain'
);

if (!domainBonus || !('count' in domainBonus.bonus)) {
return false;
}

const allowedDomains: number = domainBonus.bonus.count;

const domainQuery = await db.query.domains.findMany({
where: and(eq(domains.orgId, orgId), eq(domains.disabled, false)),
columns: {
id: true
if (
domainBonusMetadataEntry &&
'count' in domainBonusMetadataEntry.bonus
) {
const allowedBonusDomains: number =
domainBonusMetadataEntry.bonus.count;
if (existingOrgDomainCount < allowedBonusDomains) {
return true;
}
});
const domainCount = domainQuery?.length || 0;
}

if (domainCount < allowedDomains) {
if (existingOrgDomainCount < allowedDomainsOnFreePlan) {
return true;
}

Expand Down
Loading