2022-05-30 00:21:42 +00:00
|
|
|
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";
|
2022-05-30 00:21:42 +00:00
|
|
|
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";
|
2022-05-30 00:21:42 +00:00
|
|
|
|
|
|
|
export const action: ActionFunction = async () => {
|
2022-06-01 20:45:49 +00:00
|
|
|
const phoneNumber = await db.phoneNumber.findUnique({
|
|
|
|
where: { id: "PN4f11f0c4155dfb5d5ac8bbab2cc23cbc" },
|
|
|
|
select: {
|
2022-06-11 00:09:37 +00:00
|
|
|
twilioAccount: {
|
|
|
|
include: {
|
|
|
|
organization: {
|
|
|
|
select: {
|
|
|
|
memberships: {
|
|
|
|
select: { notificationSubscription: true },
|
|
|
|
},
|
|
|
|
},
|
2022-06-01 20:45:49 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2022-06-11 00:09:37 +00:00
|
|
|
const subscriptions = phoneNumber!.twilioAccount.organization.memberships.flatMap(
|
2022-06-01 20:45:49 +00:00
|
|
|
(membership) => membership.notificationSubscription,
|
|
|
|
);
|
|
|
|
await notify(subscriptions, {
|
2022-05-30 00:21:42 +00:00
|
|
|
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" },
|
2022-05-30 00:21:42 +00:00
|
|
|
});
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
2022-06-01 20:45:49 +00:00
|
|
|
export default function Notifications() {
|
2022-05-14 10:22:06 +00:00
|
|
|
return (
|
2022-05-30 00:21:42 +00:00
|
|
|
<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>
|
|
|
|
|
2022-05-30 00:21:42 +00:00
|
|
|
<section>
|
2022-06-01 21:56:37 +00:00
|
|
|
<Form method="post">
|
2022-05-30 00:21:42 +00:00
|
|
|
<Button variant="default" type="submit">
|
|
|
|
send it!!!
|
|
|
|
</Button>
|
|
|
|
</Form>
|
|
|
|
</section>
|
|
|
|
</section>
|
2022-05-14 10:22:06 +00:00
|
|
|
);
|
|
|
|
}
|