Skip to content

Commit

Permalink
internal users + auth
Browse files Browse the repository at this point in the history
  • Loading branch information
potts99 committed Nov 27, 2023
1 parent 948eefa commit 1b5fecd
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 278 deletions.
9 changes: 8 additions & 1 deletion apps/client/pages/admin/clients/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getCookie } from "cookies-next";
import Link from "next/link";
import { useRouter } from "next/router";
import React from "react";
Expand All @@ -13,7 +14,13 @@ import {

const fetchAllClients = async () => {
const res = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/api/v1/clients/all`
`${process.env.NEXT_PUBLIC_API_URL}/api/v1/clients/all`,
{
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${getCookie("session")}`,
},
}
);
return res.json();
};
Expand Down
4 changes: 4 additions & 0 deletions apps/client/pages/admin/clients/new.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { notifications } from "@mantine/notifications";
import { getCookie } from "cookies-next";
import { useRouter } from "next/router";
import { useState } from "react";

export default function CreateClientPage() {
const router = useRouter();

const token = getCookie("session");

const [number, setNumber] = useState("");
const [contactName, setContactName] = useState("");
const [name, setName] = useState("");
Expand All @@ -20,6 +23,7 @@ export default function CreateClientPage() {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + token,
},
body: JSON.stringify({
number,
Expand Down
14 changes: 8 additions & 6 deletions apps/client/pages/admin/email-queues/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { getCookie } from "cookies-next";
import Link from "next/link";
import { useEffect, useState } from "react";

export default function EmailQueues() {
const [queues, setQueues] = useState();

// fetch queues / display them
// create a new queue

async function fetchQueues() {
const res = await fetch("/api/v1/admin/email-queue/check").then((res) =>
res.json()
);
const res = await fetch("/api/v1/admin/email-queue/check", {
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + getCookie("session"),
},
}).then((res) => res.json());
setQueues(res.queues);
}

Expand All @@ -19,6 +20,7 @@ export default function EmailQueues() {
method: "post",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + getCookie("session"),
},
body: JSON.stringify({
id,
Expand Down
6 changes: 4 additions & 2 deletions apps/client/pages/admin/email-queues/new.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState, useEffect } from "react";
import { getCookie } from "cookies-next";
import { useRouter } from "next/router";
import { useState } from "react";

export default function EmailQueues() {
const router = useRouter();
Expand All @@ -15,6 +16,7 @@ export default function EmailQueues() {
method: "post",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + getCookie("session"),
},
body: JSON.stringify({
name,
Expand All @@ -26,7 +28,7 @@ export default function EmailQueues() {
})
.then((res) => res.json())
.then(() => {
// router.back();
router.back("/admin/email-queues");
});
}

Expand Down
258 changes: 0 additions & 258 deletions apps/client/pages/admin/settings.js

This file was deleted.

14 changes: 11 additions & 3 deletions apps/client/pages/admin/teams.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getCookie } from "cookies-next";
import React from "react";
import { useQuery } from "react-query";
import {
Expand Down Expand Up @@ -184,13 +185,20 @@ function Table({ columns, data }) {
);
}

const fetchAllTeams = async () => {
const res = await fetch("/api/v1/admin/team/all");
const fetchAllTeams = async (token) => {
const res = await fetch("/api/v1/admin/team/all", {
headers: {
Authorization: `Bearer ${token}`,
},
});
return res.json();
};

export default function Teams() {
const { data, status, refetch } = useQuery("fetchAllTeams", fetchAllTeams);
const token = getCookie("session");
const { data, status, refetch } = useQuery("fetchAllTeams", () =>
fetchAllTeams(token)
);

// async function deleteClient(id) {
// try {
Expand Down
Loading

0 comments on commit 1b5fecd

Please sign in to comment.