Merge branch 'develop' into feature/MED-129

This commit is contained in:
Danel Kungla
2025-09-24 15:00:27 +03:00
622 changed files with 19603 additions and 10824 deletions

View File

@@ -1,3 +0,0 @@
import eslintConfigBase from '@kit/eslint-config/base.js';
export default eslintConfigBase;

View File

@@ -4,16 +4,11 @@
"version": "0.1.0",
"scripts": {
"clean": "git clean -xdf .turbo node_modules",
"format": "prettier --check \"**/*.{ts,tsx}\"",
"lint": "eslint .",
"typecheck": "tsc --noEmit"
},
"prettier": "@kit/prettier-config",
"devDependencies": {
"@hookform/resolvers": "^5.0.1",
"@kit/eslint-config": "workspace:*",
"@kit/next": "workspace:*",
"@kit/prettier-config": "workspace:*",
"@kit/shared": "workspace:*",
"@kit/supabase": "workspace:*",
"@kit/tsconfig": "workspace:*",

View File

@@ -170,6 +170,7 @@ async function TeamAccountPage(props: {
<>
<PageHeader
className="border-b"
title={'Account'}
description={
<AppBreadcrumbs
values={{

View File

@@ -48,7 +48,7 @@ export function AdminCreateUserDialog(props: React.PropsWithChildren) {
email: '',
password: '',
emailConfirm: false,
personalCode: ''
personalCode: '',
},
mode: 'onBlur',
});
@@ -163,7 +163,7 @@ export function AdminCreateUserDialog(props: React.PropsWithChildren) {
<FormField
name={'emailConfirm'}
render={({ field }) => (
<FormItem className="flex flex-row items-start space-x-3 space-y-0 rounded-md border p-4">
<FormItem className="flex flex-row items-start space-y-0 space-x-3 rounded-md border p-4">
<FormControl>
<Checkbox
checked={field.value}

View File

@@ -18,8 +18,8 @@ export async function AdminDashboard() {
' xl:grid-cols-4'
}
>
<Card>
<CardHeader>
<Card className="flex flex-col">
<CardHeader className="flex-1">
<CardTitle>Users</CardTitle>
<CardDescription>
@@ -34,8 +34,8 @@ export async function AdminDashboard() {
</CardContent>
</Card>
<Card>
<CardHeader>
<Card className="flex flex-col">
<CardHeader className="flex-1">
<CardTitle>Company Accounts</CardTitle>
<CardDescription>

View File

@@ -4,6 +4,7 @@ import Link from 'next/link';
import { ColumnDef } from '@tanstack/react-table';
import { formatDateAndTime } from '@kit/shared/utils';
import { Database } from '@kit/supabase/database';
import { DataTable } from '@kit/ui/enhanced-data-table';
import { ProfileAvatar } from '@kit/ui/profile-avatar';
@@ -17,10 +18,6 @@ export function AdminMembersTable(props: { members: Memberships[] }) {
function getColumns(): ColumnDef<Memberships>[] {
return [
{
header: 'User ID',
accessorKey: 'user_id',
},
{
header: 'Name',
cell: ({ row }) => {
@@ -58,10 +55,16 @@ function getColumns(): ColumnDef<Memberships>[] {
{
header: 'Created At',
accessorKey: 'created_at',
cell: ({ row }) => {
return formatDateAndTime(row.original.created_at);
},
},
{
header: 'Updated At',
accessorKey: 'updated_at',
cell: ({ row }) => {
return formatDateAndTime(row.original.updated_at);
},
},
];
}

View File

@@ -148,12 +148,17 @@ export const deleteAccountAction = adminAction(
}
const medusa = getAdminSdk();
const { customer_groups } = await medusa.admin.customerGroup.list();
const customerGroup = customer_groups.find(({ name }) => name === customerGroupName);
const customerGroup = customer_groups.find(
({ name }) => name === customerGroupName,
);
if (customerGroup) {
try {
await medusa.admin.customerGroup.delete(customerGroup.id);
} catch (e) {
logger.error({ accountId }, `Error deleting Medusa customer group for company ${customerGroupName}`);
logger.error(
{ accountId },
`Error deleting Medusa customer group for company ${customerGroupName}`,
);
throw e;
}
}
@@ -288,22 +293,29 @@ export const createCompanyAccountAction = enhanceAction(
logger.info(ctx, `Creating Medusa customer group`);
const medusa = getAdminSdk();
const { customer_groups: existingCustomerGroups } = await medusa.admin.customerGroup.list();
const isExisting = existingCustomerGroups.find((group) => group.name === name);
const { customer_groups: existingCustomerGroups } =
await medusa.admin.customerGroup.list();
const isExisting = existingCustomerGroups.find(
(group) => group.name === name,
);
if (isExisting) {
logger.info(ctx, `Customer group already exists`);
} else {
logger.info(ctx, `Creating Medusa customer group`);
const { data: account } = await client
.schema('medreport').from('accounts')
.schema('medreport')
.from('accounts')
.select('medusa_account_id')
.eq('personal_code', ownerPersonalCode)
.single().throwOnError();
.single()
.throwOnError();
const medusaAccountId = account.medusa_account_id;
if (!medusaAccountId) {
logger.error(ctx, `User has no Medusa account ID`);
} else {
const { customer_group: { id: customerGroupId } } = await medusa.admin.customerGroup.create({ name });
const {
customer_group: { id: customerGroupId },
} = await medusa.admin.customerGroup.create({ name });
const { customers } = await medusa.admin.customer.list({
id: medusaAccountId,
});
@@ -316,7 +328,6 @@ export const createCompanyAccountAction = enhanceAction(
});
}
}
}
redirect(`/admin/accounts/${data.id}`);

View File

@@ -1,10 +1,13 @@
import { z } from 'zod';
export const CreateUserProfileSchema = z.object({
personalCode: z.string().regex(/^[1-6]\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}\d$/, {
message: 'Invalid Estonian personal code format',
}),
personalCode: z
.string()
.regex(/^[1-6]\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}\d$/, {
message: 'Invalid Estonian personal code format',
}),
});
export type CreateUserProfileSchemaType = z.infer<typeof CreateUserProfileSchema>;
export type CreateUserProfileSchemaType = z.infer<
typeof CreateUserProfileSchema
>;

View File

@@ -1,9 +1,11 @@
import { z } from 'zod';
export const CreateUserSchema = z.object({
personalCode: z.string().regex(/^[1-6]\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}\d$/, {
message: 'Invalid Estonian personal code format',
}),
personalCode: z
.string()
.regex(/^[1-6]\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}\d$/, {
message: 'Invalid Estonian personal code format',
}),
email: z.string().email({ message: 'Please enter a valid email address' }),
password: z
.string()

View File

@@ -44,7 +44,8 @@ class AdminAccountsService {
.from('accounts')
.select('*')
.eq('id', accountId)
.single().throwOnError();
.single()
.throwOnError();
return data;
}

View File

@@ -1,8 +1,9 @@
import Medusa from "@medusajs/js-sdk"
import Medusa from '@medusajs/js-sdk';
export const getAdminSdk = () => {
const medusaBackendUrl = process.env.MEDUSA_BACKEND_PUBLIC_URL!;
const medusaPublishableApiKey = process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY!;
const medusaPublishableApiKey =
process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY!;
const key = process.env.MEDUSA_SECRET_API_KEY!;
if (!medusaBackendUrl || !medusaPublishableApiKey) {
@@ -13,4 +14,4 @@ export const getAdminSdk = () => {
debug: process.env.NODE_ENV === 'development',
apiKey: key,
});
}
};

View File

@@ -4,7 +4,5 @@
"tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json"
},
"include": ["*.ts", "src"],
"exclude": [
"node_modules"
]
"exclude": ["node_modules"]
}