Skip to content

Commit

Permalink
added pricing and new users
Browse files Browse the repository at this point in the history
  • Loading branch information
postpilotai committed Feb 19, 2025
1 parent 98f6662 commit eab5e66
Show file tree
Hide file tree
Showing 19 changed files with 176 additions and 114 deletions.
2 changes: 1 addition & 1 deletion apps/backend/src/api/routes/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class UsersController {
totalChannels: !process.env.STRIPE_PUBLISHABLE_KEY ? 10000 : organization?.subscription?.totalChannels || pricing.FREE.channel,
// @ts-ignore
tier: organization?.subscription?.subscriptionTier ||
(!process.env.STRIPE_PUBLISHABLE_KEY ? 'ULTIMATE' : 'FREE'),
(!process.env.STRIPE_PUBLISHABLE_KEY ? 'BUSINESS' : 'FREE'),
// @ts-ignore
role: organization?.users[0]?.role,
// @ts-ignore
Expand Down
4 changes: 2 additions & 2 deletions apps/backend/src/services/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class AuthService {
body: CreateOrgUserDto | LoginUserDto,
ip: string,
userAgent: string,
addToOrg?: boolean | { orgId: string; role: 'USER' | 'ADMIN'; id: string }
addToOrg?: boolean | { orgId: string; role: 'VIEWER' | 'EDITOR' | 'ADMIN'; id: string }
) {
if (provider === Provider.LOCAL) {
const user = await this._userService.getUserByEmail(body.email);
Expand Down Expand Up @@ -114,7 +114,7 @@ export class AuthService {

return getOrg as {
email: string;
role: 'USER' | 'ADMIN';
role: 'EDITOR' | 'VIEWER' | 'ADMIN';
orgId: string;
id: string;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class PermissionsService {
async check(
orgId: string,
created_at: Date,
permission: 'USER' | 'ADMIN' | 'SUPERADMIN',
permission: 'VIEWER' | 'EDITOR' | 'ADMIN' | 'SUPERADMIN',
requestedPermission: Array<[AuthorizationActions, Sections]>
) {
const { can, build } = new AbilityBuilder<
Expand Down
6 changes: 3 additions & 3 deletions apps/frontend/src/components/billing/lifetime.deal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ export const LifetimeDeal = () => {
}, [code]);

const nextPackage = useMemo(() => {
if (user?.tier?.current === 'STANDARD') {
if (user?.tier?.current === 'BASIC') {
return 'PRO';
}

return 'STANDARD';
return 'BASIC';
}, [user?.tier]);

const features = useMemo(() => {
Expand Down Expand Up @@ -144,7 +144,7 @@ export const LifetimeDeal = () => {
<div className="border border-customColor6 bg-sixth p-[24px] flex flex-col gap-[20px] flex-1 rounded-[4px]">
<div className="text-[30px]">
Next Package:{' '}
{user?.tier?.current === 'PRO' ? 'EXTRA' : !user?.tier?.current ? 'FREE' : user?.tier?.current === 'STANDARD' ? 'PRO' : 'STANDARD'}
{user?.tier?.current === 'BASIC' ? 'PRO' : !user?.tier?.current ? 'PRO' : 'BUSINESS'}
</div>

<div className="flex flex-col gap-[10px] justify-center text-[16px] text-customColor18">
Expand Down
16 changes: 8 additions & 8 deletions apps/frontend/src/components/billing/main.billing.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ import { PurchaseCrypto } from '@gitroom/frontend/components/billing/purchase.cr

export interface Tiers {
month: Array<{
name: 'Pro' | 'Standard';
name: 'Basic' | 'Pro' | 'Business';
recurring: 'month' | 'year';
price: number;
}>;
year: Array<{
name: 'Pro' | 'Standard';
name: 'Basic' | 'Pro' | 'Business';
recurring: 'month' | 'year';
price: number;
}>;
}

export const Prorate: FC<{
period: 'MONTHLY' | 'YEARLY';
pack: 'STANDARD' | 'PRO';
pack: 'Basic' | 'Pro' | 'Business';
}> = (props) => {
const { period, pack } = props;
const fetch = useFetch();
Expand Down Expand Up @@ -93,7 +93,7 @@ export const Prorate: FC<{
};

export const Features: FC<{
pack: 'FREE' | 'STANDARD' | 'PRO';
pack: 'BASIC' | 'PRO' | 'BUSINESS' | 'FREE';
}> = (props) => {
const { pack } = props;
const features = useMemo(() => {
Expand Down Expand Up @@ -281,7 +281,7 @@ export const MainBillingComponent: FC<{
}, [subscription, initialChannels, monthlyOrYearly, period]);

const moveToCheckout = useCallback(
(billing: 'STANDARD' | 'PRO' | 'FREE') => async () => {
(billing: 'BUSINESS' | 'BASIC' | 'PRO' | 'FREE') => async () => {
const messages = [];

if (
Expand Down Expand Up @@ -469,7 +469,7 @@ export const MainBillingComponent: FC<{
'!bg-red-500'
)}
onClick={moveToCheckout(
name.toUpperCase() as 'STANDARD' | 'PRO'
name.toUpperCase() as 'BASIC' | 'PRO' | 'BUSINESS'
)}
>
{currentPackage === name.toUpperCase()
Expand All @@ -493,12 +493,12 @@ export const MainBillingComponent: FC<{
!!name && (
<Prorate
period={monthlyOrYearly === 'on' ? 'YEARLY' : 'MONTHLY'}
pack={name.toUpperCase() as 'STANDARD' | 'PRO'}
pack={name.toUpperCase() as 'BASIC' | 'PRO' | 'BUSINESS'}
/>
)}
</div>
<Features
pack={name.toUpperCase() as 'FREE' | 'STANDARD' | 'PRO'}
pack={name.toUpperCase() as 'BASIC' | 'PRO' | 'BUSINESS'}
/>
</div>
))}
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/src/components/layout/top.menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const useMenuItems = () => {
name: 'Affiliate',
icon: 'affiliate',
path: 'https://affiliate.postiz.com',
role: ['ADMIN', 'SUPERADMIN', 'USER'],
role: ['EDITOR', 'VIEWER', 'ADMIN', 'SUPERADMIN'],
requireBilling: true,
},
];
Expand Down
6 changes: 3 additions & 3 deletions apps/frontend/src/components/layout/user.context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const UserContext = createContext<
orgId: string;
tier: PricingInnerInterface;
publicApi: string;
role: 'USER' | 'ADMIN' | 'SUPERADMIN';
role: 'EDITOR' | 'VIEWER' | 'ADMIN' | 'SUPERADMIN';
totalChannels: number;
isLifetime?: boolean;
impersonate: boolean;
Expand All @@ -24,8 +24,8 @@ export const UserContext = createContext<
export const ContextWrapper: FC<{
user: User & {
orgId: string;
tier: 'FREE' | 'STANDARD' | 'PRO' | 'ULTIMATE' | 'TEAM';
role: 'USER' | 'ADMIN' | 'SUPERADMIN';
tier: 'FREE' | 'BASIC' | 'PRO' | 'BUSINESS';
role: 'EDITOR' | 'VIEWER' | 'ADMIN' | 'SUPERADMIN';
publicApi: string;
totalChannels: number;
};
Expand Down
33 changes: 24 additions & 9 deletions apps/frontend/src/components/settings/teams.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ import interClass from '@gitroom/react/helpers/inter.font';

const roles = [
{
name: 'User',
value: 'USER',
name: 'Viewer',
value: 'VIEWER',
},
{
name: 'Editor',
value: 'EDITOR'
},
{
name: 'Admin',
Expand Down Expand Up @@ -135,20 +139,31 @@ export const TeamsComponent = () => {
const user = useUser();
const modals = useModals();

const myLevel = user?.role === 'USER' ? 0 : user?.role === 'ADMIN' ? 1 : 2;
const myLevel = user?.role === 'VIEWER' ? 0 : user?.role === 'EDITOR' ? 1 : (user?.role === 'ADMIN' ? 2 : 3);
const getLevel = useCallback(
(role: 'USER' | 'ADMIN' | 'SUPERADMIN') =>
role === 'USER' ? 0 : role === 'ADMIN' ? 1 : 2,
(role: 'VIEWER' | 'EDITOR' | 'ADMIN' | 'SUPERADMIN') => {
switch (role) {

case 'EDITOR':
return 0;
case 'VIEWER':
return 1;
case 'ADMIN':
return 2;
default:
return 3;
}
},
[]
);

const loadTeam = useCallback(async () => {
return (await (await fetch('/settings/team')).json()).users as Array<{
id: string;
role: 'SUPERADMIN' | 'ADMIN' | 'USER';
role: 'EDITOR' | 'VIEWER' | 'ADMIN' | 'SUPERADMIN';
user: { email: string; id: string };
}>;
}, []);

const addMember = useCallback(() => {
modals.openModal({
classNames: {
Expand Down Expand Up @@ -198,8 +213,8 @@ export const TeamsComponent = () => {
{capitalize(p.user.email.split('@')[0]).split('.')[0]}
</div>
<div className="flex-1">
{p.role === 'USER'
? 'User'
{p.role === 'VIEWER'
? 'Viewer'
: p.role === 'ADMIN'
? 'Admin'
: 'Super Admin'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class OrganizationRepository {
userId: string,
id: string,
orgId: string,
role: 'USER' | 'ADMIN'
role: 'EDITOR' | 'VIEWER' | 'ADMIN'
) {
const checkIfInviteExists = await this._user.model.user.findFirst({
where: {
Expand All @@ -184,7 +184,7 @@ export class OrganizationRepository {
if (
process.env.STRIPE_PUBLISHABLE_KEY &&
checkForSubscription?.subscription?.subscriptionTier ===
SubscriptionTier.STANDARD
SubscriptionTier.BASIC
) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class OrganizationService {
userId: string,
id: string,
orgId: string,
role: 'USER' | 'ADMIN'
role: 'EDITOR' | 'VIEWER' | 'ADMIN'
) {
return this._organizationRepository.addUserToOrg(userId, id, orgId, role);
}
Expand Down Expand Up @@ -95,8 +95,26 @@ export class OrganizationService {
// @ts-ignore
const myRole = org.users[0].role;
const userRole = findOrgToDelete.users[0].role;
const myLevel = myRole === 'USER' ? 0 : myRole === 'ADMIN' ? 1 : 2;
const userLevel = userRole === 'USER' ? 0 : userRole === 'ADMIN' ? 1 : 2;
const LEVELS = {
VIEWER: 0,
EDITOR: 1,
ADMIN: 2,
DEFAULT: 3,
};
const getLevel = (role: string) => {
switch (role) {
case 'VIEWER':
return LEVELS.VIEWER;
case 'EDITOR':
return LEVELS.EDITOR;
case 'ADMIN':
return LEVELS.ADMIN;
default:
return LEVELS.DEFAULT;
}
};
const myLevel = getLevel(myRole);
const userLevel = getLevel(userRole);

if (myLevel < userLevel) {
throw new Error('You do not have permission to delete this user');
Expand Down
11 changes: 6 additions & 5 deletions libraries/nestjs-libraries/src/database/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ model UserOrganization {
organization Organization @relation(fields: [organizationId], references: [id])
organizationId String
disabled Boolean @default(false)
role Role @default(USER)
role Role @default(VIEWER)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Expand Down Expand Up @@ -619,10 +619,10 @@ enum State {
}

enum SubscriptionTier {
STANDARD
FREE
BASIC
PRO
TEAM
ULTIMATE
BUSINESS
}

enum Period {
Expand All @@ -641,7 +641,8 @@ enum Provider {
enum Role {
SUPERADMIN
ADMIN
USER
EDITOR
VIEWER
}

enum APPROVED_SUBMIT_FOR_ORDER {
Expand Down
Loading

0 comments on commit eab5e66

Please sign in to comment.