-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add firebase and migrate from moment to dayjs
- Loading branch information
1 parent
9dffb72
commit 37b7d65
Showing
11 changed files
with
88 additions
and
34 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { useFirebase } from '../providers/components/firebase-provider' | ||
|
||
export default useFirebase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export { useGlobals } from '../providers/components/globals-provider' | ||
import { useGlobals } from '../providers/components/globals-provider' | ||
|
||
export default useGlobals |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { createContext, ReactNode, useContext } from 'react' | ||
import { initializeApp } from 'firebase/app' | ||
import { | ||
getAnalytics, | ||
logEvent as logEventVendor, | ||
setUserProperties, | ||
} from 'firebase/analytics' | ||
import packageJson from '../../../package.json' | ||
|
||
/** | ||
* Firebase configuration | ||
* | ||
* production conf is setted in https://github.com/sensasi-delight/simulasi-grading-sawit/settings/environments | ||
*/ | ||
const FIREBASE_APP = import.meta.env.FIREBASE_PROJECT_ID | ||
? initializeApp({ | ||
apiKey: import.meta.env.FIREBASE_API_KEY, | ||
authDomain: import.meta.env.FIREBASE_AUTH_DOMAIN, | ||
projectId: import.meta.env.FIREBASE_PROJECT_ID, | ||
storageBucket: import.meta.env.FIREBASE_STORAGE_BUCKET, | ||
messagingSenderId: import.meta.env.FIREBASE_MESSAGING_SENDER_ID, | ||
appId: import.meta.env.FIREBASE_APP_ID, | ||
measurementId: import.meta.env.FIREBASE_MEASUREMENT_ID, | ||
}) | ||
: null | ||
|
||
const analytics = FIREBASE_APP ? getAnalytics(FIREBASE_APP) : null | ||
|
||
function logEvent(eventName: string) { | ||
if (!analytics) return | ||
|
||
setUserProperties(analytics, { wpa_version: packageJson.version }) | ||
|
||
return logEventVendor(analytics, eventName) | ||
} | ||
|
||
const CONTEXT = createContext<{ | ||
logEvent: (eventName: string) => void | ||
}>({ | ||
logEvent: logEvent, | ||
}) | ||
|
||
export function FirebaseProvider({ children }: { children: ReactNode }) { | ||
return ( | ||
<CONTEXT.Provider | ||
value={{ | ||
logEvent, | ||
}}> | ||
{children} | ||
</CONTEXT.Provider> | ||
) | ||
} | ||
|
||
export function useFirebase() { | ||
return useContext(CONTEXT) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters