2022-01-10 03:10:40 +01:00
|
|
|
import {useTranslation} from 'next-i18next';
|
2021-12-27 19:06:31 +01:00
|
|
|
import {serverSideTranslations} from 'next-i18next/serverSideTranslations';
|
|
|
|
|
|
|
|
import React, {useEffect, useState} from "react";
|
|
|
|
import QRCode from "react-qr-code";
|
2021-12-29 00:53:31 +01:00
|
|
|
|
2022-01-10 03:10:40 +01:00
|
|
|
import Alert from '../components/Alert';
|
2021-12-27 19:06:31 +01:00
|
|
|
import Card from '../components/Card';
|
|
|
|
import Logo from "../components/Logo";
|
|
|
|
|
|
|
|
function Pass(): JSX.Element {
|
2022-01-10 03:10:40 +01:00
|
|
|
const { t } = useTranslation(['common', 'index']);
|
2021-12-27 19:06:31 +01:00
|
|
|
|
2022-01-10 03:10:40 +01:00
|
|
|
const [fragment, setFragment] = useState<string>(undefined);
|
|
|
|
const [view, setView] = useState<boolean>(true);
|
2021-12-29 00:53:31 +01:00
|
|
|
|
2021-12-27 19:06:31 +01:00
|
|
|
useEffect(() => {
|
|
|
|
const rawFragment = window.location.hash.substring(1);
|
2021-12-29 00:53:31 +01:00
|
|
|
|
2022-01-10 03:10:40 +01:00
|
|
|
if (!rawFragment) {
|
|
|
|
setView(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
const resizeTimeout = window.setTimeout(() => {
|
2022-01-10 04:29:20 +01:00
|
|
|
if (rawFragment) {
|
2022-01-10 03:10:40 +01:00
|
|
|
window.location.replace('/pass/note');
|
2021-12-29 00:53:31 +01:00
|
|
|
}
|
2022-01-10 04:29:20 +01:00
|
|
|
}, 200);
|
2021-12-29 00:53:31 +01:00
|
|
|
|
2022-01-10 03:10:40 +01:00
|
|
|
window.addEventListener('resize', () => {
|
|
|
|
clearTimeout(resizeTimeout);
|
|
|
|
const decodedFragment = Buffer.from(rawFragment, 'base64').toString();
|
|
|
|
setFragment(decodedFragment);
|
|
|
|
});
|
2021-12-29 00:53:31 +01:00
|
|
|
}, []);
|
2021-12-27 19:06:31 +01:00
|
|
|
|
|
|
|
return (
|
2022-01-10 03:10:40 +01:00
|
|
|
<div className="py-5 flex flex-col space-y-5 md:w-2/3 xl:w-2/5 md:mx-auto items-center justify-center px-5">
|
2021-12-27 19:06:31 +01:00
|
|
|
<Logo/>
|
|
|
|
<div className="flex flex-row items-center">
|
|
|
|
{
|
|
|
|
fragment &&
|
|
|
|
<Card content={
|
|
|
|
<div className="p-2 bg-white rounded-md">
|
2022-01-10 03:10:40 +01:00
|
|
|
<QRCode value={fragment} size={280} level="L" />
|
2021-12-27 19:06:31 +01:00
|
|
|
</div>
|
|
|
|
} />
|
|
|
|
}
|
2022-01-10 03:10:40 +01:00
|
|
|
{
|
|
|
|
!view &&
|
|
|
|
<Alert isWarning={true} message={t('index:viewerNote')} onClose={undefined} />
|
|
|
|
}
|
2021-12-27 19:06:31 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getStaticProps({ locale }) {
|
|
|
|
return {
|
|
|
|
props: {
|
2022-01-10 03:10:40 +01:00
|
|
|
...(await serverSideTranslations(locale, ['index', 'common'])),
|
2021-12-27 19:06:31 +01:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Pass;
|