Skip to content

Commit

Permalink
Merge branch 'dev' into feat/product-grid-view-user-dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Maiqel1 authored Aug 1, 2024
2 parents 0afe811 + 520077d commit cf30506
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
} from "~/components/ui/card";
import { Switch } from "~/components/ui/switch";
import { cn } from "~/lib/utils";
import { useNotificationStore } from "../../admin/(settings)/settings/notification/action/notification-store";
import { notificationSettingsProperties } from "../../admin/(settings)/settings/notification/types/notification-settings.types";
import { useNotificationStore } from "../../admin/(settings)/settings/notification/_action/notification-store";
import { notificationSettingsProperties } from "../../admin/(settings)/settings/notification/_types/notification-settings.types";

interface NotificationPreview {
header: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import create from "zustand";

import { notificationSettingsProperties } from "../types/notification-settings.types";
import { notificationSettingsProperties } from "../_types/notification-settings.types";

// Define the Zustand store
interface NotificationStore {
settings: notificationSettingsProperties;
updateSettings: (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Switch } from "~/components/ui/switch";
import { notificationSettingsProperties } from "../types/notification-settings.types";
import { notificationSettingsProperties } from "../_types/notification-settings.types";

interface IProperties {
title: string;
description: string;
name: keyof notificationSettingsProperties;
isChecked: boolean;
onToggle: (name: keyof notificationSettingsProperties) => void;
className?: string; // Add className as an optional property
className?: string;
}

export const NotificationSwitchBox = ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,79 @@
"use client";

import axios from "axios";
import { Check, ChevronLeft } from "lucide-react";
import { getSession } from "next-auth/react";
import { useState } from "react";

import CustomButton from "~/components/common/common-button/common-button";
import NotificationSettingSavedModal from "~/components/common/modals/notification-settings-saved";
import { useToast } from "~/components/ui/use-toast";
import { getApiUrl } from "~/utils/getApiUrl";
import { useNotificationStore } from "./_action/notification-store";
import NotificationHeader from "./_components/header";
import { NotificationSwitchBox } from "./_components/notification-switch-box";
import { useNotificationStore } from "./action/notification-store";
import { notificationSettingsProperties } from "./_types/notification-settings.types";

const NotificationPage = () => {
const { settings, updateSettings } = useNotificationStore();
const [isOpen, setOpen] = useState(false);
const { toast } = useToast();

const saveNotificationSettings = async (
settings: notificationSettingsProperties,
) => {
const baseUrl = await getApiUrl();
const endpoint = "/api/v1/settings/notification-settings";
const url = `${baseUrl}${endpoint}`;

try {
const session = await getSession();
const token = session?.user?.access_token;

if (!token) {
toast({
title: "Error",
description: "No access token",
variant: "destructive",
});
}

const response = await axios.post(url, settings, {
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
});

if (response.status !== 200) {
toast({
title: "Error",
description: "Request failed",
variant: "destructive",
});
}
const data = response.data;
return data;
} catch {
toast({
title: "Error",
description: "Failed to save settings",
variant: "destructive",
});
}
};

const handleToggleSwitch = (name: keyof typeof settings) => {
updateSettings({ [name]: !settings[name] });
};

const handleSaveChanges = () => {
setOpen(true);
const handleSaveChanges = async () => {
try {
await saveNotificationSettings(settings);
setOpen(true);
} catch {
throw new Error("Failed to save settings");
}
};

return (
Expand Down Expand Up @@ -54,7 +109,7 @@ const NotificationPage = () => {
onToggle={handleToggleSwitch}
/>
<NotificationSwitchBox
title={"Activity in your workspace"}
title={"Always send email notifications"}
description={
"Receive emails about activity in your workspace, even when you are active on the app"
}
Expand Down

0 comments on commit cf30506

Please sign in to comment.