Skip to content

Commit

Permalink
Merge branch 'production' into comments-2-layers
Browse files Browse the repository at this point in the history
  • Loading branch information
omranjamal committed Sep 7, 2024
2 parents 67c892d + 2ec8d9a commit 1786378
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/web-next-to-cloudflare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
env:
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
FIREBASE_WEB_CONFIG_JSON_BASE64URL: ${{ secrets.FIREBASE_WEB_CONFIG_JSON_BASE64URL }}
NEXT_PUBLIC_FIREBASE_WEB_CONFIG_JSON_BASE64URL: ${{ secrets.NEXT_PUBLIC_FIREBASE_WEB_CONFIG_JSON_BASE64URL }}
30 changes: 25 additions & 5 deletions apps/jonogon-core/src/services/firebase/index.mts
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
import admin from 'firebase-admin';
import {initializeApp} from 'firebase-admin/app';
import {getAuth} from 'firebase-admin/auth';
import {decode} from 'universal-base64url';
import {returnOf} from 'scope-utilities';

const firebaseConfig = process.env.FIREBASE_ADMIN_PRIVATE_KEY_JSON_BASE64URL
? JSON.parse(decode(process.env.FIREBASE_ADMIN_PRIVATE_KEY_JSON_BASE64URL))
: {
projectId: 'bangladesh2-jonogon',
};
const firebaseConfig = returnOf(() => {
if (process.env.NODE_ENV === 'development') {
return {
projectId: 'bangladesh2-jonogon',
};
}

if (!process.env.FIREBASE_ADMIN_PRIVATE_KEY_JSON_BASE64URL) {
return {
projectId: 'bangladesh2-jonogon',
};
}

const parsed = JSON.parse(
decode(process.env.FIREBASE_ADMIN_PRIVATE_KEY_JSON_BASE64URL),
);

return {
credential: admin.credential.cert(parsed),
databaseURL:
'https://bangladesh2-jonogon-default-rtdb.asia-southeast1.firebasedatabase.app',
};
});

export const firebaseApp = initializeApp(firebaseConfig);
export const firebaseAuth = getAuth(firebaseApp);
66 changes: 28 additions & 38 deletions apps/jonogon-web-next/src/app/petitions/[id]/edit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ import {
AlertDialogTitle,
AlertDialogTrigger,
} from '@/components/ui/alert-dialog';
import {AutoCompleteInput} from '@/components/ui/input-autocomplete';
import {petitionLocations, petitionTargets} from '@/lib/constants';

// import {AutoCompleteInput} from '@/components/ui/input-autocomplete';
// import {petitionLocations, petitionTargets} from '@/lib/constants';

export default function EditPetition() {
const utils = trpc.useUtils();
Expand Down Expand Up @@ -213,14 +214,17 @@ export default function EditPetition() {
},
});

const isValid = z
const validation = z
.object({
title: z.string().min(12),
target: z.string().min(6),
title: z.string().min(3),
target: z.string().min(3),
location: z.string().min(3),
description: z.string().optional(),
})
.safeParse(petitionData).success;
.safeParse(petitionData);

const isValid = validation.success;
const validationErrors = !validation.success ? validation.error : undefined;

