Files
cal.diy/packages/ui/v2/core/Meta.tsx
T
27d9fad292 Feature/whitelabel part 2 (#5821)
* applied whitelabel to additional parts of the app

* format .md files

* updated metadata of all apps

* applied whitelabel to PoweredByCal.tsx

* fixed `team_upgrade_banner_action` with better german

* fixed import of APP_NAME in email templates

* revert "applied whitelabel" in CalEventParser.test.ts

* Revert "updated metadata of all apps"

This reverts commit 9c1621788d2c4c4a4e4a545f48898d4af7a39f33.

* revert app-store whitelabel changes

* Revert "applied whitelabel to PoweredByCal.tsx"

This reverts commit f2b2d79aa51cca3a70af6bf649b24e22f2fca73a.

* Update website

* Sync

* Update constants.ts

* Prevent unit test error

Co-authored-by: René Müller <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
Co-authored-by: zomars <[email protected]>
2023-01-04 22:14:46 +00:00

66 lines
2.0 KiB
TypeScript

import Head from "next/head";
import React, { createContext, useContext, useState, useEffect } from "react";
import { APP_NAME } from "@calcom/lib/constants";
type MetaType = {
title: string;
description: string;
backButton?: boolean;
CTA?: React.ReactNode;
};
const initialMeta: MetaType = {
title: "",
description: "",
backButton: false,
CTA: null,
};
const MetaContext = createContext({
meta: initialMeta,
// eslint-disable-next-line @typescript-eslint/no-empty-function
setMeta: (newMeta: Partial<MetaType>) => {},
});
export function useMeta() {
return useContext(MetaContext);
}
export function MetaProvider({ children }: { children: React.ReactNode }) {
const [value, setValue] = useState(initialMeta);
const setMeta = (newMeta: Partial<MetaType>) => {
setValue((v) => ({ ...v, ...newMeta }));
};
return <MetaContext.Provider value={{ meta: value, setMeta }}>{children}</MetaContext.Provider>;
}
/**
* The purpose of this component is to simplify title and description handling.
* Similarly to `next/head`'s `Head` component this allow us to update the metadata for a page
* from any children, also exposes the metadata via the `useMeta` hook in case we need them
* elsewhere (ie. on a Heading, Title, Subtitle, etc.)
* @example <Meta title="Password" description="Manage settings for your account passwords" />
*/
export default function Meta({ title, description, backButton, CTA }: MetaType) {
const { setMeta, meta } = useMeta();
/* @TODO: maybe find a way to have this data on first render to prevent flicker */
useEffect(() => {
if (meta.title !== title || meta.description !== description || meta.CTA !== CTA) {
setMeta({ title, description, backButton, CTA });
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [title, description, backButton, CTA]);
return (
<Head>
<title>
{title} | {APP_NAME}
</title>
<meta name="description" content={description} />
</Head>
);
}