shellphone.app/src/pages/calls.tsx

57 lines
1.4 KiB
TypeScript
Raw Normal View History

2021-07-18 15:32:45 +00:00
import type { InferGetServerSidePropsType, NextPage } from "next";
import { withPageOnboardingRequired } from "../../lib/session-helpers";
2021-07-21 16:48:49 +00:00
import { findCustomerPhoneCalls } from "../database/phone-call";
2021-07-18 15:32:45 +00:00
import useUser from "../hooks/use-user";
2021-07-21 16:48:49 +00:00
import Layout from "../components/layout";
2021-07-18 15:32:45 +00:00
type Props = InferGetServerSidePropsType<typeof getServerSideProps>;
const pageTitle = "Calls";
2021-07-21 16:48:49 +00:00
const Calls: NextPage<Props> = ({ phoneCalls }) => {
2021-07-18 15:32:45 +00:00
const { userProfile } = useUser();
console.log("userProfile", userProfile);
if (!userProfile) {
return <Layout title={pageTitle}>Loading...</Layout>;
}
return (
<Layout title={pageTitle}>
<div className="flex flex-col space-y-6 p-6">
<p>Calls page</p>
2021-07-21 16:48:49 +00:00
<ul className="divide-y">
{phoneCalls.map((phoneCall) => {
const recipient = phoneCall.direction === "outbound" ? phoneCall.to : phoneCall.from;
return (
<li key={phoneCall.twilioSid} className="flex flex-row justify-between py-2">
<div>{recipient}</div>
<div>{new Date(phoneCall.createdAt).toLocaleString("fr-FR")}</div>
</li>
)
})}
</ul>
2021-07-18 15:32:45 +00:00
</div>
</Layout>
);
};
export const getServerSideProps = withPageOnboardingRequired(
2021-07-21 16:48:49 +00:00
async ({ res }, user) => {
2021-07-21 04:00:43 +00:00
res.setHeader(
"Cache-Control",
"private, s-maxage=15, stale-while-revalidate=59",
);
2021-07-21 16:48:49 +00:00
const phoneCalls = await findCustomerPhoneCalls(user.id);
return {
props: { phoneCalls },
};
2021-07-18 15:32:45 +00:00
},
);
export default Calls;