const isOwnPetition =
petitionRemoteData &&
Expand All @@ -231,38 +235,24 @@ export default function EditPetition() {
const isMod = !!selfResponse?.meta.token.is_user_moderator;

useEffect(() => {
if (!isAuthenticated) {
router.push(
if (isAuthenticated === false) {
router.replace(
`/login?next=${encodeURIComponent(`/petitions/${petition_id}/edit`)}`,
);
} else if (!isPetitionLoading && petitionRemoteData && selfResponse) {
if (!(isOwnPetition || isAdmin || isMod)) {
router.push(`/petitions/${petition_id}`);
}
}, [isAuthenticated]);

toast({
title: 'You are not authorized to edit this petition',
variant: 'destructive',
});
}
useEffect(() => {
if (isAuthenticated && !isOwnPetition && !isAdmin) {
router.push(`/petitions/${petition_id}`);

toast({
title: 'You are not authorized to edit this petition',
variant: 'destructive',
});
}
}, [
isAuthenticated,
isPetitionLoading,
petitionRemoteData,
selfResponse,
isOwnPetition,
isAdmin,
isMod,
router,
petition_id,
]);

if (
!isAuthenticated ||
(!isPetitionLoading && !(isOwnPetition || isAdmin || isMod))
) {
return null;
}
}, [isAdmin, isOwnPetition]);

return (
<div className="flex flex-col gap-4 max-w-screen-sm mx-auto pt-5 pb-16 px-4">
<div className="flex flex-col-reverse gap-6 sm:flex-row sm:gap-2 justify-between py-12 md:py-10">
Expand Down Expand Up @@ -332,8 +322,8 @@ export default function EditPetition() {
আপনি কার কাছে দাবি করছেন?
</div>
</Label>
<AutoCompleteInput
options={petitionTargets}
<Input
// options={petitionTargets}
className="bg-card text-card-foreground"
id="target"
value={petitionData.target ?? ''}
Expand All @@ -352,8 +342,8 @@ export default function EditPetition() {
কোন এলাকার মানুষের জন্য প্রযোজ্য?
</div>
</Label>
<AutoCompleteInput
options={petitionLocations}
<Input
// options={petitionLocations}
id="target"
value={petitionData.location ?? ''}
className="bg-card text-card-foreground"
Expand Down
4 changes: 3 additions & 1 deletion apps/jonogon-web-next/src/components/custom/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ const Navigation = () => {
<Link href="/" className="flex items-center gap-2">
<img src="/images/icon.svg" alt="logo" className="w-12" />
<div className={'flex flex-col -space-y-2'}>
<span className="text-3xl font-black">জনগণ</span>
<span className="text-3xl font-black text-red-500">
জনগণ
</span>
<span className="text-neutral-600">
সবার দাবির প্লাটফর্ম
</span>
Expand Down
35 changes: 24 additions & 11 deletions apps/jonogon-web-next/src/firebase/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,31 @@ import {type FirebaseApp, initializeApp} from 'firebase/app';
import {getAuth, connectAuthEmulator, type Auth} from 'firebase/auth';
import {getAnalytics} from 'firebase/analytics';
import {decode} from 'universal-base64url';
import {returnOf} from 'scope-utilities';

const firebaseConfig = process.env.FIREBASE_WEB_CONFIG_JSON_BASE64URL
? JSON.parse(decode(process.env.FIREBASE_WEB_CONFIG_JSON_BASE64URL))
: {
apiKey: '-----',
projectId: 'bangladesh2-jonogon',
authDomain: 'bangladesh2-jonogon.firebaseapp.com',
storageBucket: 'bangladesh2-jonogon.appspot.com',
messagingSenderId: '162943930438',
appId: '1:162943930438:web:3650066f5b7bd3df37ba47',
measurementId: 'G-BY995Q5BBE',
};
const firebaseConfig = returnOf(() => {
const defaultConfig = {
apiKey: '-----',
projectId: 'bangladesh2-jonogon',
appId: '1:162943930438:web:3650066f5b7bd3df37ba47',
};

if (process.env.NODE_ENV === 'development') {
return defaultConfig;
}

if (!process.env.NEXT_PUBLIC_FIREBASE_WEB_CONFIG_JSON_BASE64URL) {
return defaultConfig;
}

const parsed = JSON.parse(
decode(process.env.NEXT_PUBLIC_FIREBASE_WEB_CONFIG_JSON_BASE64URL),
);

console.log(parsed);

return parsed;
});

let app: null | FirebaseApp = null;

Expand Down
8 changes: 6 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ services:
dockerfile: Dockerfile
working_dir: /mono
command: pnpm run dev

environment:
NODE_ENV: development
DATABASE_URL: "${DATABASE_URL:-postgresql://postgres:postgres@postgres:5432/postgres}" # useful for `misc/migrator`
Expand All @@ -22,7 +21,7 @@ services:
CLOUDFLARE_SECRET_ACCESS_KEY: "${CLOUDFLARE_SECRET_ACCESS_KEY:-}"

FIREBASE_AUTH_EMULATOR_HOST: "localhost:12005"
FIREBASE_WEB_CONFIG_JSON_BASE64URL: "${FIREBASE_WEB_CONFIG_JSON_BASE64URL:-}"
NEXT_PUBLIC_FIREBASE_WEB_CONFIG_JSON_BASE64URL: "${NEXT_PUBLIC_FIREBASE_WEB_CONFIG_JSON_BASE64URL:-}"
FIREBASE_ADMIN_PRIVATE_KEY_JSON_BASE64URL: "${FIREBASE_ADMIN_PRIVATE_KEY_JSON_BASE64URL:-}"

ports:
Expand Down Expand Up @@ -63,6 +62,10 @@ services:
target: /jonogon-static/
type: volume

- source: firebase-emulator-storage
target: /firebase-persistence
type: volume

depends_on:
- postgres
- redis
Expand Down Expand Up @@ -99,5 +102,6 @@ volumes:
# named volumes; they aren't removed on `docker compose down`
mono-pnpm-store:
core-static-storage:
firebase-emulator-storage:
postgres-data:
redis-data:

0 comments on commit 1786378

Please sign in to comment.