mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 16:23:06 +10:00
feat: update items
Refactored billing flag name Refactored FeatureFlag type Disabled session recording by default
This commit is contained in:
@ -8,7 +8,7 @@ import { getServerComponentFlag } from '~/helpers/get-server-component-feature-f
|
|||||||
export default async function BillingSettingsPage() {
|
export default async function BillingSettingsPage() {
|
||||||
const user = await getRequiredServerComponentSession();
|
const user = await getRequiredServerComponentSession();
|
||||||
|
|
||||||
const isBillingEnabled = await getServerComponentFlag('billing');
|
const isBillingEnabled = await getServerComponentFlag('app_billing');
|
||||||
|
|
||||||
// Redirect if subscriptions are not enabled.
|
// Redirect if subscriptions are not enabled.
|
||||||
if (!isBillingEnabled) {
|
if (!isBillingEnabled) {
|
||||||
|
|||||||
@ -38,7 +38,7 @@ export const ProfileDropdown = ({ user }: ProfileDropdownProps) => {
|
|||||||
|
|
||||||
const { getFlag } = useFeatureFlags();
|
const { getFlag } = useFeatureFlags();
|
||||||
|
|
||||||
const isBillingEnabled = getFlag('billing');
|
const isBillingEnabled = getFlag('app_billing');
|
||||||
|
|
||||||
const initials =
|
const initials =
|
||||||
user.name
|
user.name
|
||||||
|
|||||||
@ -19,7 +19,7 @@ export const DesktopNav = ({ className, ...props }: DesktopNavProps) => {
|
|||||||
|
|
||||||
const { getFlag } = useFeatureFlags();
|
const { getFlag } = useFeatureFlags();
|
||||||
|
|
||||||
const isBillingEnabled = getFlag('billing');
|
const isBillingEnabled = getFlag('app_billing');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cn('flex flex-col gap-y-2', className)} {...props}>
|
<div className={cn('flex flex-col gap-y-2', className)} {...props}>
|
||||||
|
|||||||
@ -19,7 +19,7 @@ export const MobileNav = ({ className, ...props }: MobileNavProps) => {
|
|||||||
|
|
||||||
const { getFlag } = useFeatureFlags();
|
const { getFlag } = useFeatureFlags();
|
||||||
|
|
||||||
const isBillingEnabled = getFlag('billing');
|
const isBillingEnabled = getFlag('app_billing');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { z } from 'zod';
|
|||||||
|
|
||||||
import { LOCAL_FEATURE_FLAGS, isFeatureFlagEnabled } from '@documenso/lib/constants/feature-flags';
|
import { LOCAL_FEATURE_FLAGS, isFeatureFlagEnabled } from '@documenso/lib/constants/feature-flags';
|
||||||
|
|
||||||
import { FeatureFlagValue } from '~/providers/feature-flag';
|
import { TFeatureFlagValue } from '~/providers/feature-flag';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Evaluate whether a flag is enabled for the current user.
|
* Evaluate whether a flag is enabled for the current user.
|
||||||
@ -14,7 +14,7 @@ import { FeatureFlagValue } from '~/providers/feature-flag';
|
|||||||
export const getFlag = async (
|
export const getFlag = async (
|
||||||
flag: string,
|
flag: string,
|
||||||
options?: GetFlagOptions,
|
options?: GetFlagOptions,
|
||||||
): Promise<FeatureFlagValue> => {
|
): Promise<TFeatureFlagValue> => {
|
||||||
const requestHeaders = options?.requestHeaders ?? {};
|
const requestHeaders = options?.requestHeaders ?? {};
|
||||||
|
|
||||||
if (!isFeatureFlagEnabled()) {
|
if (!isFeatureFlagEnabled()) {
|
||||||
@ -47,7 +47,7 @@ export const getFlag = async (
|
|||||||
*/
|
*/
|
||||||
export const getAllFlags = async (
|
export const getAllFlags = async (
|
||||||
options?: GetFlagOptions,
|
options?: GetFlagOptions,
|
||||||
): Promise<Record<string, FeatureFlagValue>> => {
|
): Promise<Record<string, TFeatureFlagValue>> => {
|
||||||
const requestHeaders = options?.requestHeaders ?? {};
|
const requestHeaders = options?.requestHeaders ?? {};
|
||||||
|
|
||||||
if (!isFeatureFlagEnabled()) {
|
if (!isFeatureFlagEnabled()) {
|
||||||
|
|||||||
@ -92,7 +92,7 @@ export const mapJwtToFlagProperties = (
|
|||||||
*
|
*
|
||||||
* @param jwt The JWT of the current user.
|
* @param jwt The JWT of the current user.
|
||||||
* @param request Request potentially containing a PostHog `distinct_id` cookie.
|
* @param request Request potentially containing a PostHog `distinct_id` cookie.
|
||||||
* @returns
|
* @returns A distinct user ID.
|
||||||
*/
|
*/
|
||||||
export const extractDistinctUserId = (jwt: JWT | null, request: NextRequest): string => {
|
export const extractDistinctUserId = (jwt: JWT | null, request: NextRequest): string => {
|
||||||
const config = extractPostHogConfig();
|
const config = extractPostHogConfig();
|
||||||
|
|||||||
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
import { createContext, useCallback, useContext, useEffect, useState } from 'react';
|
import { createContext, useCallback, useContext, useEffect, useState } from 'react';
|
||||||
|
|
||||||
|
import { z } from 'zod';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
FEATURE_FLAG_POLL_INTERVAL,
|
FEATURE_FLAG_POLL_INTERVAL,
|
||||||
LOCAL_FEATURE_FLAGS,
|
LOCAL_FEATURE_FLAGS,
|
||||||
@ -10,10 +12,17 @@ import {
|
|||||||
|
|
||||||
import { getAllFlags } from '~/helpers/get-feature-flag';
|
import { getAllFlags } from '~/helpers/get-feature-flag';
|
||||||
|
|
||||||
export type FeatureFlagValue = boolean | string | number | undefined;
|
export const ZFeatureFlagValueSchema = z.union([
|
||||||
|
z.boolean(),
|
||||||
|
z.string(),
|
||||||
|
z.number(),
|
||||||
|
z.undefined(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
export type TFeatureFlagValue = z.infer<typeof ZFeatureFlagValueSchema>;
|
||||||
|
|
||||||
export type FeatureFlagContextValue = {
|
export type FeatureFlagContextValue = {
|
||||||
getFlag: (_key: string) => FeatureFlagValue;
|
getFlag: (_key: string) => TFeatureFlagValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const FeatureFlagContext = createContext<FeatureFlagContextValue | null>(null);
|
export const FeatureFlagContext = createContext<FeatureFlagContextValue | null>(null);
|
||||||
@ -33,7 +42,7 @@ export function FeatureFlagProvider({
|
|||||||
initialFlags,
|
initialFlags,
|
||||||
}: {
|
}: {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
initialFlags: Record<string, FeatureFlagValue>;
|
initialFlags: Record<string, TFeatureFlagValue>;
|
||||||
}) {
|
}) {
|
||||||
const [flags, setFlags] = useState(initialFlags);
|
const [flags, setFlags] = useState(initialFlags);
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import posthog from 'posthog-js';
|
|||||||
|
|
||||||
import { extractPostHogConfig } from '@documenso/lib/constants/feature-flags';
|
import { extractPostHogConfig } from '@documenso/lib/constants/feature-flags';
|
||||||
|
|
||||||
export function PostHogPageview(): JSX.Element {
|
export function PostHogPageview() {
|
||||||
const postHogConfig = extractPostHogConfig();
|
const postHogConfig = extractPostHogConfig();
|
||||||
|
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
@ -18,6 +18,7 @@ export function PostHogPageview(): JSX.Element {
|
|||||||
if (typeof window !== 'undefined' && postHogConfig) {
|
if (typeof window !== 'undefined' && postHogConfig) {
|
||||||
posthog.init(postHogConfig.key, {
|
posthog.init(postHogConfig.key, {
|
||||||
api_host: postHogConfig.host,
|
api_host: postHogConfig.host,
|
||||||
|
disable_session_recording: true,
|
||||||
loaded: () => {
|
loaded: () => {
|
||||||
getSession()
|
getSession()
|
||||||
.then((session) => {
|
.then((session) => {
|
||||||
@ -48,5 +49,5 @@ export function PostHogPageview(): JSX.Element {
|
|||||||
});
|
});
|
||||||
}, [pathname, searchParams, postHogConfig]);
|
}, [pathname, searchParams, postHogConfig]);
|
||||||
|
|
||||||
return <></>;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@ export const FEATURE_FLAG_POLL_INTERVAL = 30000;
|
|||||||
* Does not take any person or group properties into account.
|
* Does not take any person or group properties into account.
|
||||||
*/
|
*/
|
||||||
export const LOCAL_FEATURE_FLAGS: Record<string, boolean> = {
|
export const LOCAL_FEATURE_FLAGS: Record<string, boolean> = {
|
||||||
billing: process.env.NEXT_PUBLIC_FEATURE_BILLING_ENABLED === 'true',
|
app_billing: process.env.NEXT_PUBLIC_FEATURE_BILLING_ENABLED === 'true',
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user