mirror of
https://github.com/felipegcoutinho/openmonetis.git
synced 2026-06-10 07:16:01 +00:00
feat(preferencias): permite ocultar resumo do lancamento
This commit is contained in:
31
src/shared/components/providers/app-preferences-provider.tsx
Normal file
31
src/shared/components/providers/app-preferences-provider.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
"use client";
|
||||
|
||||
import { createContext, useContext } from "react";
|
||||
import type { AppPreferences } from "@/shared/lib/preferences/queries";
|
||||
|
||||
const DEFAULT_APP_PREFERENCES: AppPreferences = {
|
||||
showTransactionSummary: true,
|
||||
};
|
||||
|
||||
const AppPreferencesContext = createContext<AppPreferences>(
|
||||
DEFAULT_APP_PREFERENCES,
|
||||
);
|
||||
|
||||
type AppPreferencesProviderProps = AppPreferences & {
|
||||
children: React.ReactNode;
|
||||
};
|
||||
|
||||
export function AppPreferencesProvider({
|
||||
children,
|
||||
...preferences
|
||||
}: AppPreferencesProviderProps) {
|
||||
return (
|
||||
<AppPreferencesContext.Provider value={preferences}>
|
||||
{children}
|
||||
</AppPreferencesContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useAppPreferences() {
|
||||
return useContext(AppPreferencesContext);
|
||||
}
|
||||
24
src/shared/lib/preferences/queries.ts
Normal file
24
src/shared/lib/preferences/queries.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db, schema } from "@/shared/lib/db";
|
||||
|
||||
export type AppPreferences = {
|
||||
showTransactionSummary: boolean;
|
||||
};
|
||||
|
||||
const DEFAULT_APP_PREFERENCES: AppPreferences = {
|
||||
showTransactionSummary: true,
|
||||
};
|
||||
|
||||
export async function fetchAppPreferences(
|
||||
userId: string,
|
||||
): Promise<AppPreferences> {
|
||||
const [preferences] = await db
|
||||
.select({
|
||||
showTransactionSummary: schema.userPreferences.showTransactionSummary,
|
||||
})
|
||||
.from(schema.userPreferences)
|
||||
.where(eq(schema.userPreferences.userId, userId))
|
||||
.limit(1);
|
||||
|
||||
return preferences ?? DEFAULT_APP_PREFERENCES;
|
||||
}
|
||||
Reference in New Issue
Block a user