Refactor admin dashboard loader and update translations
The admin-dashboard.loader file was refactored to use a newly created AdminDashboardService. This service encapsulates the logic for fetching dashboard data. Translations related to account settings, privacy policy, terms of service, and cookie policy were updated for better readability. Changes also include minor reorganizing of code files for clearer structure.
This commit is contained in:
@@ -2,7 +2,7 @@ import { notFound } from 'next/navigation';
|
||||
|
||||
import { getSupabaseServerComponentClient } from '@kit/supabase/server-component-client';
|
||||
|
||||
import { isSuperAdmin } from '../lib/server/is-super-admin';
|
||||
import { isSuperAdmin } from '../lib/server/utils/is-super-admin';
|
||||
|
||||
type LayoutOrPageComponent<Params> = React.ComponentType<Params>;
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
export * from './lib/server/is-super-admin';
|
||||
export * from './lib/server/utils/is-super-admin';
|
||||
|
||||
@@ -6,7 +6,6 @@ import { redirect } from 'next/navigation';
|
||||
import { enhanceAction } from '@kit/next/actions';
|
||||
import { getSupabaseServerActionClient } from '@kit/supabase/server-actions-client';
|
||||
|
||||
import { adminAction } from './admin-action';
|
||||
import {
|
||||
BanUserSchema,
|
||||
DeleteAccountSchema,
|
||||
@@ -16,6 +15,7 @@ import {
|
||||
} from './schema/admin-actions.schema';
|
||||
import { AdminAccountsService } from './services/admin-accounts.service';
|
||||
import { AdminAuthUserService } from './services/admin-auth-user.service';
|
||||
import { adminAction } from './utils/admin-action';
|
||||
|
||||
/**
|
||||
* @name banUserAction
|
||||
|
||||
@@ -1,58 +1,19 @@
|
||||
import 'server-only';
|
||||
|
||||
import { cache } from 'react';
|
||||
|
||||
import { getSupabaseServerComponentClient } from '@kit/supabase/server-component-client';
|
||||
|
||||
import { AdminDashboardService } from '../services/admin-dashboard.service';
|
||||
|
||||
/**
|
||||
* @name loadAdminDashboard
|
||||
* @description Load the admin dashboard data.
|
||||
* @param params
|
||||
*/
|
||||
export async function loadAdminDashboard(params?: {
|
||||
count: 'exact' | 'estimated' | 'planned';
|
||||
}) {
|
||||
const count = params?.count ?? 'estimated';
|
||||
export const loadAdminDashboard = cache(() => {
|
||||
const client = getSupabaseServerComponentClient({ admin: true });
|
||||
const service = new AdminDashboardService(client);
|
||||
|
||||
const selectParams = {
|
||||
count,
|
||||
head: true,
|
||||
};
|
||||
|
||||
const subscriptionsPromise = client
|
||||
.from('subscriptions')
|
||||
.select('*', selectParams)
|
||||
.eq('status', 'active')
|
||||
.then((response) => response.count);
|
||||
|
||||
const trialsPromise = client
|
||||
.from('subscriptions')
|
||||
.select('*', selectParams)
|
||||
.eq('status', 'trialing')
|
||||
.then((response) => response.count);
|
||||
|
||||
const accountsPromise = client
|
||||
.from('accounts')
|
||||
.select('*', selectParams)
|
||||
.eq('is_personal_account', true)
|
||||
.then((response) => response.count);
|
||||
|
||||
const teamAccountsPromise = client
|
||||
.from('accounts')
|
||||
.select('*', selectParams)
|
||||
.eq('is_personal_account', false)
|
||||
.then((response) => response.count);
|
||||
|
||||
const [subscriptions, trials, accounts, teamAccounts] = await Promise.all([
|
||||
subscriptionsPromise,
|
||||
trialsPromise,
|
||||
accountsPromise,
|
||||
teamAccountsPromise,
|
||||
]);
|
||||
|
||||
return {
|
||||
subscriptions,
|
||||
trials,
|
||||
accounts,
|
||||
teamAccounts,
|
||||
};
|
||||
}
|
||||
return service.getDashboardData();
|
||||
});
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
import { SupabaseClient } from '@supabase/supabase-js';
|
||||
|
||||
import { Database } from '@kit/supabase/database';
|
||||
|
||||
export class AdminDashboardService {
|
||||
constructor(private readonly client: SupabaseClient<Database>) {}
|
||||
|
||||
async getDashboardData(
|
||||
{ count }: { count: 'exact' | 'estimated' | 'planned' } = {
|
||||
count: 'estimated',
|
||||
},
|
||||
) {
|
||||
const selectParams = {
|
||||
count,
|
||||
head: true,
|
||||
};
|
||||
|
||||
const subscriptionsPromise = this.client
|
||||
.from('subscriptions')
|
||||
.select('*', selectParams)
|
||||
.eq('status', 'active')
|
||||
.then((response) => {
|
||||
if (response.error) {
|
||||
throw new Error(response.error.message);
|
||||
}
|
||||
|
||||
return response.count;
|
||||
});
|
||||
|
||||
const trialsPromise = this.client
|
||||
.from('subscriptions')
|
||||
.select('*', selectParams)
|
||||
.eq('status', 'trialing')
|
||||
.then((response) => {
|
||||
if (response.error) {
|
||||
throw new Error(response.error.message);
|
||||
}
|
||||
|
||||
return response.count;
|
||||
});
|
||||
|
||||
const accountsPromise = this.client
|
||||
.from('accounts')
|
||||
.select('*', selectParams)
|
||||
.eq('is_personal_account', true)
|
||||
.then((response) => {
|
||||
if (response.error) {
|
||||
throw new Error(response.error.message);
|
||||
}
|
||||
|
||||
return response.count;
|
||||
});
|
||||
|
||||
const teamAccountsPromise = this.client
|
||||
.from('accounts')
|
||||
.select('*', selectParams)
|
||||
.eq('is_personal_account', false)
|
||||
.then((response) => {
|
||||
if (response.error) {
|
||||
throw new Error(response.error.message);
|
||||
}
|
||||
|
||||
return response.count;
|
||||
});
|
||||
|
||||
const [subscriptions, trials, accounts, teamAccounts] = await Promise.all([
|
||||
subscriptionsPromise,
|
||||
trialsPromise,
|
||||
accountsPromise,
|
||||
teamAccountsPromise,
|
||||
]);
|
||||
|
||||
return {
|
||||
subscriptions,
|
||||
trials,
|
||||
accounts,
|
||||
teamAccounts,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user