Files
goodgo-platform/apps/web/lib/hooks/use-residential-projects-flag.ts
Ho Ngoc Hai 492bd0a043
Some checks failed
CI / Lint → Typecheck → Test → Build (22) (push) Failing after 8s
CI / E2E Tests (push) Has been skipped
CodeQL Analysis / CodeQL (javascript-typescript) (push) Failing after 44s
Deploy / Build AI Services Image (push) Failing after 9s
E2E Tests / Playwright E2E (push) Failing after 8s
Security Scanning / Dependency Audit (pnpm) (push) Failing after 3s
Security Scanning / Trivy Scan — API Image (push) Failing after 37s
Security Scanning / Trivy Scan — Web Image (push) Failing after 31s
Security Scanning / Trivy Scan — AI Services Image (push) Failing after 38s
Deploy / Deploy to Staging (push) Has been cancelled
Deploy / Deploy to Production (push) Has been cancelled
Deploy / Smoke Test Staging (push) Has been cancelled
Deploy / Rollback Staging (push) Has been cancelled
Deploy / Rollback Production (push) Has been cancelled
Deploy / Build API Image (push) Failing after 11s
Deploy / Build Web Image (push) Failing after 9s
Deploy / Smoke Test Production (push) Has been cancelled
Security Scanning / Security Gate (push) Has been cancelled
Security Scanning / Trivy Filesystem Scan (push) Has been cancelled
feat(web): enable residential projects feature flag by default for MVP
Flip NEXT_PUBLIC_FEATURE_RESIDENTIAL_PROJECTS default from false to
true so /du-an and /du-an/[slug] render without requiring an env var
or ?residential_projects=1 query override. Kill-switch preserved —
set the env var to "0"/"false" to disable.

The homepage now advertises Dự án as a core feature; having the page
404 by default contradicted that positioning.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-18 21:59:54 +07:00

60 lines
1.5 KiB
TypeScript

'use client';
import { useEffect, useState } from 'react';
const LOCAL_STORAGE_KEY = 'goodgo:residential_projects';
const QUERY_PARAM = 'residential_projects';
function readEnvDefault(): boolean {
const raw = process.env['NEXT_PUBLIC_FEATURE_RESIDENTIAL_PROJECTS'];
if (raw == null || raw === '') return true;
return !(raw === '0' || raw.toLowerCase() === 'false');
}
function readOverride(): boolean | null {
if (typeof window === 'undefined') return null;
const params = new URLSearchParams(window.location.search);
const qp = params.get(QUERY_PARAM);
if (qp === '1' || qp === 'true') {
try {
window.localStorage.setItem(LOCAL_STORAGE_KEY, '1');
} catch {
// localStorage may be blocked — ignore
}
return true;
}
if (qp === '0' || qp === 'false') {
try {
window.localStorage.setItem(LOCAL_STORAGE_KEY, '0');
} catch {
// localStorage may be blocked — ignore
}
return false;
}
try {
const stored = window.localStorage.getItem(LOCAL_STORAGE_KEY);
if (stored === '1') return true;
if (stored === '0') return false;
} catch {
// ignore
}
return null;
}
export function useResidentialProjectsFlag(): boolean {
const [enabled, setEnabled] = useState<boolean>(readEnvDefault());
useEffect(() => {
const override = readOverride();
setEnabled(override ?? readEnvDefault());
}, []);
return enabled;
}
export function isResidentialProjectsEnabledServer(): boolean {
return readEnvDefault();
}