i would like to ask a question, i want to add a push notification at my TypeScript Next.js 14.2 for every selection at Penjadwalan (translate: Schedule), like i want it to send a push notification for 1 time in a day and much more based on the user select, can i get a recommendation or solving for this?
"use client";
import React, { useEffect, useState } from "react";
import Image from "next/image";
import { FieldValues, SubmitHandler, useForm } from "react-hook-form";
import { useSupabaseClient } from "@supabase/auth-helpers-react";
import { useRouter } from "next/navigation";
import { useUser } from "@/hooks/useUser";
const svg = {
userDarken: require("@/shared/icons/user-darken.svg"),
pillDarken: require("@/shared/icons/pill-darken.svg"),
calendarPlusDarken: require("@/shared/icons/calendar-plus-darken.svg"),
vaccineBottleDarken: require("@/shared/icons/vaccine-bottle-darken.svg"),
bellPlusDarken: require("@/shared/icons/bell-plus-darken.svg"),
checkupListDarken: require("@/shared/icons/checkup-list-darken.svg"),
plusSecondary: require("@/shared/icons/plus-secondary.svg"),
xSecondary: require("@/shared/icons/x-secondary.svg"),
};
interface AddProviderProps {
className: string;
onClick: (event: React.MouseEvent<HTMLButtonElement>) => void;
}
const ComponentAddProvider: React.FC<AddProviderProps> = ({
className,
onClick,
}) => {
const [controlExpand, setControlExpand] = useState(false);
const [isLoading, setIsLoading] = useState(false);
const supabaseClient = useSupabaseClient();
const router = useRouter();
const { user } = useUser();
useEffect(() => {
const controlExpandBreakpoint = window.innerWidth < 1024;
setControlExpand(!controlExpandBreakpoint);
}, []);
const { register, handleSubmit, reset } = useForm<FieldValues>({
defaultValues: {
date_added: new Date().toISOString().split("T")[0],
patient: "",
medicine: "",
dosage: "",
dosage_unit: "Pilih Dosis",
schedule: "Pilih Penjadwalan",
notes: "",
},
});
const eventSubmit: SubmitHandler<FieldValues> = async (values) => {
try {
setIsLoading(true);
const { error: supabaseError } = await supabaseClient
.from("reminders")
.insert({
user_id: user?.id,
date_added: values.date_added,
patient: values.patient,
medicine: values.medicine,
dosage: values.dosage,
dosage_unit: values.dosage_unit,
schedule: values.schedule,
notes: values.notes,
});
if (supabaseError) {
setIsLoading(false);
console.log(supabaseError.message);
}
router.refresh();
reset();
} catch (error) {
console.log(error);
} finally {
setIsLoading(false);
}
};
return (
<form
onSubmit={handleSubmit(eventSubmit)}
className={`bg-[hsl(210,17%,98%)] ${className} z-10 w-full lg:w-[480px] px-6 py-0 lg:p-8 rounded-3xl`}
>
<div
className={`${
controlExpand ? "mt-0 mb-4 lg:mb-8" : "m-0"
} flex flex-col lg:flex-row items-start justify-between w-full h-auto`}
>
<div className="z-10 flex flex-col items-center lg:items-start justify-center lg:justify-start w-full lg:w-auto h-auto">
<p className="text-[hsl(0,0%,13%)] font-medium text-sm text-start mt-0 mb-0">
Tambahkan Pengingat
</p>
<p className="text-[hsl(0,0%,53%)] font-light text-xs text-start mt-0 mb-0">
Buat Penjadwalan Sekarang
</p>
</div>
<div className="flex flex-row gap-4 lg:gap-2 items-center justify-center lg:justify-end w-full lg:w-auto h-auto mt-4 lg:mt-0">
<button
type="submit"
className="bg-[hsl(0,0%,13%)] opacity-100 transition-all hover:opacity-80 flex flex-row gap-2 items-center justify-center w-full lg:w-fit p-4 lg:px-4 lg:py-2 rounded-2xl"
>
<Image
src={svg.plusSecondary}
width="14"
height="14"
alt="plusSecondary"
/>
<p className="text-[hsl(210,17%,98%)] font-medium text-xs">
Tambah
</p>
</button>
<button
onClick={onClick}
className="bg-[hsl(0,0%,13%)] opacity-100 transition-all hover:opacity-80 flex flex-row gap-2 items-center justify-center w-full lg:w-fit p-4 lg:px-4 lg:py-2 rounded-2xl"
>
<Image
src={svg.xSecondary}
width="14"
height="14"
alt="xSecondary"
/>
<p className="text-[hsl(210,17%,98%)] font-medium text-xs">
Keluar
</p>
</button>
</div>
</div>
<div className="flex flex-col w-full h-auto gap-4 mt-4 lg:mt-8">
<div className="flex flex-col lg:flex-row items-center justify-center gap-2 w-full h-auto">
<div className="flex flex-row gap-2 items-center justify-start w-full lg:w-[60%] h-auto p-0 mt-0">
<Image
src={svg.calendarPlusDarken}
width="16"
height="16"
alt="calendarPlusDarken"
/>
<p className="text-[hsl(0,0%,13%)] font-medium text-xs text-start mt-0">
Ditambahkan Pada
</p>
</div>
<input
id="date_added"
{...register("date_added", { required: true })}
disabled={isLoading}
type="date"
placeholder="Masukkan Nama Obat .."
className="outline-none bg-transparent text-[hsl(0,0%,13%)] placeholder:text-[hsl(0,0%,13%)]/60 w-full font-light text-xs"
/>
</div>
<div className="flex flex-col lg:flex-row items-center justify-center gap-2 w-full h-auto">
<div className="flex flex-row gap-2 items-center justify-start w-full lg:w-[60%] h-auto p-0 mt-0">
<Image
src={svg.userDarken}
width="16"
height="16"
alt="userDarken"
/>
<p className="text-[hsl(0,0%,13%)] font-medium text-xs text-start mt-0">
Nama Pasien
</p>
</div>
<input
id="patient"
{...register("patient", { required: true })}
disabled={isLoading}
type="text"
placeholder="Masukkan Nama Pasien .."
className="outline-none bg-transparent text-[hsl(0,0%,13%)] placeholder:text-[hsl(0,0%,13%)]/60 w-full font-light text-xs"
/>
</div>
<div className="flex flex-col lg:flex-row items-center justify-center gap-2 w-full h-auto">
<div className="flex flex-row gap-2 items-center justify-start w-full lg:w-[60%] h-auto p-0 mt-0">
<Image
src={svg.pillDarken}
width="16"
height="16"
alt="pillDarken"
/>
<p className="text-[hsl(0,0%,13%)] font-medium text-xs text-start mt-0">
Obat
</p>
</div>
<input
id="medicine"
{...register("medicine", { required: true })}
disabled={isLoading}
type="text"
placeholder="Masukkan Nama Obat .."
className="outline-none bg-transparent text-[hsl(0,0%,13%)] placeholder:text-[hsl(0,0%,13%)]/60 w-full font-light text-xs"
/>
</div>
<div className="flex flex-col lg:flex-row items-center justify-center gap-2 w-full h-auto">
<div className="flex flex-row gap-2 items-center justify-start w-full lg:w-[60%] h-auto p-0 mt-0">
<Image
src={svg.vaccineBottleDarken}
width="16"
height="16"
alt="vaccineBottleDarken"
/>
<p className="text-[hsl(0,0%,13%)] font-medium text-xs text-start mt-0">
Dosis
</p>
</div>
<div className="flex flex-row gap-2 items-center justify-start w-full h-auto">
<input
id="dosage"
{...register("dosage", { required: true })}
disabled={isLoading}
type="number"
placeholder="Masukkan Dosis .."
className="outline-none bg-transparent text-[hsl(0,0%,13%)] placeholder:text-[hsl(0,0%,13%)]/60 w-full font-light text-xs"
/>
<select
id="dosage_unit"
{...register("dosage_unit", { required: true })}
disabled={isLoading}
className="outline-none bg-transparent text-[hsl(0,0%,13%)] placeholder:text-[hsl(0,0%,13%)]/60 w-full font-light text-xs"
>
<option>Pilih Satuan</option>
<option id="miligram">Miligram (mg)</option>
<option id="mikrogram">Mikrogram (µg)</option>
<option id="milliliter">
Milliliter (ml) atau Cubic Centimeter (cc)
</option>
<option id="unit">Unit (U)</option>
<option id="gram">Gram (g)</option>
<option id="international_unit">International Unit (IU)</option>
</select>
</div>
</div>
<div className="flex flex-col lg:flex-row items-center justify-center gap-2 w-full h-auto">
<div className="flex flex-row gap-2 items-center justify-start w-full lg:w-[60%] h-auto p-0 mt-0">
<Image
src={svg.bellPlusDarken}
width="16"
height="16"
alt="bellPlusDarken"
/>
<p className="text-[hsl(0,0%,13%)] font-medium text-xs text-start mt-0">
Penjadwalan
</p>
</div>
<select
id="schedule"
{...register("schedule", { required: true })}
disabled={isLoading}
className="outline-none bg-transparent text-[hsl(0,0%,13%)] placeholder:text-[hsl(0,0%,13%)]/60 w-full font-light text-xs"
>
<option>Pilih Penjadwalan</option>
<option id="one_time_in_a_day">1x Sehari</option>
<option id="two_time_in_a_day">2x Sehari</option>
<option id="three_time_in_a_day">3x Sehari</option>
<option id="one_time_in_a_week">1x Seminggu</option>
<option id="one_time_in_a_week">2x Seminggu</option>
<option id="one_time_in_a_week">3x Seminggu</option>
</select>
</div>
<div className="flex flex-col lg:flex-row items-center justify-center gap-2 w-full h-auto">
<div className="flex flex-row gap-2 items-center justify-start w-full lg:w-[60%] h-auto p-0 mt-0">
<Image
src={svg.checkupListDarken}
width="16"
height="16"
alt="checkupListDarken"
/>
<p className="text-[hsl(0,0%,13%)] font-medium text-xs text-start mt-0">
Keterangan
</p>
</div>
<input
id="notes"
{...register("notes", { required: false })}
disabled={isLoading}
type="text"
placeholder="(Opsional) Masukkan Keterangan .."
className="outline-none bg-transparent text-[hsl(0,0%,13%)] placeholder:text-[hsl(0,0%,13%)]/60 w-full font-light text-xs"
/>
</div>
</div>
</form>
);
};
export default ComponentAddProvider;
I just dont know what kind of npm modules to use, or if there’s anybody can help me to solve it?