shellphone.app/app/routes/__app/settings/notifications.tsx

60 lines
1.6 KiB
TypeScript
Raw Normal View History

import type { ActionFunction } from "@remix-run/node";
import { ClientOnly } from "remix-utils";
import { Form } from "@remix-run/react";
2022-06-01 20:45:49 +00:00
2022-06-01 21:56:37 +00:00
import db from "~/utils/db.server";
import { notify } from "~/utils/web-push.server";
import Button from "~/features/settings/components/button";
2022-06-01 20:45:49 +00:00
import NotificationsSettings, {
FallbackNotificationsSettings,
} from "~/features/settings/components/settings/notifications-settings";
export const action: ActionFunction = async () => {
2022-06-01 20:45:49 +00:00
const phoneNumber = await db.phoneNumber.findUnique({
where: { id: "PN4f11f0c4155dfb5d5ac8bbab2cc23cbc" },
select: {
organization: {
select: {
memberships: {
select: { notificationSubscription: true },
},
},
},
},
});
const subscriptions = phoneNumber!.organization.memberships.flatMap(
(membership) => membership.notificationSubscription,
);
await notify(subscriptions, {
title: "+33 6 13 37 07 87",
body: "wesh le zin, wesh la zine, copain copine mais si y'a moyen on pine",
actions: [
{
action: "reply",
title: "Reply",
},
],
2022-06-01 21:56:37 +00:00
data: { recipient: "+33613370787", type: "message" },
});
return null;
};
2022-06-01 20:45:49 +00:00
export default function Notifications() {
2022-05-14 10:22:06 +00:00
return (
<section className="pt-6 divide-y divide-gray-200">
2022-06-01 20:45:49 +00:00
<div className="px-4 sm:px-6">
<h2 className="text-lg leading-6 font-medium text-gray-900">Notifications</h2>
<ClientOnly fallback={<FallbackNotificationsSettings />}>{() => <NotificationsSettings />}</ClientOnly>
</div>
<section>
2022-06-01 21:56:37 +00:00
<Form method="post">
<Button variant="default" type="submit">
send it!!!
</Button>
</Form>
</section>
</section>
2022-05-14 10:22:06 +00:00
);
}