Skip to content

Commit

Permalink
Notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Nov 15, 2023
1 parent 4d28496 commit fc064ae
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 23 deletions.
17 changes: 1 addition & 16 deletions apps/dashboard/src/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
import { createClient } from "@midday/supabase/server";
import { Provider } from "./provider";

const ADMINS = [
"ec10c095-8cf7-4ba3-a62e-98f2a3d40c4c",
"7d723617-c2e1-4b71-8bf4-fb02479b264a",
"efea0311-0786-4f70-9b5a-63e3efa5d319",
"2f76981b-fc66-479c-8203-521a5a1f734a",
"3cb7ad12-907e-49c6-9f3a-ea3eeb1d34cf",
"71908de2-2727-43a8-8a3f-4ae203faa4c5",
"a9f6e6f2-8d58-4cf7-a3e7-312be3ee9560", // Ali Saheli
];

export default async function Layout({
dashboard,
login,
closed,

params: { locale },
}: {
dashboard: React.ReactNode;
login: React.ReactNode;
closed: React.ReactNode;
params: { locale: string };
}) {
const supabase = createClient();
Expand All @@ -28,9 +17,5 @@ export default async function Layout({
data: { session },
} = await supabase.auth.getSession();

if (session && !ADMINS.includes(session?.user?.id)) {
return closed;
}

return <Provider locale={locale}>{session ? dashboard : login}</Provider>;
}
6 changes: 3 additions & 3 deletions apps/dashboard/src/components/charts/bar-chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const ToolTipContent = ({ payload = {} }) => {
? current?.payload?.current?.date &&
`Week ${format(
new Date(current.payload.current.date),
"ww, Y",
"ww, Y"
)}`
: current?.payload?.current?.date &&
format(new Date(current.payload.current.date), "MMM, Y")}
Expand All @@ -79,7 +79,7 @@ const ToolTipContent = ({ payload = {} }) => {
? previous?.payload?.previous?.date &&
`Week ${format(
new Date(previous.payload.previous.date),
"ww, Y",
"ww, Y"
)}`
: previous?.payload?.previous?.date &&
format(new Date(previous.payload.previous.date), "MMM, Y")}
Expand All @@ -96,7 +96,7 @@ export function BarChart({ data }) {
meta: data.meta,
date: format(
new Date(item.date),
data.meta.period === "weekly" ? "w" : "MMM",
data.meta.period === "weekly" ? "w" : "MMM"
),
}));

Expand Down
4 changes: 2 additions & 2 deletions apps/dashboard/src/jobs/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const mapTransactionMethod = (method: string) => {

const transformTransactions = (transactions, { teamId, accountId }) =>
// We want to insert transactions in reversed order so the incremental id in supabase is correct
transactions.reverse().map((data) => ({
transactions?.reverse().map((data) => ({
transaction_id: data.transactionId,
reference: data.entryReference,
booking_date: data.bookingDate,
Expand Down Expand Up @@ -162,7 +162,7 @@ client.defineJob({
description: t(
{ id: "notifications.transaction" },
{
amount: Intl.NumberFormat(locale, {
amount: Intl.NumberFormat(user.locale, {
style: "currency",
currency: transaction.currency,
}).format(transaction.amount),
Expand Down
18 changes: 18 additions & 0 deletions apps/dashboard/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ const I18nMiddleware = createI18nMiddleware({
urlMappingStrategy: "rewrite",
});

const ADMINS = [
"ec10c095-8cf7-4ba3-a62e-98f2a3d40c4c",
"7d723617-c2e1-4b71-8bf4-fb02479b264a",
"efea0311-0786-4f70-9b5a-63e3efa5d319",
"2f76981b-fc66-479c-8203-521a5a1f734a",
"3cb7ad12-907e-49c6-9f3a-ea3eeb1d34cf",
"71908de2-2727-43a8-8a3f-4ae203faa4c5",
"a9f6e6f2-8d58-4cf7-a3e7-312be3ee9560", // Ali Saheli
];

export async function middleware(request: NextRequest) {
const response = I18nMiddleware(request);
const { supabase } = createClient(request, response);
Expand All @@ -18,6 +28,14 @@ export async function middleware(request: NextRequest) {
return NextResponse.redirect(new URL("/", request.url));
}

if (
data.session &&
!ADMINS.includes(data.session.user.id) &&
request.nextUrl.pathname !== "/closed"
) {
return NextResponse.redirect(new URL("/closed", request.url));
}

return response;
}

Expand Down
1 change: 1 addition & 0 deletions packages/supabase/src/queries/cached-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export const getMetrics = async (params) => {
["metrics", teamId],
{
tags: [`metrics_${teamId}`],
revalidate: 10,
}
)(params);
};
4 changes: 2 additions & 2 deletions packages/supabase/src/queries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,12 +441,12 @@ export async function getMetricsQuery(
return {
date: date.toDateString(),
previous: {
date: format(subYears(date, 1), "y-M-d"),
date: subYears(date, 1).toISOString(),
value: previousValue ?? 0,
currency: previous?.currency || data?.at(0)?.currency,
},
current: {
date: format(date, "y-M-d"),
date: date.toISOString(),
value: currentValue ?? 0,
currency: current?.currency || data?.at(0)?.currency,
},
Expand Down

0 comments on commit fc064ae

Please sign in to comment.