Use eslint config for whole project
Add eslint
This commit is contained in:
1
.npmrc
1
.npmrc
@@ -3,6 +3,7 @@ dedupe-peer-dependents=true
|
|||||||
use-lockfile-v6=true
|
use-lockfile-v6=true
|
||||||
resolution-mode=highest
|
resolution-mode=highest
|
||||||
package-manager-strict=true
|
package-manager-strict=true
|
||||||
|
ignore-workspace-root-check=true
|
||||||
public-hoist-pattern[]=*i18next*
|
public-hoist-pattern[]=*i18next*
|
||||||
public-hoist-pattern[]=*eslint*
|
public-hoist-pattern[]=*eslint*
|
||||||
public-hoist-pattern[]=*prettier*
|
public-hoist-pattern[]=*prettier*
|
||||||
|
|||||||
12
README.md
12
README.md
@@ -47,6 +47,18 @@ if you get missing dependency error do `pnpm i --force`
|
|||||||
pnpm add <pacakge-name> -w
|
pnpm add <pacakge-name> -w
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Eslint and prettier
|
||||||
|
|
||||||
|
To clean code run
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run lint:fix
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run prettier:fix
|
||||||
|
```
|
||||||
|
|
||||||
## Supabase
|
## Supabase
|
||||||
|
|
||||||
Start supabase in docker
|
Start supabase in docker
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { SitePageHeader } from '~/(marketing)/_components/site-page-header';
|
|||||||
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
|
|
||||||
|
|
||||||
export async function generateMetadata() {
|
export async function generateMetadata() {
|
||||||
const { t } = await createI18nServerInstance();
|
const { t } = await createI18nServerInstance();
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { SitePageHeader } from '~/(marketing)/_components/site-page-header';
|
|||||||
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
|
|
||||||
|
|
||||||
export async function generateMetadata() {
|
export async function generateMetadata() {
|
||||||
const { t } = await createI18nServerInstance();
|
const { t } = await createI18nServerInstance();
|
||||||
|
|
||||||
|
|||||||
@@ -7,15 +7,14 @@ import { UserWorkspace } from '@/app/home/(user)/_lib/server/load-user-workspace
|
|||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
|
||||||
import { PersonalAccountDropdown } from '@kit/accounts/personal-account-dropdown';
|
import { PersonalAccountDropdown } from '@kit/accounts/personal-account-dropdown';
|
||||||
|
import { featureFlagsConfig, pathsConfig } from '@kit/shared/config';
|
||||||
|
import { useAuthConfig } from '@kit/shared/hooks';
|
||||||
import { useSignOut } from '@kit/supabase/hooks/use-sign-out';
|
import { useSignOut } from '@kit/supabase/hooks/use-sign-out';
|
||||||
import { useSupabase } from '@kit/supabase/hooks/use-supabase';
|
import { useSupabase } from '@kit/supabase/hooks/use-supabase';
|
||||||
import { Button } from '@kit/ui/button';
|
import { Button } from '@kit/ui/button';
|
||||||
import { If } from '@kit/ui/if';
|
import { If } from '@kit/ui/if';
|
||||||
import { Trans } from '@kit/ui/trans';
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
import { featureFlagsConfig, pathsConfig } from '@kit/shared/config';
|
|
||||||
import { useAuthConfig } from '@kit/shared/hooks';
|
|
||||||
|
|
||||||
const ModeToggle = dynamic(() =>
|
const ModeToggle = dynamic(() =>
|
||||||
import('@kit/ui/mode-toggle').then((mod) => ({
|
import('@kit/ui/mode-toggle').then((mod) => ({
|
||||||
default: mod.ModeToggle,
|
default: mod.ModeToggle,
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import { UserWorkspace } from '@/app/home/(user)/_lib/server/load-user-workspace';
|
import { UserWorkspace } from '@/app/home/(user)/_lib/server/load-user-workspace';
|
||||||
|
|
||||||
import { Header } from '@kit/ui/marketing';
|
|
||||||
|
|
||||||
import { AppLogo } from '@kit/shared/components/app-logo';
|
import { AppLogo } from '@kit/shared/components/app-logo';
|
||||||
|
import { Header } from '@kit/ui/marketing';
|
||||||
|
|
||||||
import { SiteHeaderAccountSection } from './site-header-account-section';
|
import { SiteHeaderAccountSection } from './site-header-account-section';
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import { createCmsClient } from '@kit/cms';
|
|||||||
|
|
||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
|
|
||||||
|
|
||||||
import { Post } from '../../blog/_components/post';
|
import { Post } from '../../blog/_components/post';
|
||||||
|
|
||||||
interface BlogPageProps {
|
interface BlogPageProps {
|
||||||
|
|||||||
@@ -11,14 +11,16 @@ const contactEmail = z
|
|||||||
.string({
|
.string({
|
||||||
error:
|
error:
|
||||||
'Contact email is required. Please use the environment variable CONTACT_EMAIL.',
|
'Contact email is required. Please use the environment variable CONTACT_EMAIL.',
|
||||||
}).describe(`The email where you want to receive the contact form submissions.`)
|
})
|
||||||
|
.describe(`The email where you want to receive the contact form submissions.`)
|
||||||
.parse(process.env.CONTACT_EMAIL);
|
.parse(process.env.CONTACT_EMAIL);
|
||||||
|
|
||||||
const emailFrom = z
|
const emailFrom = z
|
||||||
.string({
|
.string({
|
||||||
error:
|
error:
|
||||||
'Sender email is required. Please use the environment variable EMAIL_SENDER.',
|
'Sender email is required. Please use the environment variable EMAIL_SENDER.',
|
||||||
}).describe(`The email sending address.`)
|
})
|
||||||
|
.describe(`The email sending address.`)
|
||||||
.parse(process.env.EMAIL_SENDER);
|
.parse(process.env.EMAIL_SENDER);
|
||||||
|
|
||||||
export const sendContactEmail = enhanceAction(
|
export const sendContactEmail = enhanceAction(
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import { ContactForm } from '~/(marketing)/contact/_components/contact-form';
|
|||||||
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
|
|
||||||
|
|
||||||
export async function generateMetadata() {
|
export async function generateMetadata() {
|
||||||
const { t } = await createI18nServerInstance();
|
const { t } = await createI18nServerInstance();
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import { SitePageHeader } from '~/(marketing)/_components/site-page-header';
|
|||||||
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
|
|
||||||
|
|
||||||
export const generateMetadata = async () => {
|
export const generateMetadata = async () => {
|
||||||
const { t } = await createI18nServerInstance();
|
const { t } = await createI18nServerInstance();
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,8 @@ import { use } from 'react';
|
|||||||
|
|
||||||
import { SiteFooter } from '~/(marketing)/_components/site-footer';
|
import { SiteFooter } from '~/(marketing)/_components/site-footer';
|
||||||
import { SiteHeader } from '~/(marketing)/_components/site-header';
|
import { SiteHeader } from '~/(marketing)/_components/site-header';
|
||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
|
||||||
|
|
||||||
import { loadCurrentUserAccounts } from '~/home/(user)/_lib/server/load-accounts';
|
import { loadCurrentUserAccounts } from '~/home/(user)/_lib/server/load-accounts';
|
||||||
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
|
|
||||||
function SiteLayout(props: React.PropsWithChildren) {
|
function SiteLayout(props: React.PropsWithChildren) {
|
||||||
const accounts = use(loadCurrentUserAccounts());
|
const accounts = use(loadCurrentUserAccounts());
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
|
|
||||||
|
import { ArrowRightIcon } from 'lucide-react';
|
||||||
|
|
||||||
import { MedReportLogo } from '@kit/shared/components/med-report-logo';
|
import { MedReportLogo } from '@kit/shared/components/med-report-logo';
|
||||||
import { pathsConfig } from '@kit/shared/config';
|
import { pathsConfig } from '@kit/shared/config';
|
||||||
import { ArrowRightIcon } from 'lucide-react';
|
|
||||||
|
|
||||||
import { CtaButton, Hero } from '@kit/ui/marketing';
|
import { CtaButton, Hero } from '@kit/ui/marketing';
|
||||||
import { Trans } from '@kit/ui/trans';
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { MedReportLogo } from '@kit/shared/components/med-report-logo';
|
import { MedReportLogo } from '@kit/shared/components/med-report-logo';
|
||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
|
||||||
import { Trans } from '@kit/ui/trans';
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
|
|
||||||
import CompanyOfferForm from './_components/company-offer-form';
|
import CompanyOfferForm from './_components/company-offer-form';
|
||||||
|
|
||||||
function CompanyOffer() {
|
function CompanyOffer() {
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
|
|
||||||
|
|
||||||
function SiteLayout(props: React.PropsWithChildren) {
|
function SiteLayout(props: React.PropsWithChildren) {
|
||||||
return (
|
return (
|
||||||
<div className={'flex min-h-[100vh] flex-col justify-center items-center'}>
|
<div className={'flex min-h-[100vh] flex-col items-center justify-center'}>
|
||||||
{props.children}
|
{props.children}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import { usePathname } from 'next/navigation';
|
|||||||
import { UserWorkspace } from '@/app/home/(user)/_lib/server/load-user-workspace';
|
import { UserWorkspace } from '@/app/home/(user)/_lib/server/load-user-workspace';
|
||||||
import { LayoutDashboard, Users } from 'lucide-react';
|
import { LayoutDashboard, Users } from 'lucide-react';
|
||||||
|
|
||||||
|
import { AppLogo } from '@kit/shared/components/app-logo';
|
||||||
|
import { ProfileAccountDropdownContainer } from '@kit/shared/components/personal-account-dropdown-container';
|
||||||
import {
|
import {
|
||||||
Sidebar,
|
Sidebar,
|
||||||
SidebarContent,
|
SidebarContent,
|
||||||
@@ -19,9 +21,6 @@ import {
|
|||||||
useSidebar,
|
useSidebar,
|
||||||
} from '@kit/ui/shadcn-sidebar';
|
} from '@kit/ui/shadcn-sidebar';
|
||||||
|
|
||||||
import { AppLogo } from '@kit/shared/components/app-logo';
|
|
||||||
import { ProfileAccountDropdownContainer } from '@kit/shared/components/personal-account-dropdown-container';
|
|
||||||
|
|
||||||
export function AdminSidebar({
|
export function AdminSidebar({
|
||||||
accounts,
|
accounts,
|
||||||
}: {
|
}: {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { cache } from 'react';
|
|||||||
|
|
||||||
import { AdminAccountPage } from '@kit/admin/components/admin-account-page';
|
import { AdminAccountPage } from '@kit/admin/components/admin-account-page';
|
||||||
import { AdminGuard } from '@kit/admin/components/admin-guard';
|
import { AdminGuard } from '@kit/admin/components/admin-guard';
|
||||||
|
|
||||||
import { getAccount } from '~/lib/services/account.service';
|
import { getAccount } from '~/lib/services/account.service';
|
||||||
|
|
||||||
interface Params {
|
interface Params {
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import { getPlanTypesMap } from '@kit/billing';
|
import { getPlanTypesMap } from '@kit/billing';
|
||||||
import { getBillingEventHandlerService } from '@kit/billing-gateway';
|
import { getBillingEventHandlerService } from '@kit/billing-gateway';
|
||||||
import { enhanceRouteHandler } from '@kit/next/routes';
|
import { enhanceRouteHandler } from '@kit/next/routes';
|
||||||
|
import { billingConfig } from '@kit/shared/config';
|
||||||
import { getLogger } from '@kit/shared/logger';
|
import { getLogger } from '@kit/shared/logger';
|
||||||
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
||||||
|
|
||||||
import { billingConfig } from '@kit/shared/config';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Handle the webhooks from Stripe related to checkouts
|
* @description Handle the webhooks from Stripe related to checkouts
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -2,7 +2,11 @@ import { config } from 'dotenv';
|
|||||||
|
|
||||||
export default function loadEnv() {
|
export default function loadEnv() {
|
||||||
config({ path: `.env` });
|
config({ path: `.env` });
|
||||||
if (['local', 'test', 'development', 'production'].includes(process.env.NODE_ENV!)) {
|
if (
|
||||||
|
['local', 'test', 'development', 'production'].includes(
|
||||||
|
process.env.NODE_ENV!,
|
||||||
|
)
|
||||||
|
) {
|
||||||
config({ path: `.env.${process.env.NODE_ENV}` });
|
config({ path: `.env.${process.env.NODE_ENV}` });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
import Medusa from "@medusajs/js-sdk"
|
import { listProductTypes } from '@lib/data/products';
|
||||||
import type { AdminProductCategory } from "@medusajs/types";
|
import Medusa from '@medusajs/js-sdk';
|
||||||
import { listProductTypes } from "@lib/data/products";
|
import type { AdminProductCategory } from '@medusajs/types';
|
||||||
import { getAnalysisElements } from "~/lib/services/analysis-element.service";
|
|
||||||
import { getAnalysisGroups } from "~/lib/services/analysis-group.service";
|
import {
|
||||||
import { createMedusaSyncFailEntry, createMedusaSyncSuccessEntry } from "~/lib/services/analyses.service";
|
createMedusaSyncFailEntry,
|
||||||
|
createMedusaSyncSuccessEntry,
|
||||||
|
} from '~/lib/services/analyses.service';
|
||||||
|
import { getAnalysisElements } from '~/lib/services/analysis-element.service';
|
||||||
|
import { getAnalysisGroups } from '~/lib/services/analysis-group.service';
|
||||||
|
|
||||||
const SYNLAB_SERVICES_CATEGORY_HANDLE = 'synlab-services';
|
const SYNLAB_SERVICES_CATEGORY_HANDLE = 'synlab-services';
|
||||||
const SYNLAB_ANALYSIS_PRODUCT_TYPE_HANDLE = 'synlab-analysis';
|
const SYNLAB_ANALYSIS_PRODUCT_TYPE_HANDLE = 'synlab-analysis';
|
||||||
@@ -12,7 +16,8 @@ const BASE_ANALYSIS_PRODUCT_HANDLE = 'analysis-base';
|
|||||||
|
|
||||||
const getAdminSdk = () => {
|
const getAdminSdk = () => {
|
||||||
const medusaBackendUrl = process.env.MEDUSA_BACKEND_PUBLIC_URL!;
|
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!;
|
const key = process.env.MEDUSA_SECRET_API_KEY!;
|
||||||
|
|
||||||
if (!medusaBackendUrl || !medusaPublishableApiKey) {
|
if (!medusaBackendUrl || !medusaPublishableApiKey) {
|
||||||
@@ -23,15 +28,14 @@ const getAdminSdk = () => {
|
|||||||
debug: process.env.NODE_ENV === 'development',
|
debug: process.env.NODE_ENV === 'development',
|
||||||
apiKey: key,
|
apiKey: key,
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
async function createProductCategories({
|
async function createProductCategories({ medusa }: { medusa: Medusa }) {
|
||||||
medusa,
|
const { product_categories: existingProductCategories } =
|
||||||
}: {
|
await medusa.admin.productCategory.list();
|
||||||
medusa: Medusa;
|
const parentCategory = existingProductCategories.find(
|
||||||
}) {
|
({ handle }) => handle === SYNLAB_SERVICES_CATEGORY_HANDLE,
|
||||||
const { product_categories: existingProductCategories } = await medusa.admin.productCategory.list();
|
);
|
||||||
const parentCategory = existingProductCategories.find(({ handle }) => handle === SYNLAB_SERVICES_CATEGORY_HANDLE);
|
|
||||||
|
|
||||||
if (!parentCategory) {
|
if (!parentCategory) {
|
||||||
throw new Error('Parent category not found');
|
throw new Error('Parent category not found');
|
||||||
@@ -46,8 +50,12 @@ async function createProductCategories({
|
|||||||
for (const analysisGroup of analysisGroups) {
|
for (const analysisGroup of analysisGroups) {
|
||||||
console.info(`Processing analysis group '${analysisGroup.name}'`);
|
console.info(`Processing analysis group '${analysisGroup.name}'`);
|
||||||
|
|
||||||
const isExisting = existingProductCategories.find(({ name }) => name === analysisGroup.name);
|
const isExisting = existingProductCategories.find(
|
||||||
const isNewlyCreated = createdCategories.find(({ name }) => name === analysisGroup.name);
|
({ name }) => name === analysisGroup.name,
|
||||||
|
);
|
||||||
|
const isNewlyCreated = createdCategories.find(
|
||||||
|
({ name }) => name === analysisGroup.name,
|
||||||
|
);
|
||||||
if (isExisting || isNewlyCreated) {
|
if (isExisting || isNewlyCreated) {
|
||||||
console.info(`Analysis group '${analysisGroup.name}' already exists`);
|
console.info(`Analysis group '${analysisGroup.name}' already exists`);
|
||||||
continue;
|
continue;
|
||||||
@@ -63,18 +71,19 @@ async function createProductCategories({
|
|||||||
analysisGroupId: analysisGroup.id,
|
analysisGroupId: analysisGroup.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
console.info(`Successfully created category, id=${createResponse.product_category.id}`);
|
console.info(
|
||||||
|
`Successfully created category, id=${createResponse.product_category.id}`,
|
||||||
|
);
|
||||||
createdCategories.push(createResponse.product_category);
|
createdCategories.push(createResponse.product_category);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getChildProductCategories({
|
async function getChildProductCategories({ medusa }: { medusa: Medusa }) {
|
||||||
medusa,
|
const { product_categories: allCategories } =
|
||||||
}: {
|
await medusa.admin.productCategory.list();
|
||||||
medusa: Medusa;
|
const childCategories = allCategories.filter(
|
||||||
}) {
|
({ parent_category_id }) => parent_category_id !== null,
|
||||||
const { product_categories: allCategories } = await medusa.admin.productCategory.list();
|
);
|
||||||
const childCategories = allCategories.filter(({ parent_category_id }) => parent_category_id !== null);
|
|
||||||
return childCategories;
|
return childCategories;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,34 +102,34 @@ async function deleteProductCategories({
|
|||||||
/**
|
/**
|
||||||
* In case a reset is needed
|
* In case a reset is needed
|
||||||
*/
|
*/
|
||||||
async function deleteProducts({
|
async function deleteProducts({ medusa }: { medusa: Medusa }) {
|
||||||
medusa,
|
|
||||||
}: {
|
|
||||||
medusa: Medusa;
|
|
||||||
}) {
|
|
||||||
const { products: existingProducts } = await medusa.admin.product.list({
|
const { products: existingProducts } = await medusa.admin.product.list({
|
||||||
fields: 'id,collection_id',
|
fields: 'id,collection_id',
|
||||||
limit: 1000,
|
limit: 1000,
|
||||||
});
|
});
|
||||||
|
|
||||||
await Promise.all(existingProducts.filter((a) => !a.collection_id).map(({ id }) => medusa.admin.product.delete(id)));
|
await Promise.all(
|
||||||
|
existingProducts
|
||||||
|
.filter((a) => !a.collection_id)
|
||||||
|
.map(({ id }) => medusa.admin.product.delete(id)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getAnalysisPackagesType() {
|
async function getAnalysisPackagesType() {
|
||||||
const { productTypes } = await listProductTypes();
|
const { productTypes } = await listProductTypes();
|
||||||
const analysisPackagesType = productTypes.find(({ metadata }) => metadata?.handle === SYNLAB_ANALYSIS_PRODUCT_TYPE_HANDLE);
|
const analysisPackagesType = productTypes.find(
|
||||||
|
({ metadata }) => metadata?.handle === SYNLAB_ANALYSIS_PRODUCT_TYPE_HANDLE,
|
||||||
|
);
|
||||||
if (!analysisPackagesType) {
|
if (!analysisPackagesType) {
|
||||||
throw new Error('Synlab analysis packages type not found');
|
throw new Error('Synlab analysis packages type not found');
|
||||||
}
|
}
|
||||||
return analysisPackagesType;
|
return analysisPackagesType;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getProductDefaultFields({
|
async function getProductDefaultFields({ medusa }: { medusa: Medusa }) {
|
||||||
medusa,
|
const baseProductsResponse = await medusa.admin.product.list({
|
||||||
}: {
|
handle: BASE_ANALYSIS_PRODUCT_HANDLE,
|
||||||
medusa: Medusa;
|
});
|
||||||
}) {
|
|
||||||
const baseProductsResponse = await medusa.admin.product.list({ handle: BASE_ANALYSIS_PRODUCT_HANDLE })
|
|
||||||
const baseProduct = baseProductsResponse.products[0];
|
const baseProduct = baseProductsResponse.products[0];
|
||||||
if (!baseProduct) {
|
if (!baseProduct) {
|
||||||
throw new Error('Base product not found');
|
throw new Error('Base product not found');
|
||||||
@@ -142,25 +151,18 @@ async function getProductDefaultFields({
|
|||||||
defaultSalesChannels,
|
defaultSalesChannels,
|
||||||
defaultProductOption,
|
defaultProductOption,
|
||||||
defaultProductVariant,
|
defaultProductVariant,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createProducts({
|
async function createProducts({ medusa }: { medusa: Medusa }) {
|
||||||
medusa,
|
const { product_categories: allCategories } =
|
||||||
}: {
|
await medusa.admin.productCategory.list();
|
||||||
medusa: Medusa;
|
|
||||||
}) {
|
|
||||||
const { product_categories: allCategories } = await medusa.admin.productCategory.list();
|
|
||||||
|
|
||||||
const [
|
const [
|
||||||
{ products: existingProducts },
|
{ products: existingProducts },
|
||||||
analysisElements,
|
analysisElements,
|
||||||
analysisPackagesType,
|
analysisPackagesType,
|
||||||
{
|
{ defaultSalesChannels, defaultProductOption, defaultProductVariant },
|
||||||
defaultSalesChannels,
|
|
||||||
defaultProductOption,
|
|
||||||
defaultProductVariant,
|
|
||||||
}
|
|
||||||
] = await Promise.all([
|
] = await Promise.all([
|
||||||
medusa.admin.product.list({
|
medusa.admin.product.list({
|
||||||
category_id: allCategories.map(({ id }) => id),
|
category_id: allCategories.map(({ id }) => id),
|
||||||
@@ -168,13 +170,17 @@ async function createProducts({
|
|||||||
getAnalysisElements({ getAll: true }),
|
getAnalysisElements({ getAll: true }),
|
||||||
getAnalysisPackagesType(),
|
getAnalysisPackagesType(),
|
||||||
getProductDefaultFields({ medusa }),
|
getProductDefaultFields({ medusa }),
|
||||||
])
|
]);
|
||||||
|
|
||||||
for (const analysisElement of analysisElements) {
|
for (const analysisElement of analysisElements) {
|
||||||
const { analysis_id_original: originalId } = analysisElement;
|
const { analysis_id_original: originalId } = analysisElement;
|
||||||
const isExisting = existingProducts.find(({ metadata }) => metadata?.analysisIdOriginal === originalId);
|
const isExisting = existingProducts.find(
|
||||||
|
({ metadata }) => metadata?.analysisIdOriginal === originalId,
|
||||||
|
);
|
||||||
if (isExisting) {
|
if (isExisting) {
|
||||||
console.info(`Analysis element '${analysisElement.analysis_name_lab}' already exists`);
|
console.info(
|
||||||
|
`Analysis element '${analysisElement.analysis_name_lab}' already exists`,
|
||||||
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const { analysis_name_lab: name } = analysisElement;
|
const { analysis_name_lab: name } = analysisElement;
|
||||||
@@ -183,7 +189,10 @@ async function createProducts({
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const category = allCategories.find(({ metadata }) => metadata?.analysisGroupId === analysisElement.parent_analysis_group_id);
|
const category = allCategories.find(
|
||||||
|
({ metadata }) =>
|
||||||
|
metadata?.analysisGroupId === analysisElement.parent_analysis_group_id,
|
||||||
|
);
|
||||||
if (!category) {
|
if (!category) {
|
||||||
console.error(`Category not found for analysis element '${name}'`);
|
console.error(`Category not found for analysis element '${name}'`);
|
||||||
continue;
|
continue;
|
||||||
@@ -227,9 +236,9 @@ export default async function syncAnalysisGroupsStore() {
|
|||||||
// await deleteProductCategories({ medusa, categories });
|
// await deleteProductCategories({ medusa, categories });
|
||||||
// await deleteProducts({ medusa });
|
// await deleteProducts({ medusa });
|
||||||
// return;
|
// return;
|
||||||
|
|
||||||
await createProducts({ medusa });
|
await createProducts({ medusa });
|
||||||
|
|
||||||
await createMedusaSyncSuccessEntry();
|
await createMedusaSyncSuccessEntry();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await createMedusaSyncFailEntry(JSON.stringify(e));
|
await createMedusaSyncFailEntry(JSON.stringify(e));
|
||||||
|
|||||||
@@ -1,16 +1,32 @@
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { XMLParser } from 'fast-xml-parser';
|
import { XMLParser } from 'fast-xml-parser';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { createAnalysisGroup, getAnalysisGroups } from '~/lib/services/analysis-group.service';
|
|
||||||
import { IMedipostPublicMessageDataParsed } from '~/lib/services/medipost/medipost.types';
|
|
||||||
import { createAnalysis, createNoDataReceivedEntry, createNoNewDataReceivedEntry, createSyncFailEntry, createSyncSuccessEntry, getAnalyses } from '~/lib/services/analyses.service';
|
|
||||||
import { getLastCheckedDate } from '~/lib/services/sync-entries.service';
|
|
||||||
import { AnalysisElement, createAnalysisElement, getAnalysisElements } from '~/lib/services/analysis-element.service';
|
|
||||||
import { createCodes } from '~/lib/services/codes.service';
|
|
||||||
import { getLatestPublicMessageListItem } from '~/lib/services/medipost/medipostPublicMessage.service';
|
|
||||||
import type { ICode } from '~/lib/types/code';
|
|
||||||
import { toArray } from '@kit/shared/utils';
|
import { toArray } from '@kit/shared/utils';
|
||||||
|
|
||||||
|
import {
|
||||||
|
createAnalysis,
|
||||||
|
createNoDataReceivedEntry,
|
||||||
|
createNoNewDataReceivedEntry,
|
||||||
|
createSyncFailEntry,
|
||||||
|
createSyncSuccessEntry,
|
||||||
|
getAnalyses,
|
||||||
|
} from '~/lib/services/analyses.service';
|
||||||
|
import {
|
||||||
|
AnalysisElement,
|
||||||
|
createAnalysisElement,
|
||||||
|
getAnalysisElements,
|
||||||
|
} from '~/lib/services/analysis-element.service';
|
||||||
|
import {
|
||||||
|
createAnalysisGroup,
|
||||||
|
getAnalysisGroups,
|
||||||
|
} from '~/lib/services/analysis-group.service';
|
||||||
|
import { createCodes } from '~/lib/services/codes.service';
|
||||||
|
import { IMedipostPublicMessageDataParsed } from '~/lib/services/medipost/medipost.types';
|
||||||
|
import { getLatestPublicMessageListItem } from '~/lib/services/medipost/medipostPublicMessage.service';
|
||||||
|
import { getLastCheckedDate } from '~/lib/services/sync-entries.service';
|
||||||
|
import type { ICode } from '~/lib/types/code';
|
||||||
|
|
||||||
const WRITE_XML_TO_FILE = false as boolean;
|
const WRITE_XML_TO_FILE = false as boolean;
|
||||||
|
|
||||||
export default async function syncAnalysisGroups() {
|
export default async function syncAnalysisGroups() {
|
||||||
@@ -52,7 +68,8 @@ export default async function syncAnalysisGroups() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const parser = new XMLParser({ ignoreAttributes: false });
|
const parser = new XMLParser({ ignoreAttributes: false });
|
||||||
const parsed: IMedipostPublicMessageDataParsed = parser.parse(publicMessageData);
|
const parsed: IMedipostPublicMessageDataParsed =
|
||||||
|
parser.parse(publicMessageData);
|
||||||
|
|
||||||
if (parsed.ANSWER?.CODE && parsed.ANSWER?.CODE !== 0) {
|
if (parsed.ANSWER?.CODE && parsed.ANSWER?.CODE !== 0) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@@ -77,12 +94,18 @@ export default async function syncAnalysisGroups() {
|
|||||||
|
|
||||||
const codes: ICode[] = [];
|
const codes: ICode[] = [];
|
||||||
for (const analysisGroup of analysisGroups) {
|
for (const analysisGroup of analysisGroups) {
|
||||||
const existingAnalysisGroup = existingAnalysisGroups?.find(({ original_id }) => original_id === analysisGroup.UuringuGruppId);
|
const existingAnalysisGroup = existingAnalysisGroups?.find(
|
||||||
|
({ original_id }) => original_id === analysisGroup.UuringuGruppId,
|
||||||
|
);
|
||||||
let groupExistingAnalysisElements: AnalysisElement[] = [];
|
let groupExistingAnalysisElements: AnalysisElement[] = [];
|
||||||
let analysisGroupId: number;
|
let analysisGroupId: number;
|
||||||
if (existingAnalysisGroup) {
|
if (existingAnalysisGroup) {
|
||||||
console.info(`Analysis group '${analysisGroup.UuringuGruppNimi}' already exists, only creating new analysis elements`);
|
console.info(
|
||||||
groupExistingAnalysisElements = await getAnalysisElements({ analysisGroupId: existingAnalysisGroup.id });
|
`Analysis group '${analysisGroup.UuringuGruppNimi}' already exists, only creating new analysis elements`,
|
||||||
|
);
|
||||||
|
groupExistingAnalysisElements = await getAnalysisElements({
|
||||||
|
analysisGroupId: existingAnalysisGroup.id,
|
||||||
|
});
|
||||||
analysisGroupId = existingAnalysisGroup.id;
|
analysisGroupId = existingAnalysisGroup.id;
|
||||||
} else {
|
} else {
|
||||||
analysisGroupId = await createAnalysisGroup({
|
analysisGroupId = await createAnalysisGroup({
|
||||||
@@ -109,10 +132,14 @@ export default async function syncAnalysisGroups() {
|
|||||||
|
|
||||||
for (const item of analysisGroupItems) {
|
for (const item of analysisGroupItems) {
|
||||||
const analysisElement = item.UuringuElement!;
|
const analysisElement = item.UuringuElement!;
|
||||||
const isExistingAnalysisElement = groupExistingAnalysisElements
|
const isExistingAnalysisElement = groupExistingAnalysisElements.find(
|
||||||
.find(({ analysis_id_original }) => analysis_id_original === analysisElement.UuringId);
|
({ analysis_id_original }) =>
|
||||||
|
analysis_id_original === analysisElement.UuringId,
|
||||||
|
);
|
||||||
if (isExistingAnalysisElement) {
|
if (isExistingAnalysisElement) {
|
||||||
console.info(`Analysis element '${analysisElement.UuringNimi}' already exists`);
|
console.info(
|
||||||
|
`Analysis element '${analysisElement.UuringNimi}' already exists`,
|
||||||
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,16 +176,24 @@ export default async function syncAnalysisGroups() {
|
|||||||
|
|
||||||
const analyses = analysisElement.UuringuElement;
|
const analyses = analysisElement.UuringuElement;
|
||||||
if (analyses?.length) {
|
if (analyses?.length) {
|
||||||
const existingAnalyses = await getAnalyses({ originalIds: analyses.map(({ UuringId }) => UuringId) });
|
const existingAnalyses = await getAnalyses({
|
||||||
|
originalIds: analyses.map(({ UuringId }) => UuringId),
|
||||||
|
});
|
||||||
|
|
||||||
for (const analysis of analyses) {
|
for (const analysis of analyses) {
|
||||||
const isExistingAnalysis = existingAnalyses.find(({ analysis_id_original }) => analysis_id_original === analysis.UuringId);
|
const isExistingAnalysis = existingAnalyses.find(
|
||||||
|
({ analysis_id_original }) =>
|
||||||
|
analysis_id_original === analysis.UuringId,
|
||||||
|
);
|
||||||
if (isExistingAnalysis) {
|
if (isExistingAnalysis) {
|
||||||
console.info(`Analysis '${analysis.UuringNimi}' already exists`);
|
console.info(`Analysis '${analysis.UuringNimi}' already exists`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const insertedAnalysisId = await createAnalysis(analysis, analysisGroupId);
|
const insertedAnalysisId = await createAnalysis(
|
||||||
|
analysis,
|
||||||
|
analysisGroupId,
|
||||||
|
);
|
||||||
|
|
||||||
if (analysis.Kood) {
|
if (analysis.Kood) {
|
||||||
const analysisCodes = toArray(analysis.Kood);
|
const analysisCodes = toArray(analysis.Kood);
|
||||||
@@ -187,11 +222,17 @@ export default async function syncAnalysisGroups() {
|
|||||||
await createSyncSuccessEntry();
|
await createSyncSuccessEntry();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const errorMessage = e instanceof Error ? e.message : String(e);
|
const errorMessage = e instanceof Error ? e.message : String(e);
|
||||||
await createSyncFailEntry(JSON.stringify({
|
await createSyncFailEntry(
|
||||||
message: errorMessage,
|
JSON.stringify(
|
||||||
stack: e instanceof Error ? e.stack : undefined,
|
{
|
||||||
name: e instanceof Error ? e.name : 'Unknown',
|
message: errorMessage,
|
||||||
}, null, 2));
|
stack: e instanceof Error ? e.stack : undefined,
|
||||||
|
name: e instanceof Error ? e.name : 'Unknown',
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
2,
|
||||||
|
),
|
||||||
|
);
|
||||||
console.error('Sync failed:', e);
|
console.error('Sync failed:', e);
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Failed to sync public message data, error: ${errorMessage}`,
|
`Failed to sync public message data, error: ${errorMessage}`,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { readPrivateMessageResponse } from "~/lib/services/medipost/medipostPrivateMessage.service";
|
import { readPrivateMessageResponse } from '~/lib/services/medipost/medipostPrivateMessage.service';
|
||||||
|
|
||||||
type ProcessedMessage = {
|
type ProcessedMessage = {
|
||||||
messageId: string;
|
messageId: string;
|
||||||
@@ -15,9 +15,9 @@ type GroupedResults = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default async function syncAnalysisResults() {
|
export default async function syncAnalysisResults() {
|
||||||
console.info("Syncing analysis results");
|
console.info('Syncing analysis results');
|
||||||
|
|
||||||
let processedMessages: ProcessedMessage[] = [];
|
const processedMessages: ProcessedMessage[] = [];
|
||||||
const excludedMessageIds: string[] = [];
|
const excludedMessageIds: string[] = [];
|
||||||
while (true) {
|
while (true) {
|
||||||
const result = await readPrivateMessageResponse({ excludedMessageIds });
|
const result = await readPrivateMessageResponse({ excludedMessageIds });
|
||||||
@@ -26,7 +26,7 @@ export default async function syncAnalysisResults() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!result.messageId) {
|
if (!result.messageId) {
|
||||||
console.info("No more messages to process");
|
console.info('No more messages to process');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,5 +59,7 @@ export default async function syncAnalysisResults() {
|
|||||||
}
|
}
|
||||||
return acc;
|
return acc;
|
||||||
}, {} as GroupedResults);
|
}, {} as GroupedResults);
|
||||||
console.info(`Processed ${processedMessages.length} messages, results: ${JSON.stringify(groupedResults)}`);
|
console.info(
|
||||||
|
`Processed ${processedMessages.length} messages, results: ${JSON.stringify(groupedResults)}`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { NextRequest } from "next/server";
|
import { NextRequest } from 'next/server';
|
||||||
|
|
||||||
export default function validateApiKey(request: NextRequest) {
|
export default function validateApiKey(request: NextRequest) {
|
||||||
const envApiKey = process.env.JOBS_API_TOKEN;
|
const envApiKey = process.env.JOBS_API_TOKEN;
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from 'next/server';
|
||||||
import loadEnv from "../handler/load-env";
|
|
||||||
import validateApiKey from "../handler/validate-api-key";
|
import { retrieveOrder } from '@lib/data/orders';
|
||||||
import { getOrderedAnalysisIds } from "~/lib/services/medusaOrder.service";
|
|
||||||
import { sendOrderToMedipost } from "~/lib/services/medipost/medipostPrivateMessage.service";
|
import { getMedipostDispatchTries } from '~/lib/services/audit.service';
|
||||||
import { retrieveOrder } from "@lib/data/orders";
|
import { sendOrderToMedipost } from '~/lib/services/medipost/medipostPrivateMessage.service';
|
||||||
import { getMedipostDispatchTries } from "~/lib/services/audit.service";
|
import { getOrderedAnalysisIds } from '~/lib/services/medusaOrder.service';
|
||||||
|
|
||||||
|
import loadEnv from '../handler/load-env';
|
||||||
|
import validateApiKey from '../handler/validate-api-key';
|
||||||
|
|
||||||
export const POST = async (request: NextRequest) => {
|
export const POST = async (request: NextRequest) => {
|
||||||
loadEnv();
|
loadEnv();
|
||||||
@@ -19,23 +22,34 @@ export const POST = async (request: NextRequest) => {
|
|||||||
|
|
||||||
const tries = await getMedipostDispatchTries(medusaOrderId);
|
const tries = await getMedipostDispatchTries(medusaOrderId);
|
||||||
if (tries >= 3) {
|
if (tries >= 3) {
|
||||||
return NextResponse.json({
|
return NextResponse.json(
|
||||||
message: 'Order has been retried too many times',
|
{
|
||||||
}, { status: 400 });
|
message: 'Order has been retried too many times',
|
||||||
|
},
|
||||||
|
{ status: 400 },
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const medusaOrder = await retrieveOrder(medusaOrderId);
|
const medusaOrder = await retrieveOrder(medusaOrderId);
|
||||||
const orderedAnalysisElements = await getOrderedAnalysisIds({ medusaOrder });
|
const orderedAnalysisElements = await getOrderedAnalysisIds({
|
||||||
|
medusaOrder,
|
||||||
|
});
|
||||||
await sendOrderToMedipost({ medusaOrderId, orderedAnalysisElements });
|
await sendOrderToMedipost({ medusaOrderId, orderedAnalysisElements });
|
||||||
console.info("Successfully sent order to medipost");
|
console.info('Successfully sent order to medipost');
|
||||||
return NextResponse.json({
|
return NextResponse.json(
|
||||||
message: 'Successfully sent order to medipost',
|
{
|
||||||
}, { status: 200 });
|
message: 'Successfully sent order to medipost',
|
||||||
|
},
|
||||||
|
{ status: 200 },
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Error sending order to medipost", e);
|
console.error('Error sending order to medipost', e);
|
||||||
return NextResponse.json({
|
return NextResponse.json(
|
||||||
message: 'Failed to send order to medipost',
|
{
|
||||||
}, { status: 500 });
|
message: 'Failed to send order to medipost',
|
||||||
|
},
|
||||||
|
{ status: 500 },
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
NotificationAction,
|
NotificationAction,
|
||||||
createNotificationLog,
|
createNotificationLog,
|
||||||
} from '~/lib/services/audit/notificationEntries.service';
|
} from '~/lib/services/audit/notificationEntries.service';
|
||||||
|
|
||||||
import loadEnv from '../handler/load-env';
|
import loadEnv from '../handler/load-env';
|
||||||
import sendOpenJobsEmails from '../handler/send-open-jobs-emails';
|
import sendOpenJobsEmails from '../handler/send-open-jobs-emails';
|
||||||
import validateApiKey from '../handler/validate-api-key';
|
import validateApiKey from '../handler/validate-api-key';
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from 'next/server';
|
||||||
import loadEnv from "../handler/load-env";
|
|
||||||
import validateApiKey from "../handler/validate-api-key";
|
import loadEnv from '../handler/load-env';
|
||||||
import syncAnalysisGroupsStore from "../handler/sync-analysis-groups-store";
|
import syncAnalysisGroupsStore from '../handler/sync-analysis-groups-store';
|
||||||
|
import validateApiKey from '../handler/validate-api-key';
|
||||||
|
|
||||||
export const POST = async (request: NextRequest) => {
|
export const POST = async (request: NextRequest) => {
|
||||||
loadEnv();
|
loadEnv();
|
||||||
@@ -14,14 +15,20 @@ export const POST = async (request: NextRequest) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await syncAnalysisGroupsStore();
|
await syncAnalysisGroupsStore();
|
||||||
console.info("Successfully synced analysis groups store");
|
console.info('Successfully synced analysis groups store');
|
||||||
return NextResponse.json({
|
return NextResponse.json(
|
||||||
message: 'Successfully synced analysis groups store',
|
{
|
||||||
}, { status: 200 });
|
message: 'Successfully synced analysis groups store',
|
||||||
|
},
|
||||||
|
{ status: 200 },
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Error syncing analysis groups store", e);
|
console.error('Error syncing analysis groups store', e);
|
||||||
return NextResponse.json({
|
return NextResponse.json(
|
||||||
message: 'Failed to sync analysis groups store',
|
{
|
||||||
}, { status: 500 });
|
message: 'Failed to sync analysis groups store',
|
||||||
|
},
|
||||||
|
{ status: 500 },
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from 'next/server';
|
||||||
import syncAnalysisGroups from "../handler/sync-analysis-groups";
|
|
||||||
import loadEnv from "../handler/load-env";
|
import loadEnv from '../handler/load-env';
|
||||||
import validateApiKey from "../handler/validate-api-key";
|
import syncAnalysisGroups from '../handler/sync-analysis-groups';
|
||||||
|
import validateApiKey from '../handler/validate-api-key';
|
||||||
|
|
||||||
export const POST = async (request: NextRequest) => {
|
export const POST = async (request: NextRequest) => {
|
||||||
loadEnv();
|
loadEnv();
|
||||||
@@ -14,14 +15,20 @@ export const POST = async (request: NextRequest) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await syncAnalysisGroups();
|
await syncAnalysisGroups();
|
||||||
console.info("Successfully synced analysis groups");
|
console.info('Successfully synced analysis groups');
|
||||||
return NextResponse.json({
|
return NextResponse.json(
|
||||||
message: 'Successfully synced analysis groups',
|
{
|
||||||
}, { status: 200 });
|
message: 'Successfully synced analysis groups',
|
||||||
|
},
|
||||||
|
{ status: 200 },
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Error syncing analysis groups", e);
|
console.error('Error syncing analysis groups', e);
|
||||||
return NextResponse.json({
|
return NextResponse.json(
|
||||||
message: 'Failed to sync analysis groups',
|
{
|
||||||
}, { status: 500 });
|
message: 'Failed to sync analysis groups',
|
||||||
|
},
|
||||||
|
{ status: 500 },
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from 'next/server';
|
||||||
import loadEnv from "../handler/load-env";
|
|
||||||
import validateApiKey from "../handler/validate-api-key";
|
import loadEnv from '../handler/load-env';
|
||||||
import syncAnalysisResults from "../handler/sync-analysis-results";
|
import syncAnalysisResults from '../handler/sync-analysis-results';
|
||||||
|
import validateApiKey from '../handler/validate-api-key';
|
||||||
|
|
||||||
export const POST = async (request: NextRequest) => {
|
export const POST = async (request: NextRequest) => {
|
||||||
loadEnv();
|
loadEnv();
|
||||||
@@ -14,14 +15,20 @@ export const POST = async (request: NextRequest) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await syncAnalysisResults();
|
await syncAnalysisResults();
|
||||||
console.info("Successfully synced analysis results");
|
console.info('Successfully synced analysis results');
|
||||||
return NextResponse.json({
|
return NextResponse.json(
|
||||||
message: 'Successfully synced analysis results',
|
{
|
||||||
}, { status: 200 });
|
message: 'Successfully synced analysis results',
|
||||||
|
},
|
||||||
|
{ status: 200 },
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Error syncing analysis results", e);
|
console.error('Error syncing analysis results', e);
|
||||||
return NextResponse.json({
|
return NextResponse.json(
|
||||||
message: 'Failed to sync analysis results',
|
{
|
||||||
}, { status: 500 });
|
message: 'Failed to sync analysis results',
|
||||||
|
},
|
||||||
|
{ status: 500 },
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from 'next/server';
|
||||||
import loadEnv from "../handler/load-env";
|
|
||||||
import validateApiKey from "../handler/validate-api-key";
|
import loadEnv from '../handler/load-env';
|
||||||
import syncConnectedOnline from "../handler/sync-connected-online";
|
import syncConnectedOnline from '../handler/sync-connected-online';
|
||||||
|
import validateApiKey from '../handler/validate-api-key';
|
||||||
|
|
||||||
export const POST = async (request: NextRequest) => {
|
export const POST = async (request: NextRequest) => {
|
||||||
loadEnv();
|
loadEnv();
|
||||||
@@ -14,14 +15,20 @@ export const POST = async (request: NextRequest) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await syncConnectedOnline();
|
await syncConnectedOnline();
|
||||||
console.info("Successfully synced connected-online");
|
console.info('Successfully synced connected-online');
|
||||||
return NextResponse.json({
|
return NextResponse.json(
|
||||||
message: 'Successfully synced connected-online',
|
{
|
||||||
}, { status: 200 });
|
message: 'Successfully synced connected-online',
|
||||||
|
},
|
||||||
|
{ status: 200 },
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Error syncing connected-online", e);
|
console.error('Error syncing connected-online', e);
|
||||||
return NextResponse.json({
|
return NextResponse.json(
|
||||||
message: 'Failed to sync connected-online',
|
{
|
||||||
}, { status: 500 });
|
message: 'Failed to sync connected-online',
|
||||||
|
},
|
||||||
|
{ status: 500 },
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,11 +1,17 @@
|
|||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from 'next/server';
|
||||||
import { getAnalysisOrdersAdmin } from "~/lib/services/order.service";
|
|
||||||
import { composeOrderTestResponseXML, sendPrivateMessageTestResponse } from "~/lib/services/medipost/medipostTest.service";
|
import { retrieveOrder } from '@lib/data';
|
||||||
import { retrieveOrder } from "@lib/data";
|
|
||||||
import { getAccountAdmin } from "~/lib/services/account.service";
|
import { getAccountAdmin } from '~/lib/services/account.service';
|
||||||
import { getOrderedAnalysisIds } from "~/lib/services/medusaOrder.service";
|
import {
|
||||||
import loadEnv from "../handler/load-env";
|
composeOrderTestResponseXML,
|
||||||
import validateApiKey from "../handler/validate-api-key";
|
sendPrivateMessageTestResponse,
|
||||||
|
} from '~/lib/services/medipost/medipostTest.service';
|
||||||
|
import { getOrderedAnalysisIds } from '~/lib/services/medusaOrder.service';
|
||||||
|
import { getAnalysisOrdersAdmin } from '~/lib/services/order.service';
|
||||||
|
|
||||||
|
import loadEnv from '../handler/load-env';
|
||||||
|
import validateApiKey from '../handler/validate-api-key';
|
||||||
|
|
||||||
export async function POST(request: NextRequest) {
|
export async function POST(request: NextRequest) {
|
||||||
loadEnv();
|
loadEnv();
|
||||||
@@ -16,17 +22,27 @@ export async function POST(request: NextRequest) {
|
|||||||
return NextResponse.json({}, { status: 401, statusText: 'Unauthorized' });
|
return NextResponse.json({}, { status: 401, statusText: 'Unauthorized' });
|
||||||
}
|
}
|
||||||
|
|
||||||
const analysisOrders = await getAnalysisOrdersAdmin({ orderStatus: 'PROCESSING' });
|
const analysisOrders = await getAnalysisOrdersAdmin({
|
||||||
|
orderStatus: 'PROCESSING',
|
||||||
|
});
|
||||||
|
|
||||||
console.error(`Sending test responses for ${analysisOrders.length} analysis orders`);
|
console.error(
|
||||||
|
`Sending test responses for ${analysisOrders.length} analysis orders`,
|
||||||
|
);
|
||||||
for (const medreportOrder of analysisOrders) {
|
for (const medreportOrder of analysisOrders) {
|
||||||
const medusaOrderId = medreportOrder.medusa_order_id;
|
const medusaOrderId = medreportOrder.medusa_order_id;
|
||||||
const medusaOrder = await retrieveOrder(medusaOrderId)
|
const medusaOrder = await retrieveOrder(medusaOrderId);
|
||||||
|
|
||||||
const account = await getAccountAdmin({ primaryOwnerUserId: medreportOrder.user_id });
|
const account = await getAccountAdmin({
|
||||||
const orderedAnalysisElementsIds = await getOrderedAnalysisIds({ medusaOrder });
|
primaryOwnerUserId: medreportOrder.user_id,
|
||||||
|
});
|
||||||
|
const orderedAnalysisElementsIds = await getOrderedAnalysisIds({
|
||||||
|
medusaOrder,
|
||||||
|
});
|
||||||
|
|
||||||
console.info(`Sending test response for order=${medusaOrderId} with ${orderedAnalysisElementsIds.length} ordered analysis elements`);
|
console.info(
|
||||||
|
`Sending test response for order=${medusaOrderId} with ${orderedAnalysisElementsIds.length} ordered analysis elements`,
|
||||||
|
);
|
||||||
const idsToSend = orderedAnalysisElementsIds;
|
const idsToSend = orderedAnalysisElementsIds;
|
||||||
const messageXml = await composeOrderTestResponseXML({
|
const messageXml = await composeOrderTestResponseXML({
|
||||||
person: {
|
person: {
|
||||||
@@ -35,8 +51,12 @@ export async function POST(request: NextRequest) {
|
|||||||
lastName: account.last_name ?? '',
|
lastName: account.last_name ?? '',
|
||||||
phone: account.phone ?? '',
|
phone: account.phone ?? '',
|
||||||
},
|
},
|
||||||
orderedAnalysisElementsIds: idsToSend.map(({ analysisElementId }) => analysisElementId).filter(Boolean) as number[],
|
orderedAnalysisElementsIds: idsToSend
|
||||||
orderedAnalysesIds: idsToSend.map(({ analysisId }) => analysisId).filter(Boolean) as number[],
|
.map(({ analysisElementId }) => analysisElementId)
|
||||||
|
.filter(Boolean) as number[],
|
||||||
|
orderedAnalysesIds: idsToSend
|
||||||
|
.map(({ analysisId }) => analysisId)
|
||||||
|
.filter(Boolean) as number[],
|
||||||
orderId: medreportOrder.id,
|
orderId: medreportOrder.id,
|
||||||
orderCreatedAt: new Date(medreportOrder.created_at),
|
orderCreatedAt: new Date(medreportOrder.created_at),
|
||||||
});
|
});
|
||||||
@@ -44,7 +64,7 @@ export async function POST(request: NextRequest) {
|
|||||||
try {
|
try {
|
||||||
await sendPrivateMessageTestResponse({ messageXml });
|
await sendPrivateMessageTestResponse({ messageXml });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error sending private message test response: ", error);
|
console.error('Error sending private message test response: ', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { NextResponse } from 'next/server';
|
import { NextResponse } from 'next/server';
|
||||||
|
|
||||||
import jwt from 'jsonwebtoken';
|
import jwt from 'jsonwebtoken';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
@@ -94,4 +95,4 @@ export const POST = enhanceRouteHandler(
|
|||||||
{
|
{
|
||||||
auth: false,
|
auth: false,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from 'next/server';
|
||||||
import { getAnalysisOrder } from "~/lib/services/order.service";
|
|
||||||
import { composeOrderTestResponseXML, sendPrivateMessageTestResponse } from "~/lib/services/medipost/medipostTest.service";
|
import { retrieveOrder } from '@lib/data';
|
||||||
import { retrieveOrder } from "@lib/data";
|
|
||||||
import { getAccountAdmin } from "~/lib/services/account.service";
|
import { getAccountAdmin } from '~/lib/services/account.service';
|
||||||
import { upsertMedipostActionLog } from "~/lib/services/medipost/medipostMessageBase.service";
|
import { upsertMedipostActionLog } from '~/lib/services/medipost/medipostMessageBase.service';
|
||||||
import { getOrderedAnalysisIds } from "~/lib/services/medusaOrder.service";
|
import {
|
||||||
|
composeOrderTestResponseXML,
|
||||||
|
sendPrivateMessageTestResponse,
|
||||||
|
} from '~/lib/services/medipost/medipostTest.service';
|
||||||
|
import { getOrderedAnalysisIds } from '~/lib/services/medusaOrder.service';
|
||||||
|
import { getAnalysisOrder } from '~/lib/services/order.service';
|
||||||
|
|
||||||
export async function POST(request: Request) {
|
export async function POST(request: Request) {
|
||||||
// const isDev = process.env.NODE_ENV === 'development';
|
// const isDev = process.env.NODE_ENV === 'development';
|
||||||
@@ -14,13 +19,19 @@ export async function POST(request: Request) {
|
|||||||
|
|
||||||
const { medusaOrderId } = await request.json();
|
const { medusaOrderId } = await request.json();
|
||||||
|
|
||||||
const medusaOrder = await retrieveOrder(medusaOrderId)
|
const medusaOrder = await retrieveOrder(medusaOrderId);
|
||||||
const analysisOrder = await getAnalysisOrder({ medusaOrderId });
|
const analysisOrder = await getAnalysisOrder({ medusaOrderId });
|
||||||
|
|
||||||
const account = await getAccountAdmin({ primaryOwnerUserId: analysisOrder.user_id });
|
const account = await getAccountAdmin({
|
||||||
const orderedAnalysisElementsIds = await getOrderedAnalysisIds({ medusaOrder });
|
primaryOwnerUserId: analysisOrder.user_id,
|
||||||
|
});
|
||||||
|
const orderedAnalysisElementsIds = await getOrderedAnalysisIds({
|
||||||
|
medusaOrder,
|
||||||
|
});
|
||||||
|
|
||||||
console.info(`Sending test response for order=${medusaOrderId} with ${orderedAnalysisElementsIds.length} ordered analysis elements`);
|
console.info(
|
||||||
|
`Sending test response for order=${medusaOrderId} with ${orderedAnalysisElementsIds.length} ordered analysis elements`,
|
||||||
|
);
|
||||||
const messageXml = await composeOrderTestResponseXML({
|
const messageXml = await composeOrderTestResponseXML({
|
||||||
person: {
|
person: {
|
||||||
idCode: account.personal_code!,
|
idCode: account.personal_code!,
|
||||||
@@ -28,8 +39,12 @@ export async function POST(request: Request) {
|
|||||||
lastName: account.last_name ?? '',
|
lastName: account.last_name ?? '',
|
||||||
phone: account.phone ?? '',
|
phone: account.phone ?? '',
|
||||||
},
|
},
|
||||||
orderedAnalysisElementsIds: orderedAnalysisElementsIds.map(({ analysisElementId }) => analysisElementId).filter(Boolean) as number[],
|
orderedAnalysisElementsIds: orderedAnalysisElementsIds
|
||||||
orderedAnalysesIds: orderedAnalysisElementsIds.map(({ analysisId }) => analysisId).filter(Boolean) as number[],
|
.map(({ analysisElementId }) => analysisElementId)
|
||||||
|
.filter(Boolean) as number[],
|
||||||
|
orderedAnalysesIds: orderedAnalysisElementsIds
|
||||||
|
.map(({ analysisId }) => analysisId)
|
||||||
|
.filter(Boolean) as number[],
|
||||||
orderId: analysisOrder.id,
|
orderId: analysisOrder.id,
|
||||||
orderCreatedAt: new Date(analysisOrder.created_at),
|
orderCreatedAt: new Date(analysisOrder.created_at),
|
||||||
});
|
});
|
||||||
@@ -42,7 +57,7 @@ export async function POST(request: Request) {
|
|||||||
});
|
});
|
||||||
await sendPrivateMessageTestResponse({ messageXml });
|
await sendPrivateMessageTestResponse({ messageXml });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error sending private message test response: ", error);
|
console.error('Error sending private message test response: ', error);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NextResponse.json({ success: true });
|
return NextResponse.json({ success: true });
|
||||||
|
|||||||
@@ -3,15 +3,13 @@ import Link from 'next/link';
|
|||||||
import type { AuthError } from '@supabase/supabase-js';
|
import type { AuthError } from '@supabase/supabase-js';
|
||||||
|
|
||||||
import { ResendAuthLinkForm } from '@kit/auth/resend-email-link';
|
import { ResendAuthLinkForm } from '@kit/auth/resend-email-link';
|
||||||
|
import { pathsConfig } from '@kit/shared/config';
|
||||||
import { Alert, AlertDescription, AlertTitle } from '@kit/ui/alert';
|
import { Alert, AlertDescription, AlertTitle } from '@kit/ui/alert';
|
||||||
import { Button } from '@kit/ui/button';
|
import { Button } from '@kit/ui/button';
|
||||||
import { Trans } from '@kit/ui/trans';
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
import { pathsConfig } from '@kit/shared/config';
|
|
||||||
|
|
||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
|
|
||||||
|
|
||||||
interface AuthCallbackErrorPageProps {
|
interface AuthCallbackErrorPageProps {
|
||||||
searchParams: Promise<{
|
searchParams: Promise<{
|
||||||
error: string;
|
error: string;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { AuthLayoutShell } from '@kit/auth/shared';
|
import { AuthLayoutShell } from '@kit/auth/shared';
|
||||||
|
|
||||||
import { AppLogo } from '@kit/shared/components/app-logo';
|
import { AppLogo } from '@kit/shared/components/app-logo';
|
||||||
|
|
||||||
function AuthLayout({ children }: React.PropsWithChildren) {
|
function AuthLayout({ children }: React.PropsWithChildren) {
|
||||||
|
|||||||
@@ -1,17 +1,20 @@
|
|||||||
import { redirect } from 'next/navigation';
|
import { redirect } from 'next/navigation';
|
||||||
import type { NextRequest } from 'next/server';
|
import type { NextRequest } from 'next/server';
|
||||||
|
|
||||||
import { createAuthCallbackService, getErrorURLParameters } from '@kit/supabase/auth';
|
import { createAccountsApi } from '@/packages/features/accounts/src/server/api';
|
||||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
|
||||||
|
|
||||||
import { pathsConfig } from '@kit/shared/config';
|
import { pathsConfig } from '@kit/shared/config';
|
||||||
import { createAccountsApi } from '@/packages/features/accounts/src/server/api';
|
import {
|
||||||
|
createAuthCallbackService,
|
||||||
|
getErrorURLParameters,
|
||||||
|
} from '@kit/supabase/auth';
|
||||||
|
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||||
|
|
||||||
const ERROR_PATH = '/auth/callback/error';
|
const ERROR_PATH = '/auth/callback/error';
|
||||||
|
|
||||||
const redirectOnError = (searchParams?: string) => {
|
const redirectOnError = (searchParams?: string) => {
|
||||||
return redirect(`${ERROR_PATH}${searchParams ? `?${searchParams}` : ''}`);
|
return redirect(`${ERROR_PATH}${searchParams ? `?${searchParams}` : ''}`);
|
||||||
}
|
};
|
||||||
|
|
||||||
export async function GET(request: NextRequest) {
|
export async function GET(request: NextRequest) {
|
||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
@@ -44,19 +47,17 @@ export async function GET(request: NextRequest) {
|
|||||||
|
|
||||||
const service = createAuthCallbackService(getSupabaseServerClient());
|
const service = createAuthCallbackService(getSupabaseServerClient());
|
||||||
const oauthResult = await service.exchangeCodeForSession(authCode);
|
const oauthResult = await service.exchangeCodeForSession(authCode);
|
||||||
if (!("isSuccess" in oauthResult)) {
|
if (!('isSuccess' in oauthResult)) {
|
||||||
return redirectOnError(oauthResult.searchParams);
|
return redirectOnError(oauthResult.searchParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
const api = createAccountsApi(getSupabaseServerClient());
|
const api = createAccountsApi(getSupabaseServerClient());
|
||||||
|
|
||||||
const account = await api.getPersonalAccountByUserId(
|
const account = await api.getPersonalAccountByUserId(oauthResult.user.id);
|
||||||
oauthResult.user.id,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!account.email || !account.name || !account.last_name) {
|
if (!account.email || !account.name || !account.last_name) {
|
||||||
return redirect(pathsConfig.auth.updateAccount);
|
return redirect(pathsConfig.auth.updateAccount);
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect(redirectPath);
|
return redirect(redirectPath);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { AuthLayoutShell } from '@kit/auth/shared';
|
import { AuthLayoutShell } from '@kit/auth/shared';
|
||||||
|
|
||||||
import { AppLogo } from '@kit/shared/components/app-logo';
|
import { AppLogo } from '@kit/shared/components/app-logo';
|
||||||
|
|
||||||
function AuthLayout({ children }: React.PropsWithChildren) {
|
function AuthLayout({ children }: React.PropsWithChildren) {
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
import { NextRequest, NextResponse } from 'next/server';
|
import { NextRequest, NextResponse } from 'next/server';
|
||||||
|
|
||||||
|
import { pathsConfig } from '@kit/shared/config';
|
||||||
import { createAuthCallbackService } from '@kit/supabase/auth';
|
import { createAuthCallbackService } from '@kit/supabase/auth';
|
||||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||||
|
|
||||||
import { pathsConfig } from '@kit/shared/config';
|
|
||||||
|
|
||||||
export async function GET(request: NextRequest) {
|
export async function GET(request: NextRequest) {
|
||||||
const service = createAuthCallbackService(getSupabaseServerClient());
|
const service = createAuthCallbackService(getSupabaseServerClient());
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { pathsConfig } from '@kit/shared/config';
|
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import { usePersonalAccountData } from '@kit/accounts/hooks/use-personal-account-data';
|
import { usePersonalAccountData } from '@kit/accounts/hooks/use-personal-account-data';
|
||||||
import { SuccessNotification } from '@kit/notifications/components';
|
import { SuccessNotification } from '@kit/notifications/components';
|
||||||
|
import { pathsConfig } from '@kit/shared/config';
|
||||||
|
|
||||||
const MembershipConfirmationNotification: React.FC<{
|
const MembershipConfirmationNotification: React.FC<{
|
||||||
userId: string;
|
userId: string;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
|
|
||||||
|
|
||||||
async function SiteLayout(props: React.PropsWithChildren) {
|
async function SiteLayout(props: React.PropsWithChildren) {
|
||||||
return (
|
return (
|
||||||
<div className={'flex min-h-[100vh] flex-col items-center justify-center'}>
|
<div className={'flex min-h-[100vh] flex-col items-center justify-center'}>
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { AuthLayoutShell } from '@kit/auth/shared';
|
import { AuthLayoutShell } from '@kit/auth/shared';
|
||||||
|
|
||||||
import { AppLogo } from '@kit/shared/components/app-logo';
|
import { AppLogo } from '@kit/shared/components/app-logo';
|
||||||
|
|
||||||
function AuthLayout({ children }: React.PropsWithChildren) {
|
function AuthLayout({ children }: React.PropsWithChildren) {
|
||||||
|
|||||||
@@ -1,16 +1,14 @@
|
|||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
|
|
||||||
import { PasswordResetRequestContainer } from '@kit/auth/password-reset';
|
import { PasswordResetRequestContainer } from '@kit/auth/password-reset';
|
||||||
|
import { pathsConfig } from '@kit/shared/config';
|
||||||
import { Button } from '@kit/ui/button';
|
import { Button } from '@kit/ui/button';
|
||||||
import { Heading } from '@kit/ui/heading';
|
import { Heading } from '@kit/ui/heading';
|
||||||
import { Trans } from '@kit/ui/trans';
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
import { pathsConfig } from '@kit/shared/config';
|
|
||||||
|
|
||||||
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
|
|
||||||
|
|
||||||
export const generateMetadata = async () => {
|
export const generateMetadata = async () => {
|
||||||
const { t } = await createI18nServerInstance();
|
const { t } = await createI18nServerInstance();
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +1,26 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import Loading from '@/app/home/loading';
|
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { getSupabaseBrowserClient } from '@/packages/supabase/src/clients/browser-client';
|
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
|
|
||||||
|
import Loading from '@/app/home/loading';
|
||||||
|
import { getSupabaseBrowserClient } from '@/packages/supabase/src/clients/browser-client';
|
||||||
|
|
||||||
export function SignInPageClientRedirect() {
|
export function SignInPageClientRedirect() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function signIn() {
|
async function signIn() {
|
||||||
const { data, error } = await getSupabaseBrowserClient()
|
const { data, error } =
|
||||||
.auth
|
await getSupabaseBrowserClient().auth.signInWithOAuth({
|
||||||
.signInWithOAuth({
|
|
||||||
provider: 'keycloak',
|
provider: 'keycloak',
|
||||||
options: {
|
options: {
|
||||||
redirectTo: `${window.location.origin}/auth/callback`,
|
redirectTo: `${window.location.origin}/auth/callback`,
|
||||||
queryParams: {
|
queryParams: {
|
||||||
prompt: 'login',
|
prompt: 'login',
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { AuthLayoutShell } from '@kit/auth/shared';
|
import { AuthLayoutShell } from '@kit/auth/shared';
|
||||||
|
|
||||||
import { AppLogo } from '@kit/shared/components/app-logo';
|
import { AppLogo } from '@kit/shared/components/app-logo';
|
||||||
|
|
||||||
function AuthLayout({ children }: React.PropsWithChildren) {
|
function AuthLayout({ children }: React.PropsWithChildren) {
|
||||||
|
|||||||
@@ -2,8 +2,9 @@ import { getServerAuthConfig, pathsConfig } from '@kit/shared/config';
|
|||||||
|
|
||||||
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
import { SignInPageClientRedirect } from './components/SignInPageClientRedirect';
|
|
||||||
import PasswordOption from './components/PasswordOption';
|
import PasswordOption from './components/PasswordOption';
|
||||||
|
import { SignInPageClientRedirect } from './components/SignInPageClientRedirect';
|
||||||
|
|
||||||
interface SignInPageProps {
|
interface SignInPageProps {
|
||||||
searchParams: Promise<{
|
searchParams: Promise<{
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { AuthLayoutShell } from '@kit/auth/shared';
|
import { AuthLayoutShell } from '@kit/auth/shared';
|
||||||
|
|
||||||
import { AppLogo } from '@kit/shared/components/app-logo';
|
import { AppLogo } from '@kit/shared/components/app-logo';
|
||||||
|
|
||||||
function AuthLayout({ children }: React.PropsWithChildren) {
|
function AuthLayout({ children }: React.PropsWithChildren) {
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import { Heading } from '@kit/ui/heading';
|
|||||||
import { Trans } from '@kit/ui/trans';
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
||||||
|
|
||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
|
|
||||||
export const generateMetadata = async () => {
|
export const generateMetadata = async () => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { z } from 'zod';
|
|
||||||
import Isikukood from 'isikukood';
|
import Isikukood from 'isikukood';
|
||||||
import parsePhoneNumber from 'libphonenumber-js/min';
|
import parsePhoneNumber from 'libphonenumber-js/min';
|
||||||
|
import { z } from 'zod';
|
||||||
|
|
||||||
const updateAccountSchema = {
|
const updateAccountSchema = {
|
||||||
firstName: z
|
firstName: z
|
||||||
@@ -39,14 +39,18 @@ const updateAccountSchema = {
|
|||||||
(phone) => {
|
(phone) => {
|
||||||
try {
|
try {
|
||||||
const phoneNumber = parsePhoneNumber(phone);
|
const phoneNumber = parsePhoneNumber(phone);
|
||||||
return !!phoneNumber && phoneNumber.isValid() && phoneNumber.country === 'EE';
|
return (
|
||||||
|
!!phoneNumber &&
|
||||||
|
phoneNumber.isValid() &&
|
||||||
|
phoneNumber.country === 'EE'
|
||||||
|
);
|
||||||
} catch {
|
} catch {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
message: 'common:formFieldError.invalidPhoneNumber',
|
message: 'common:formFieldError.invalidPhoneNumber',
|
||||||
}
|
},
|
||||||
),
|
),
|
||||||
city: z.string().optional(),
|
city: z.string().optional(),
|
||||||
weight: z
|
weight: z
|
||||||
@@ -81,22 +85,27 @@ export const UpdateAccountSchemaServer = z.object({
|
|||||||
height: updateAccountSchema.height.nullable(),
|
height: updateAccountSchema.height.nullable(),
|
||||||
userConsent: updateAccountSchema.userConsent,
|
userConsent: updateAccountSchema.userConsent,
|
||||||
});
|
});
|
||||||
export const UpdateAccountSchemaClient = ({ isEmailUser }: { isEmailUser: boolean }) => z.object({
|
export const UpdateAccountSchemaClient = ({
|
||||||
firstName: updateAccountSchema.firstName,
|
isEmailUser,
|
||||||
lastName: updateAccountSchema.lastName,
|
}: {
|
||||||
personalCode: updateAccountSchema.personalCode,
|
isEmailUser: boolean;
|
||||||
email: updateAccountSchema.email,
|
}) =>
|
||||||
phone: updateAccountSchema.phone,
|
z.object({
|
||||||
...(isEmailUser
|
firstName: updateAccountSchema.firstName,
|
||||||
? {
|
lastName: updateAccountSchema.lastName,
|
||||||
city: z.string().optional(),
|
personalCode: updateAccountSchema.personalCode,
|
||||||
weight: z.number().optional(),
|
email: updateAccountSchema.email,
|
||||||
height: z.number().optional(),
|
phone: updateAccountSchema.phone,
|
||||||
}
|
...(isEmailUser
|
||||||
: {
|
? {
|
||||||
city: updateAccountSchema.city,
|
city: z.string().optional(),
|
||||||
weight: updateAccountSchema.weight,
|
weight: z.number().optional(),
|
||||||
height: updateAccountSchema.height,
|
height: z.number().optional(),
|
||||||
}),
|
}
|
||||||
userConsent: updateAccountSchema.userConsent,
|
: {
|
||||||
});
|
city: updateAccountSchema.city,
|
||||||
|
weight: updateAccountSchema.weight,
|
||||||
|
height: updateAccountSchema.height,
|
||||||
|
}),
|
||||||
|
userConsent: updateAccountSchema.userConsent,
|
||||||
|
});
|
||||||
|
|||||||
@@ -4,9 +4,8 @@ import { updateCustomer } from '@lib/data/customer';
|
|||||||
|
|
||||||
import { AccountSubmitData, createAuthApi } from '@kit/auth/api';
|
import { AccountSubmitData, createAuthApi } from '@kit/auth/api';
|
||||||
import { enhanceAction } from '@kit/next/actions';
|
import { enhanceAction } from '@kit/next/actions';
|
||||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
|
||||||
|
|
||||||
import { pathsConfig } from '@kit/shared/config';
|
import { pathsConfig } from '@kit/shared/config';
|
||||||
|
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||||
|
|
||||||
import { UpdateAccountSchemaServer } from '../schemas/update-account.schema';
|
import { UpdateAccountSchemaServer } from '../schemas/update-account.schema';
|
||||||
|
|
||||||
@@ -32,14 +31,14 @@ export const onUpdateAccount = enhanceAction(
|
|||||||
phone: params.phone,
|
phone: params.phone,
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Failed to update Medusa customer", e);
|
console.error('Failed to update Medusa customer', e);
|
||||||
}
|
}
|
||||||
|
|
||||||
const hasUnseenMembershipConfirmation =
|
const hasUnseenMembershipConfirmation =
|
||||||
await api.hasUnseenMembershipConfirmation();
|
await api.hasUnseenMembershipConfirmation();
|
||||||
return {
|
return {
|
||||||
hasUnseenMembershipConfirmation,
|
hasUnseenMembershipConfirmation,
|
||||||
}
|
};
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
schema: UpdateAccountSchemaServer,
|
schema: UpdateAccountSchemaServer,
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
|
|
||||||
|
|
||||||
async function SiteLayout(props: React.PropsWithChildren) {
|
async function SiteLayout(props: React.PropsWithChildren) {
|
||||||
return (
|
return (
|
||||||
<div className={'flex min-h-[100vh] flex-col items-center justify-center'}>
|
<div className={'flex min-h-[100vh] flex-col items-center justify-center'}>
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { AuthLayoutShell } from '@kit/auth/shared';
|
import { AuthLayoutShell } from '@kit/auth/shared';
|
||||||
|
|
||||||
import { AppLogo } from '@kit/shared/components/app-logo';
|
import { AppLogo } from '@kit/shared/components/app-logo';
|
||||||
|
|
||||||
function AuthLayout({ children }: React.PropsWithChildren) {
|
function AuthLayout({ children }: React.PropsWithChildren) {
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import { redirect } from 'next/navigation';
|
import { redirect } from 'next/navigation';
|
||||||
|
|
||||||
import { MultiFactorChallengeContainer } from '@kit/auth/mfa';
|
import { MultiFactorChallengeContainer } from '@kit/auth/mfa';
|
||||||
|
import { pathsConfig } from '@kit/shared/config';
|
||||||
import { checkRequiresMultiFactorAuthentication } from '@kit/supabase/check-requires-mfa';
|
import { checkRequiresMultiFactorAuthentication } from '@kit/supabase/check-requires-mfa';
|
||||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||||
|
|
||||||
import { pathsConfig } from '@kit/shared/config';
|
|
||||||
|
|
||||||
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
|
|
||||||
@@ -41,7 +40,8 @@ async function VerifyPage(props: Props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const nextPath = (await props.searchParams).next;
|
const nextPath = (await props.searchParams).next;
|
||||||
const redirectPath = !!nextPath && nextPath.length > 0 ? nextPath : pathsConfig.app.home;
|
const redirectPath =
|
||||||
|
!!nextPath && nextPath.length > 0 ? nextPath : pathsConfig.app.home;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MultiFactorChallengeContainer
|
<MultiFactorChallengeContainer
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ const AnalysisDoctor = ({
|
|||||||
/>
|
/>
|
||||||
{endIcon || <div className="mx-2 w-4" />}
|
{endIcon || <div className="mx-2 w-4" />}
|
||||||
</>
|
</>
|
||||||
) : (isCancelled ? null : (
|
) : isCancelled ? null : (
|
||||||
<>
|
<>
|
||||||
<div className="flex items-center gap-3 sm:ml-auto">
|
<div className="flex items-center gap-3 sm:ml-auto">
|
||||||
<div className="font-semibold">
|
<div className="font-semibold">
|
||||||
@@ -140,7 +140,7 @@ const AnalysisDoctor = ({
|
|||||||
<div className="mx-8 w-[60px]"></div>
|
<div className="mx-8 w-[60px]"></div>
|
||||||
<AnalysisLevelBarSkeleton />
|
<AnalysisLevelBarSkeleton />
|
||||||
</>
|
</>
|
||||||
))}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { useMemo } from 'react';
|
|||||||
import { ArrowDown } from 'lucide-react';
|
import { ArrowDown } from 'lucide-react';
|
||||||
|
|
||||||
import { cn } from '@kit/ui/utils';
|
import { cn } from '@kit/ui/utils';
|
||||||
|
|
||||||
import { AnalysisResultForDisplay } from './analysis-doctor';
|
import { AnalysisResultForDisplay } from './analysis-doctor';
|
||||||
|
|
||||||
export enum AnalysisResultLevel {
|
export enum AnalysisResultLevel {
|
||||||
@@ -48,7 +49,7 @@ const Level = ({
|
|||||||
|
|
||||||
export const AnalysisLevelBarSkeleton = () => {
|
export const AnalysisLevelBarSkeleton = () => {
|
||||||
return (
|
return (
|
||||||
<div className="mt-4 flex h-3 w-[60%] sm:w-[35%] max-w-[360px] gap-1 sm:mt-0">
|
<div className="mt-4 flex h-3 w-[60%] max-w-[360px] gap-1 sm:mt-0 sm:w-[35%]">
|
||||||
<Level color="gray-200" />
|
<Level color="gray-200" />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -65,44 +66,46 @@ const AnalysisLevelBar = ({
|
|||||||
level: AnalysisResultLevel;
|
level: AnalysisResultLevel;
|
||||||
results: AnalysisResultForDisplay;
|
results: AnalysisResultForDisplay;
|
||||||
}) => {
|
}) => {
|
||||||
|
const {
|
||||||
const { norm_lower: lower, norm_upper: upper, response_value: value } = results;
|
norm_lower: lower,
|
||||||
|
norm_upper: upper,
|
||||||
|
response_value: value,
|
||||||
|
} = results;
|
||||||
const arrowLocation = useMemo(() => {
|
const arrowLocation = useMemo(() => {
|
||||||
if (value < lower!) {
|
if (value < lower!) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (normLowerIncluded || normUpperIncluded) {
|
if (normLowerIncluded || normUpperIncluded) {
|
||||||
return 50;
|
return 50;
|
||||||
}
|
}
|
||||||
|
|
||||||
const calculated = ((value - lower!) / (upper! - lower!)) * 100;
|
const calculated = ((value - lower!) / (upper! - lower!)) * 100;
|
||||||
|
|
||||||
if (calculated > 100) {
|
if (calculated > 100) {
|
||||||
return 100;
|
return 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
return calculated;
|
return calculated;
|
||||||
}, [value, upper, lower]);
|
}, [value, upper, lower]);
|
||||||
|
|
||||||
const [isVeryLow, isLow, isHigh, isVeryHigh] = useMemo(() => [
|
const [isVeryLow, isLow, isHigh, isVeryHigh] = useMemo(
|
||||||
level === AnalysisResultLevel.VERY_LOW,
|
() => [
|
||||||
level === AnalysisResultLevel.LOW,
|
level === AnalysisResultLevel.VERY_LOW,
|
||||||
level === AnalysisResultLevel.HIGH,
|
level === AnalysisResultLevel.LOW,
|
||||||
level === AnalysisResultLevel.VERY_HIGH,
|
level === AnalysisResultLevel.HIGH,
|
||||||
], [level, value, upper, lower]);
|
level === AnalysisResultLevel.VERY_HIGH,
|
||||||
|
],
|
||||||
|
[level, value, upper, lower],
|
||||||
|
);
|
||||||
|
|
||||||
const hasAbnormalLevel = isVeryLow || isLow || isHigh || isVeryHigh;
|
const hasAbnormalLevel = isVeryLow || isLow || isHigh || isVeryHigh;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mt-4 flex h-3 w-[60%] sm:w-[35%] max-w-[360px] gap-1 sm:mt-0">
|
<div className="mt-4 flex h-3 w-[60%] max-w-[360px] gap-1 sm:mt-0 sm:w-[35%]">
|
||||||
{normLowerIncluded && (
|
{normLowerIncluded && (
|
||||||
<>
|
<>
|
||||||
<Level
|
<Level isActive={isVeryLow} color="destructive" isFirst />
|
||||||
isActive={isVeryLow}
|
|
||||||
color="destructive"
|
|
||||||
isFirst
|
|
||||||
/>
|
|
||||||
<Level isActive={isLow} color="warning" />
|
<Level isActive={isLow} color="warning" />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
@@ -110,21 +113,16 @@ const AnalysisLevelBar = ({
|
|||||||
<Level
|
<Level
|
||||||
isFirst={!normLowerIncluded}
|
isFirst={!normLowerIncluded}
|
||||||
isLast={!normUpperIncluded}
|
isLast={!normUpperIncluded}
|
||||||
{...(hasAbnormalLevel ? { color: "warning", isActive: false } : { color: "success", isActive: true })}
|
{...(hasAbnormalLevel
|
||||||
|
? { color: 'warning', isActive: false }
|
||||||
|
: { color: 'success', isActive: true })}
|
||||||
arrowLocation={arrowLocation}
|
arrowLocation={arrowLocation}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{normUpperIncluded && (
|
{normUpperIncluded && (
|
||||||
<>
|
<>
|
||||||
<Level
|
<Level isActive={isHigh} color="warning" />
|
||||||
isActive={isHigh}
|
<Level isActive={isVeryHigh} color="destructive" isLast />
|
||||||
color="warning"
|
|
||||||
/>
|
|
||||||
<Level
|
|
||||||
isActive={isVeryHigh}
|
|
||||||
color="destructive"
|
|
||||||
isLast
|
|
||||||
/>
|
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -23,9 +23,7 @@ import {
|
|||||||
doctorAnalysisFeedbackFormSchema,
|
doctorAnalysisFeedbackFormSchema,
|
||||||
} from '@kit/doctor/schema/doctor-analysis.schema';
|
} from '@kit/doctor/schema/doctor-analysis.schema';
|
||||||
import ConfirmationModal from '@kit/shared/components/confirmation-modal';
|
import ConfirmationModal from '@kit/shared/components/confirmation-modal';
|
||||||
import {
|
import { useCurrentLocaleLanguageNames } from '@kit/shared/hooks';
|
||||||
useCurrentLocaleLanguageNames
|
|
||||||
} from '@kit/shared/hooks';
|
|
||||||
import { getFullName } from '@kit/shared/utils';
|
import { getFullName } from '@kit/shared/utils';
|
||||||
import { useUser } from '@kit/supabase/hooks/use-user';
|
import { useUser } from '@kit/supabase/hooks/use-user';
|
||||||
import { Button } from '@kit/ui/button';
|
import { Button } from '@kit/ui/button';
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
getUserDoneResponsesAction,
|
getUserDoneResponsesAction,
|
||||||
getUserInProgressResponsesAction,
|
getUserInProgressResponsesAction,
|
||||||
} from '@kit/doctor/actions/table-data-fetching-actions';
|
} from '@kit/doctor/actions/table-data-fetching-actions';
|
||||||
|
|
||||||
import ResultsTableWrapper from './results-table-wrapper';
|
import ResultsTableWrapper from './results-table-wrapper';
|
||||||
|
|
||||||
export default function Dashboard() {
|
export default function Dashboard() {
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import { notFound } from 'next/navigation';
|
import { notFound } from 'next/navigation';
|
||||||
|
|
||||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
|
||||||
import { isDoctor } from '@kit/doctor/lib/server/utils/is-doctor';
|
import { isDoctor } from '@kit/doctor/lib/server/utils/is-doctor';
|
||||||
|
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||||
|
|
||||||
type LayoutOrPageComponent<Params> = React.ComponentType<Params>;
|
type LayoutOrPageComponent<Params> = React.ComponentType<Params>;
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { useTransition } from 'react';
|
|||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
|
|
||||||
import { format } from 'date-fns';
|
import { format } from 'date-fns';
|
||||||
|
import { capitalize } from 'lodash';
|
||||||
import { Eye } from 'lucide-react';
|
import { Eye } from 'lucide-react';
|
||||||
|
|
||||||
import { getResultSetName } from '@kit/doctor/lib/helpers';
|
import { getResultSetName } from '@kit/doctor/lib/helpers';
|
||||||
@@ -26,7 +27,6 @@ import {
|
|||||||
import { Trans } from '@kit/ui/trans';
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
import DoctorJobSelect from './doctor-job-select';
|
import DoctorJobSelect from './doctor-job-select';
|
||||||
import { capitalize } from 'lodash';
|
|
||||||
|
|
||||||
export default function ResultsTable({
|
export default function ResultsTable({
|
||||||
results = [],
|
results = [],
|
||||||
@@ -189,7 +189,9 @@ export default function ResultsTable({
|
|||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
{capitalize(
|
{capitalize(
|
||||||
languageNames.of(result?.patient?.preferred_locale ?? 'et'),
|
languageNames.of(
|
||||||
|
result?.patient?.preferred_locale ?? 'et',
|
||||||
|
),
|
||||||
)}
|
)}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
|
|||||||
@@ -50,5 +50,3 @@ async function AnalysisPage({
|
|||||||
|
|
||||||
export default DoctorGuard(AnalysisPage);
|
export default DoctorGuard(AnalysisPage);
|
||||||
const loadResult = cache(getAnalysisResultsForDoctor);
|
const loadResult = cache(getAnalysisResultsForDoctor);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import { cookies } from 'next/headers';
|
|||||||
import { Page, PageMobileNavigation, PageNavigation } from '@kit/ui/page';
|
import { Page, PageMobileNavigation, PageNavigation } from '@kit/ui/page';
|
||||||
import { SidebarProvider } from '@kit/ui/shadcn-sidebar';
|
import { SidebarProvider } from '@kit/ui/shadcn-sidebar';
|
||||||
|
|
||||||
|
|
||||||
import { loadUserWorkspace } from '../home/(user)/_lib/server/load-user-workspace';
|
import { loadUserWorkspace } from '../home/(user)/_lib/server/load-user-workspace';
|
||||||
import { DoctorSidebar } from './_components/doctor-sidebar';
|
import { DoctorSidebar } from './_components/doctor-sidebar';
|
||||||
import { DoctorMobileNavigation } from './_components/mobile-navigation';
|
import { DoctorMobileNavigation } from './_components/mobile-navigation';
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ import Link from 'next/link';
|
|||||||
import { ArrowLeft, MessageCircle } from 'lucide-react';
|
import { ArrowLeft, MessageCircle } from 'lucide-react';
|
||||||
|
|
||||||
import { useCaptureException } from '@kit/monitoring/hooks';
|
import { useCaptureException } from '@kit/monitoring/hooks';
|
||||||
|
import { RootProviders } from '@kit/shared/components/root-providers';
|
||||||
import { Button } from '@kit/ui/button';
|
import { Button } from '@kit/ui/button';
|
||||||
import { Heading } from '@kit/ui/heading';
|
import { Heading } from '@kit/ui/heading';
|
||||||
import { Trans } from '@kit/ui/trans';
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
import { SiteHeader } from '~/(marketing)/_components/site-header';
|
import { SiteHeader } from '~/(marketing)/_components/site-header';
|
||||||
import { RootProviders } from '@kit/shared/components/root-providers';
|
|
||||||
|
|
||||||
const GlobalErrorPage = ({
|
const GlobalErrorPage = ({
|
||||||
error,
|
error,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { redirect } from 'next/navigation';
|
import { redirect } from 'next/navigation';
|
||||||
|
|
||||||
@@ -32,7 +33,7 @@ export default async function AnalysisResultsPage({
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
if (!account?.id) {
|
if (!account?.id) {
|
||||||
return redirect("/");
|
return redirect('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
await createPageViewLog({
|
await createPageViewLog({
|
||||||
@@ -47,27 +48,31 @@ export default async function AnalysisResultsPage({
|
|||||||
title={<Trans i18nKey="analysis-results:pageTitle" />}
|
title={<Trans i18nKey="analysis-results:pageTitle" />}
|
||||||
description={<Trans i18nKey="analysis-results:descriptionEmpty" />}
|
description={<Trans i18nKey="analysis-results:descriptionEmpty" />}
|
||||||
/>
|
/>
|
||||||
<PageBody className="gap-4">
|
<PageBody className="gap-4"></PageBody>
|
||||||
</PageBody>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const orderedAnalysisElements = analysisResponse.orderedAnalysisElements;
|
const orderedAnalysisElements = analysisResponse.orderedAnalysisElements;
|
||||||
const hasOrderedAnalysisElements = orderedAnalysisElements.length > 0;
|
const hasOrderedAnalysisElements = orderedAnalysisElements.length > 0;
|
||||||
const isPartialStatus = analysisResponse.order.status === 'PARTIAL_ANALYSIS_RESPONSE';
|
const isPartialStatus =
|
||||||
|
analysisResponse.order.status === 'PARTIAL_ANALYSIS_RESPONSE';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PageHeader
|
<PageHeader
|
||||||
title={<Trans i18nKey="analysis-results:pageTitle" />}
|
title={<Trans i18nKey="analysis-results:pageTitle" />}
|
||||||
description={hasOrderedAnalysisElements ? (
|
description={
|
||||||
isPartialStatus
|
hasOrderedAnalysisElements ? (
|
||||||
? <Trans i18nKey="analysis-results:descriptionPartial" />
|
isPartialStatus ? (
|
||||||
: <Trans i18nKey="analysis-results:description" />
|
<Trans i18nKey="analysis-results:descriptionPartial" />
|
||||||
) : (
|
) : (
|
||||||
<Trans i18nKey="analysis-results:descriptionEmpty" />
|
<Trans i18nKey="analysis-results:description" />
|
||||||
)}
|
)
|
||||||
|
) : (
|
||||||
|
<Trans i18nKey="analysis-results:descriptionEmpty" />
|
||||||
|
)
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
<Button asChild>
|
<Button asChild>
|
||||||
@@ -106,13 +111,15 @@ export default async function AnalysisResultsPage({
|
|||||||
orderedAnalysisElements.map((element, index) => (
|
orderedAnalysisElements.map((element, index) => (
|
||||||
<React.Fragment key={element.analysisIdOriginal}>
|
<React.Fragment key={element.analysisIdOriginal}>
|
||||||
<Analysis element={element} />
|
<Analysis element={element} />
|
||||||
{element.results?.nestedElements?.map((nestedElement, nestedIndex) => (
|
{element.results?.nestedElements?.map(
|
||||||
<Analysis
|
(nestedElement, nestedIndex) => (
|
||||||
key={`nested-${nestedElement.analysisElementOriginalId}-${nestedIndex}`}
|
<Analysis
|
||||||
nestedElement={nestedElement}
|
key={`nested-${nestedElement.analysisElementOriginalId}-${nestedIndex}`}
|
||||||
isNestedElement
|
nestedElement={nestedElement}
|
||||||
/>
|
isNestedElement
|
||||||
))}
|
/>
|
||||||
|
),
|
||||||
|
)}
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
))
|
))
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
|
|
||||||
|
import type { AnalysisResultDetailsElementResults } from '@/packages/features/user-analyses/src/types/analysis-results';
|
||||||
|
import { AnalysisResultLevel } from '@/packages/features/user-analyses/src/types/analysis-results';
|
||||||
import { ArrowDown } from 'lucide-react';
|
import { ArrowDown } from 'lucide-react';
|
||||||
|
|
||||||
import { cn } from '@kit/ui/utils';
|
import { cn } from '@kit/ui/utils';
|
||||||
import type { AnalysisResultDetailsElementResults } from '@/packages/features/user-analyses/src/types/analysis-results';
|
|
||||||
import { AnalysisResultLevel } from '@/packages/features/user-analyses/src/types/analysis-results';
|
|
||||||
|
|
||||||
type AnalysisResultLevelBarResults = Pick<AnalysisResultDetailsElementResults, 'normLower' | 'normUpper' | 'responseValue'>;
|
type AnalysisResultLevelBarResults = Pick<
|
||||||
|
AnalysisResultDetailsElementResults,
|
||||||
|
'normLower' | 'normUpper' | 'responseValue'
|
||||||
|
>;
|
||||||
|
|
||||||
const Level = ({
|
const Level = ({
|
||||||
isActive = false,
|
isActive = false,
|
||||||
@@ -34,22 +37,29 @@ const Level = ({
|
|||||||
{isActive && (
|
{isActive && (
|
||||||
<div
|
<div
|
||||||
className="absolute top-[-14px] left-1/2 -translate-x-1/2 rounded-[10px] bg-white p-[2px]"
|
className="absolute top-[-14px] left-1/2 -translate-x-1/2 rounded-[10px] bg-white p-[2px]"
|
||||||
{...(arrowLocation ? {
|
{...(arrowLocation
|
||||||
style: {
|
? {
|
||||||
left: `${arrowLocation}%`,
|
style: {
|
||||||
...(arrowLocation > 92.5 && { left: '92.5%' }),
|
left: `${arrowLocation}%`,
|
||||||
...(arrowLocation < 7.5 && { left: '7.5%' }),
|
...(arrowLocation > 92.5 && { left: '92.5%' }),
|
||||||
}
|
...(arrowLocation < 7.5 && { left: '7.5%' }),
|
||||||
} : {})}
|
},
|
||||||
|
}
|
||||||
|
: {})}
|
||||||
>
|
>
|
||||||
<ArrowDown strokeWidth={2} />
|
<ArrowDown strokeWidth={2} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{color === 'success' && typeof normRangeText === 'string' && (
|
{color === 'success' && typeof normRangeText === 'string' && (
|
||||||
<p className={cn("absolute bottom-[-18px] left-3/8 text-xs text-muted-foreground font-bold whitespace-nowrap", {
|
<p
|
||||||
'opacity-60': isActive,
|
className={cn(
|
||||||
})}>
|
'text-muted-foreground absolute bottom-[-18px] left-3/8 text-xs font-bold whitespace-nowrap',
|
||||||
|
{
|
||||||
|
'opacity-60': isActive,
|
||||||
|
},
|
||||||
|
)}
|
||||||
|
>
|
||||||
{normRangeText}
|
{normRangeText}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
@@ -59,11 +69,7 @@ const Level = ({
|
|||||||
|
|
||||||
const AnalysisLevelBar = ({
|
const AnalysisLevelBar = ({
|
||||||
level,
|
level,
|
||||||
results: {
|
results: { normLower: lower, normUpper: upper, responseValue: value },
|
||||||
normLower: lower,
|
|
||||||
normUpper: upper,
|
|
||||||
responseValue: value,
|
|
||||||
},
|
|
||||||
normRangeText,
|
normRangeText,
|
||||||
}: {
|
}: {
|
||||||
level: AnalysisResultLevel;
|
level: AnalysisResultLevel;
|
||||||
@@ -90,7 +96,7 @@ const AnalysisLevelBar = ({
|
|||||||
return 100; // Beyond upper bound
|
return 100; // Beyond upper bound
|
||||||
}
|
}
|
||||||
|
|
||||||
// If only lower bound exists
|
// If only lower bound exists
|
||||||
if (upper === null && lower !== null) {
|
if (upper === null && lower !== null) {
|
||||||
if (value >= lower) {
|
if (value >= lower) {
|
||||||
// Value is in normal range (above lower bound)
|
// Value is in normal range (above lower bound)
|
||||||
@@ -127,7 +133,7 @@ const AnalysisLevelBar = ({
|
|||||||
// If pending results, show gray bar
|
// If pending results, show gray bar
|
||||||
if (isPending) {
|
if (isPending) {
|
||||||
return (
|
return (
|
||||||
<div className="mt-4 flex h-3 w-60% sm:w-[35%] max-w-[360px] gap-1 sm:mt-0">
|
<div className="w-60% mt-4 flex h-3 max-w-[360px] gap-1 sm:mt-0 sm:w-[35%]">
|
||||||
<Level color="gray-200" isFirst isLast />
|
<Level color="gray-200" isFirst isLast />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -146,29 +152,25 @@ const AnalysisLevelBar = ({
|
|||||||
const [warning, normal, critical] = [
|
const [warning, normal, critical] = [
|
||||||
{
|
{
|
||||||
isActive: isWarning,
|
isActive: isWarning,
|
||||||
color: "warning",
|
color: 'warning',
|
||||||
...(isWarning ? { arrowLocation } : {}),
|
...(isWarning ? { arrowLocation } : {}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
isActive: isNormal,
|
isActive: isNormal,
|
||||||
color: "success",
|
color: 'success',
|
||||||
normRangeText,
|
normRangeText,
|
||||||
...(isNormal ? { arrowLocation } : {}),
|
...(isNormal ? { arrowLocation } : {}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
isActive: isCritical,
|
isActive: isCritical,
|
||||||
color: "destructive",
|
color: 'destructive',
|
||||||
isLast: true,
|
isLast: true,
|
||||||
...(isCritical ? { arrowLocation } : {}),
|
...(isCritical ? { arrowLocation } : {}),
|
||||||
},
|
},
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
if (!hasLowerBound) {
|
if (!hasLowerBound) {
|
||||||
return [
|
return [{ ...normal, isFirst: true }, warning, critical] as const;
|
||||||
{ ...normal, isFirst: true },
|
|
||||||
warning,
|
|
||||||
critical,
|
|
||||||
] as const;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
@@ -176,16 +178,27 @@ const AnalysisLevelBar = ({
|
|||||||
normal,
|
normal,
|
||||||
{ ...critical, isLast: true },
|
{ ...critical, isLast: true },
|
||||||
] as const;
|
] as const;
|
||||||
}, [isValueBelowLower, isValueAboveUpper, isValueInNormalRange, arrowLocation, normRangeText, isNormal, isWarning, isCritical]);
|
}, [
|
||||||
|
isValueBelowLower,
|
||||||
|
isValueAboveUpper,
|
||||||
|
isValueInNormalRange,
|
||||||
|
arrowLocation,
|
||||||
|
normRangeText,
|
||||||
|
isNormal,
|
||||||
|
isWarning,
|
||||||
|
isCritical,
|
||||||
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cn(
|
<div
|
||||||
"flex h-3 gap-1",
|
className={cn(
|
||||||
"mt-4 sm:mt-0",
|
'flex h-3 gap-1',
|
||||||
"w-[60%] sm:w-[35%]",
|
'mt-4 sm:mt-0',
|
||||||
"min-w-[50vw] sm:min-w-auto",
|
'w-[60%] sm:w-[35%]',
|
||||||
"max-w-[360px]",
|
'min-w-[50vw] sm:min-w-auto',
|
||||||
)}>
|
'max-w-[360px]',
|
||||||
|
)}
|
||||||
|
>
|
||||||
<Level {...first} />
|
<Level {...first} />
|
||||||
<Level {...second} />
|
<Level {...second} />
|
||||||
<Level {...third} />
|
<Level {...third} />
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import React, { useMemo, useState } from 'react';
|
import React, { useMemo, useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
|
||||||
import { format } from 'date-fns';
|
|
||||||
import { Info } from 'lucide-react';
|
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
AnalysisResultDetailsElement,
|
AnalysisResultDetailsElement,
|
||||||
AnalysisResultsDetailsElementNested,
|
AnalysisResultsDetailsElementNested,
|
||||||
} from '@/packages/features/user-analyses/src/types/analysis-results';
|
} from '@/packages/features/user-analyses/src/types/analysis-results';
|
||||||
import { AnalysisResultLevel } from '@/packages/features/user-analyses/src/types/analysis-results';
|
import { AnalysisResultLevel } from '@/packages/features/user-analyses/src/types/analysis-results';
|
||||||
|
import { format } from 'date-fns';
|
||||||
|
import { Info } from 'lucide-react';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import { Trans } from '@kit/ui/trans';
|
import { Trans } from '@kit/ui/trans';
|
||||||
import { cn } from '@kit/ui/utils';
|
import { cn } from '@kit/ui/utils';
|
||||||
|
|
||||||
@@ -64,7 +65,11 @@ const Analysis = ({
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { responseValue, responseValueIsNegative, responseValueIsWithinNorm } = results;
|
const {
|
||||||
|
responseValue,
|
||||||
|
responseValueIsNegative,
|
||||||
|
responseValueIsWithinNorm,
|
||||||
|
} = results;
|
||||||
if (responseValue === null || responseValue === undefined) {
|
if (responseValue === null || responseValue === undefined) {
|
||||||
if (hasIsNegative) {
|
if (hasIsNegative) {
|
||||||
if (responseValueIsNegative) {
|
if (responseValueIsNegative) {
|
||||||
@@ -107,7 +112,8 @@ const Analysis = ({
|
|||||||
|
|
||||||
const isCancelled = Number(results?.status) === 5;
|
const isCancelled = Number(results?.status) === 5;
|
||||||
const nestedElements = results?.nestedElements ?? null;
|
const nestedElements = results?.nestedElements ?? null;
|
||||||
const hasNestedElements = Array.isArray(nestedElements) && nestedElements.length > 0;
|
const hasNestedElements =
|
||||||
|
Array.isArray(nestedElements) && nestedElements.length > 0;
|
||||||
|
|
||||||
const normRangeText = (() => {
|
const normRangeText = (() => {
|
||||||
if (normLower === null && normUpper === null) {
|
if (normLower === null && normUpper === null) {
|
||||||
@@ -118,9 +124,17 @@ const Analysis = ({
|
|||||||
const hasTextualResponse = hasIsNegative || hasIsWithinNorm;
|
const hasTextualResponse = hasIsNegative || hasIsWithinNorm;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cn("border-border rounded-lg border px-5", { 'ml-8': isNestedElement })}>
|
<div
|
||||||
<div className="flex flex-col items-center justify-between gap-2 pt-3 pb-6 sm:py-3 sm:h-[65px] sm:flex-row sm:gap-0">
|
className={cn('border-border rounded-lg border px-5', {
|
||||||
<div className={cn("flex items-center gap-2 font-semibold", { 'font-bold': isNestedElement })}>
|
'ml-8': isNestedElement,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<div className="flex flex-col items-center justify-between gap-2 pt-3 pb-6 sm:h-[65px] sm:flex-row sm:gap-0 sm:py-3">
|
||||||
|
<div
|
||||||
|
className={cn('flex items-center gap-2 font-semibold', {
|
||||||
|
'font-bold': isNestedElement,
|
||||||
|
})}
|
||||||
|
>
|
||||||
{name}
|
{name}
|
||||||
{results?.responseTime && (
|
{results?.responseTime && (
|
||||||
<div
|
<div
|
||||||
@@ -147,7 +161,7 @@ const Analysis = ({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{isCancelled && (
|
{isCancelled && (
|
||||||
<div className="text-red-600 font-semibold text-sm">
|
<div className="text-sm font-semibold text-red-600">
|
||||||
<Trans i18nKey="analysis-results:cancelled" />
|
<Trans i18nKey="analysis-results:cancelled" />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -157,9 +171,15 @@ const Analysis = ({
|
|||||||
<div className="flex items-center gap-3 sm:ml-auto">
|
<div className="flex items-center gap-3 sm:ml-auto">
|
||||||
<div
|
<div
|
||||||
className={cn('font-semibold', {
|
className={cn('font-semibold', {
|
||||||
'text-yellow-600': hasTextualResponse && analysisResultLevel === AnalysisResultLevel.WARNING,
|
'text-yellow-600':
|
||||||
'text-red-600': hasTextualResponse && analysisResultLevel === AnalysisResultLevel.CRITICAL,
|
hasTextualResponse &&
|
||||||
'text-green-600': hasTextualResponse && analysisResultLevel === AnalysisResultLevel.NORMAL,
|
analysisResultLevel === AnalysisResultLevel.WARNING,
|
||||||
|
'text-red-600':
|
||||||
|
hasTextualResponse &&
|
||||||
|
analysisResultLevel === AnalysisResultLevel.CRITICAL,
|
||||||
|
'text-green-600':
|
||||||
|
hasTextualResponse &&
|
||||||
|
analysisResultLevel === AnalysisResultLevel.NORMAL,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
{value}
|
{value}
|
||||||
|
|||||||
@@ -2,10 +2,11 @@
|
|||||||
|
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
|
|
||||||
|
import Modal from '@modules/common/components/modal';
|
||||||
|
|
||||||
import { PageBody, PageHeader } from '@kit/ui/page';
|
import { PageBody, PageHeader } from '@kit/ui/page';
|
||||||
import { Trans } from '@kit/ui/trans';
|
|
||||||
import { Button } from '@kit/ui/shadcn/button';
|
import { Button } from '@kit/ui/shadcn/button';
|
||||||
import Modal from "@modules/common/components/modal"
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
import Analysis from '../_components/analysis';
|
import Analysis from '../_components/analysis';
|
||||||
import { analysisResponses } from './test-responses';
|
import { analysisResponses } from './test-responses';
|
||||||
@@ -19,16 +20,15 @@ export default function AnalysisResultsPage() {
|
|||||||
<PageBody className="gap-4">
|
<PageBody className="gap-4">
|
||||||
<div className="mt-8 flex flex-col justify-between gap-4 sm:flex-row sm:items-center sm:gap-0">
|
<div className="mt-8 flex flex-col justify-between gap-4 sm:flex-row sm:items-center sm:gap-0">
|
||||||
<div>
|
<div>
|
||||||
<h2>
|
<h2>Analüüsi tulemused demo</h2>
|
||||||
Analüüsi tulemused demo
|
|
||||||
</h2>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex flex-col gap-2">
|
<div className="flex flex-col gap-2">
|
||||||
{analysisResponses.map(({ id, orderedAnalysisElements }, index) => {
|
{analysisResponses.map(({ id, orderedAnalysisElements }, index) => {
|
||||||
const isOpen = openBlocks.includes(id);
|
const isOpen = openBlocks.includes(id);
|
||||||
const closeModal = () => setOpenBlocks(openBlocks.filter((block) => block !== id));
|
const closeModal = () =>
|
||||||
|
setOpenBlocks(openBlocks.filter((block) => block !== id));
|
||||||
return (
|
return (
|
||||||
<div key={index} className="flex flex-col gap-2 py-4">
|
<div key={index} className="flex flex-col gap-2 py-4">
|
||||||
<div className="flex flex-col gap-2 pb-4">
|
<div className="flex flex-col gap-2 pb-4">
|
||||||
@@ -52,12 +52,21 @@ export default function AnalysisResultsPage() {
|
|||||||
{isOpen && (
|
{isOpen && (
|
||||||
<Modal isOpen={isOpen} close={closeModal} size="large">
|
<Modal isOpen={isOpen} close={closeModal} size="large">
|
||||||
<div className="overflow-y-auto">
|
<div className="overflow-y-auto">
|
||||||
|
|
||||||
<p>NormiStaatus</p>
|
<p>NormiStaatus</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>0 - testi väärtus jääb normaalväärtuste piirkonda või on määramata,</li>
|
<li>
|
||||||
<li>1 - testi väärtus jääb hoiatava (tähelepanu suunava) märkega piirkonda,</li>
|
0 - testi väärtus jääb normaalväärtuste piirkonda
|
||||||
<li>2 - testi väärtus on normaalväärtuste piirkonnast väljas või kõrgendatud tähelepanu nõudvas piirkonnas.</li>
|
või on määramata,
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
1 - testi väärtus jääb hoiatava (tähelepanu
|
||||||
|
suunava) märkega piirkonda,
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
2 - testi väärtus on normaalväärtuste piirkonnast
|
||||||
|
väljas või kõrgendatud tähelepanu nõudvas
|
||||||
|
piirkonnas.
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<p>UuringOlek</p>
|
<p>UuringOlek</p>
|
||||||
@@ -70,7 +79,7 @@ export default function AnalysisResultsPage() {
|
|||||||
<li>6 - Tühistatud,</li>
|
<li>6 - Tühistatud,</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<pre className="text-sm bg-muted p-4 rounded-md">
|
<pre className="bg-muted rounded-md p-4 text-sm">
|
||||||
{JSON.stringify(orderedAnalysisElements, null, 2)}
|
{JSON.stringify(orderedAnalysisElements, null, 2)}
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
@@ -90,7 +99,7 @@ export default function AnalysisResultsPage() {
|
|||||||
</div>
|
</div>
|
||||||
<hr />
|
<hr />
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
</PageBody>
|
</PageBody>
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,46 +1,52 @@
|
|||||||
'use server';
|
'use server';
|
||||||
|
|
||||||
|
import { MontonioOrderToken } from '@/app/home/(user)/_components/cart/types';
|
||||||
|
import { loadCurrentUserAccount } from '@/app/home/(user)/_lib/server/load-user-account';
|
||||||
|
import { placeOrder, retrieveCart } from '@lib/data/cart';
|
||||||
|
import { listProductTypes } from '@lib/data/products';
|
||||||
|
import type { StoreOrder } from '@medusajs/types';
|
||||||
import jwt from 'jsonwebtoken';
|
import jwt from 'jsonwebtoken';
|
||||||
import { z } from "zod";
|
import { z } from 'zod';
|
||||||
import { MontonioOrderToken } from "@/app/home/(user)/_components/cart/types";
|
|
||||||
import { loadCurrentUserAccount } from "@/app/home/(user)/_lib/server/load-user-account";
|
import type { AccountWithParams } from '@kit/accounts/types/accounts';
|
||||||
import { listProductTypes } from "@lib/data/products";
|
|
||||||
import { placeOrder, retrieveCart } from "@lib/data/cart";
|
|
||||||
import { createI18nServerInstance } from "~/lib/i18n/i18n.server";
|
|
||||||
import { createAnalysisOrder, getAnalysisOrder } from '~/lib/services/order.service';
|
|
||||||
import { sendOrderToMedipost } from '~/lib/services/medipost/medipostPrivateMessage.service';
|
|
||||||
import { getOrderedAnalysisIds } from '~/lib/services/medusaOrder.service';
|
|
||||||
import { createNotificationsApi } from '@kit/notifications/api';
|
import { createNotificationsApi } from '@kit/notifications/api';
|
||||||
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
||||||
import type { AccountWithParams } from '@kit/accounts/types/accounts';
|
|
||||||
import type { StoreOrder } from '@medusajs/types';
|
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
||||||
|
import { sendOrderToMedipost } from '~/lib/services/medipost/medipostPrivateMessage.service';
|
||||||
|
import { getOrderedAnalysisIds } from '~/lib/services/medusaOrder.service';
|
||||||
|
import {
|
||||||
|
createAnalysisOrder,
|
||||||
|
getAnalysisOrder,
|
||||||
|
} from '~/lib/services/order.service';
|
||||||
|
|
||||||
const ANALYSIS_PACKAGES_TYPE_HANDLE = 'analysis-packages';
|
const ANALYSIS_PACKAGES_TYPE_HANDLE = 'analysis-packages';
|
||||||
const ANALYSIS_TYPE_HANDLE = 'synlab-analysis';
|
const ANALYSIS_TYPE_HANDLE = 'synlab-analysis';
|
||||||
const MONTONIO_PAID_STATUS = 'PAID';
|
const MONTONIO_PAID_STATUS = 'PAID';
|
||||||
|
|
||||||
const env = () => z
|
const env = () =>
|
||||||
.object({
|
z
|
||||||
emailSender: z
|
.object({
|
||||||
.string({
|
emailSender: z
|
||||||
error: 'EMAIL_SENDER is required',
|
.string({
|
||||||
})
|
error: 'EMAIL_SENDER is required',
|
||||||
.min(1),
|
})
|
||||||
siteUrl: z
|
.min(1),
|
||||||
.string({
|
siteUrl: z
|
||||||
error: 'NEXT_PUBLIC_SITE_URL is required',
|
.string({
|
||||||
})
|
error: 'NEXT_PUBLIC_SITE_URL is required',
|
||||||
.min(1),
|
})
|
||||||
isEnabledDispatchOnMontonioCallback: z
|
.min(1),
|
||||||
.boolean({
|
isEnabledDispatchOnMontonioCallback: z.boolean({
|
||||||
error: 'MEDIPOST_ENABLE_DISPATCH_ON_MONTONIO_CALLBACK is required',
|
error: 'MEDIPOST_ENABLE_DISPATCH_ON_MONTONIO_CALLBACK is required',
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
.parse({
|
.parse({
|
||||||
emailSender: process.env.EMAIL_SENDER,
|
emailSender: process.env.EMAIL_SENDER,
|
||||||
siteUrl: process.env.NEXT_PUBLIC_SITE_URL!,
|
siteUrl: process.env.NEXT_PUBLIC_SITE_URL!,
|
||||||
isEnabledDispatchOnMontonioCallback: process.env.MEDIPOST_ENABLE_DISPATCH_ON_MONTONIO_CALLBACK === 'true',
|
isEnabledDispatchOnMontonioCallback:
|
||||||
});
|
process.env.MEDIPOST_ENABLE_DISPATCH_ON_MONTONIO_CALLBACK === 'true',
|
||||||
|
});
|
||||||
|
|
||||||
const sendEmail = async ({
|
const sendEmail = async ({
|
||||||
account,
|
account,
|
||||||
@@ -49,15 +55,17 @@ const sendEmail = async ({
|
|||||||
partnerLocationName,
|
partnerLocationName,
|
||||||
language,
|
language,
|
||||||
}: {
|
}: {
|
||||||
account: Pick<AccountWithParams, 'name' | 'id'>,
|
account: Pick<AccountWithParams, 'name' | 'id'>;
|
||||||
email: string,
|
email: string;
|
||||||
analysisPackageName: string,
|
analysisPackageName: string;
|
||||||
partnerLocationName: string,
|
partnerLocationName: string;
|
||||||
language: string,
|
language: string;
|
||||||
}) => {
|
}) => {
|
||||||
const client = getSupabaseServerAdminClient();
|
const client = getSupabaseServerAdminClient();
|
||||||
try {
|
try {
|
||||||
const { renderSynlabAnalysisPackageEmail } = await import('@kit/email-templates');
|
const { renderSynlabAnalysisPackageEmail } = await import(
|
||||||
|
'@kit/email-templates'
|
||||||
|
);
|
||||||
const { getMailer } = await import('@kit/mailers');
|
const { getMailer } = await import('@kit/mailers');
|
||||||
|
|
||||||
const mailer = await getMailer();
|
const mailer = await getMailer();
|
||||||
@@ -79,15 +87,14 @@ const sendEmail = async ({
|
|||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
throw new Error(`Failed to send email, message=${error}`);
|
throw new Error(`Failed to send email, message=${error}`);
|
||||||
});
|
});
|
||||||
await createNotificationsApi(client)
|
await createNotificationsApi(client).createNotification({
|
||||||
.createNotification({
|
account_id: account.id,
|
||||||
account_id: account.id,
|
body: html,
|
||||||
body: html,
|
});
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(`Failed to send email, message=${error}`);
|
throw new Error(`Failed to send email, message=${error}`);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
async function decodeOrderToken(orderToken: string) {
|
async function decodeOrderToken(orderToken: string) {
|
||||||
const secretKey = process.env.MONTONIO_SECRET_KEY as string;
|
const secretKey = process.env.MONTONIO_SECRET_KEY as string;
|
||||||
@@ -97,7 +104,7 @@ async function decodeOrderToken(orderToken: string) {
|
|||||||
}) as MontonioOrderToken;
|
}) as MontonioOrderToken;
|
||||||
|
|
||||||
if (decoded.paymentStatus !== MONTONIO_PAID_STATUS) {
|
if (decoded.paymentStatus !== MONTONIO_PAID_STATUS) {
|
||||||
throw new Error("Payment not successful");
|
throw new Error('Payment not successful');
|
||||||
}
|
}
|
||||||
|
|
||||||
return decoded;
|
return decoded;
|
||||||
@@ -106,38 +113,49 @@ async function decodeOrderToken(orderToken: string) {
|
|||||||
async function getCartByOrderToken(decoded: MontonioOrderToken) {
|
async function getCartByOrderToken(decoded: MontonioOrderToken) {
|
||||||
const [, , cartId] = decoded.merchantReferenceDisplay.split(':');
|
const [, , cartId] = decoded.merchantReferenceDisplay.split(':');
|
||||||
if (!cartId) {
|
if (!cartId) {
|
||||||
throw new Error("Cart ID not found");
|
throw new Error('Cart ID not found');
|
||||||
}
|
}
|
||||||
const cart = await retrieveCart(cartId);
|
const cart = await retrieveCart(cartId);
|
||||||
if (!cart) {
|
if (!cart) {
|
||||||
throw new Error("Cart not found");
|
throw new Error('Cart not found');
|
||||||
}
|
}
|
||||||
return cart;
|
return cart;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getOrderResultParameters(medusaOrder: StoreOrder) {
|
async function getOrderResultParameters(medusaOrder: StoreOrder) {
|
||||||
const { productTypes } = await listProductTypes();
|
const { productTypes } = await listProductTypes();
|
||||||
const analysisPackagesType = productTypes.find(({ metadata }) => metadata?.handle === ANALYSIS_PACKAGES_TYPE_HANDLE);
|
const analysisPackagesType = productTypes.find(
|
||||||
const analysisType = productTypes.find(({ metadata }) => metadata?.handle === ANALYSIS_TYPE_HANDLE);
|
({ metadata }) => metadata?.handle === ANALYSIS_PACKAGES_TYPE_HANDLE,
|
||||||
|
);
|
||||||
|
const analysisType = productTypes.find(
|
||||||
|
({ metadata }) => metadata?.handle === ANALYSIS_TYPE_HANDLE,
|
||||||
|
);
|
||||||
|
|
||||||
const analysisPackageOrderItem = medusaOrder.items?.find(({ product_type_id }) => product_type_id === analysisPackagesType?.id);
|
const analysisPackageOrderItem = medusaOrder.items?.find(
|
||||||
const analysisItems = medusaOrder.items?.filter(({ product_type_id }) => product_type_id === analysisType?.id);
|
({ product_type_id }) => product_type_id === analysisPackagesType?.id,
|
||||||
|
);
|
||||||
|
const analysisItems = medusaOrder.items?.filter(
|
||||||
|
({ product_type_id }) => product_type_id === analysisType?.id,
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
medusaOrderId: medusaOrder.id,
|
medusaOrderId: medusaOrder.id,
|
||||||
email: medusaOrder.email,
|
email: medusaOrder.email,
|
||||||
analysisPackageOrder: analysisPackageOrderItem
|
analysisPackageOrder: analysisPackageOrderItem
|
||||||
? {
|
? {
|
||||||
partnerLocationName: analysisPackageOrderItem?.metadata?.partner_location_name as string ?? '',
|
partnerLocationName:
|
||||||
analysisPackageName: analysisPackageOrderItem?.title ?? '',
|
(analysisPackageOrderItem?.metadata
|
||||||
}
|
?.partner_location_name as string) ?? '',
|
||||||
: null,
|
analysisPackageName: analysisPackageOrderItem?.title ?? '',
|
||||||
analysisItemsOrder: Array.isArray(analysisItems) && analysisItems.length > 0
|
}
|
||||||
? analysisItems.map(({ product }) => ({
|
|
||||||
analysisName: product?.title ?? '',
|
|
||||||
analysisId: product?.metadata?.analysisIdOriginal as string ?? '',
|
|
||||||
}))
|
|
||||||
: null,
|
: null,
|
||||||
|
analysisItemsOrder:
|
||||||
|
Array.isArray(analysisItems) && analysisItems.length > 0
|
||||||
|
? analysisItems.map(({ product }) => ({
|
||||||
|
analysisName: product?.title ?? '',
|
||||||
|
analysisId: (product?.metadata?.analysisIdOriginal as string) ?? '',
|
||||||
|
}))
|
||||||
|
: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,12 +164,12 @@ async function sendAnalysisPackageOrderEmail({
|
|||||||
email,
|
email,
|
||||||
analysisPackageOrder,
|
analysisPackageOrder,
|
||||||
}: {
|
}: {
|
||||||
account: AccountWithParams,
|
account: AccountWithParams;
|
||||||
email: string,
|
email: string;
|
||||||
analysisPackageOrder: {
|
analysisPackageOrder: {
|
||||||
partnerLocationName: string,
|
partnerLocationName: string;
|
||||||
analysisPackageName: string,
|
analysisPackageName: string;
|
||||||
},
|
};
|
||||||
}) {
|
}) {
|
||||||
const { language } = await createI18nServerInstance();
|
const { language } = await createI18nServerInstance();
|
||||||
const { analysisPackageName, partnerLocationName } = analysisPackageOrder;
|
const { analysisPackageName, partnerLocationName } = analysisPackageOrder;
|
||||||
@@ -165,51 +183,72 @@ async function sendAnalysisPackageOrderEmail({
|
|||||||
});
|
});
|
||||||
console.info(`Successfully sent analysis package order email to ${email}`);
|
console.info(`Successfully sent analysis package order email to ${email}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Failed to send analysis package order email to ${email}`, error);
|
console.error(
|
||||||
|
`Failed to send analysis package order email to ${email}`,
|
||||||
|
error,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function processMontonioCallback(orderToken: string) {
|
export async function processMontonioCallback(orderToken: string) {
|
||||||
const { account } = await loadCurrentUserAccount();
|
const { account } = await loadCurrentUserAccount();
|
||||||
if (!account) {
|
if (!account) {
|
||||||
throw new Error("Account not found in context");
|
throw new Error('Account not found in context');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const decoded = await decodeOrderToken(orderToken);
|
const decoded = await decodeOrderToken(orderToken);
|
||||||
const cart = await getCartByOrderToken(decoded);
|
const cart = await getCartByOrderToken(decoded);
|
||||||
|
|
||||||
const medusaOrder = await placeOrder(cart.id, { revalidateCacheTags: false });
|
const medusaOrder = await placeOrder(cart.id, {
|
||||||
const orderedAnalysisElements = await getOrderedAnalysisIds({ medusaOrder });
|
revalidateCacheTags: false,
|
||||||
|
});
|
||||||
|
const orderedAnalysisElements = await getOrderedAnalysisIds({
|
||||||
|
medusaOrder,
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const existingAnalysisOrder = await getAnalysisOrder({ medusaOrderId: medusaOrder.id });
|
const existingAnalysisOrder = await getAnalysisOrder({
|
||||||
console.info(`Analysis order already exists for medusaOrderId=${medusaOrder.id}, orderId=${existingAnalysisOrder.id}`);
|
medusaOrderId: medusaOrder.id,
|
||||||
|
});
|
||||||
|
console.info(
|
||||||
|
`Analysis order already exists for medusaOrderId=${medusaOrder.id}, orderId=${existingAnalysisOrder.id}`,
|
||||||
|
);
|
||||||
return { success: true, orderId: existingAnalysisOrder.id };
|
return { success: true, orderId: existingAnalysisOrder.id };
|
||||||
} catch {
|
} catch {
|
||||||
// ignored
|
// ignored
|
||||||
}
|
}
|
||||||
|
|
||||||
const orderId = await createAnalysisOrder({ medusaOrder, orderedAnalysisElements });
|
const orderId = await createAnalysisOrder({
|
||||||
|
medusaOrder,
|
||||||
|
orderedAnalysisElements,
|
||||||
|
});
|
||||||
const orderResult = await getOrderResultParameters(medusaOrder);
|
const orderResult = await getOrderResultParameters(medusaOrder);
|
||||||
|
|
||||||
const { medusaOrderId, email, analysisPackageOrder, analysisItemsOrder } = orderResult;
|
const { medusaOrderId, email, analysisPackageOrder, analysisItemsOrder } =
|
||||||
|
orderResult;
|
||||||
|
|
||||||
if (email) {
|
if (email) {
|
||||||
if (analysisPackageOrder) {
|
if (analysisPackageOrder) {
|
||||||
await sendAnalysisPackageOrderEmail({ account, email, analysisPackageOrder });
|
await sendAnalysisPackageOrderEmail({
|
||||||
|
account,
|
||||||
|
email,
|
||||||
|
analysisPackageOrder,
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
console.info(`Order has no analysis package, skipping email.`);
|
console.info(`Order has no analysis package, skipping email.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (analysisItemsOrder) {
|
if (analysisItemsOrder) {
|
||||||
// @TODO send email for separate analyses
|
// @TODO send email for separate analyses
|
||||||
console.warn(`Order has analysis items, but no email template exists yet`);
|
console.warn(
|
||||||
|
`Order has analysis items, but no email template exists yet`,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
console.info(`Order has no analysis items, skipping email.`);
|
console.info(`Order has no analysis items, skipping email.`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.error("Missing email to send order result email", orderResult);
|
console.error('Missing email to send order result email', orderResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (env().isEnabledDispatchOnMontonioCallback) {
|
if (env().isEnabledDispatchOnMontonioCallback) {
|
||||||
@@ -218,7 +257,7 @@ export async function processMontonioCallback(orderToken: string) {
|
|||||||
|
|
||||||
return { success: true, orderId };
|
return { success: true, orderId };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to place order", error);
|
console.error('Failed to place order', error);
|
||||||
throw new Error(`Failed to place order, message=${error}`);
|
throw new Error(`Failed to place order, message=${error}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
|
|
||||||
import { processMontonioCallback } from './actions';
|
import { processMontonioCallback } from './actions';
|
||||||
|
|
||||||
export default function MontonioCallbackClient({ orderToken, error }: {
|
export default function MontonioCallbackClient({
|
||||||
|
orderToken,
|
||||||
|
error,
|
||||||
|
}: {
|
||||||
orderToken?: string;
|
orderToken?: string;
|
||||||
error?: string;
|
error?: string;
|
||||||
}) {
|
}) {
|
||||||
@@ -32,7 +37,7 @@ export default function MontonioCallbackClient({ orderToken, error }: {
|
|||||||
const { orderId } = await processMontonioCallback(orderToken);
|
const { orderId } = await processMontonioCallback(orderToken);
|
||||||
router.push(`/home/order/${orderId}/confirmed`);
|
router.push(`/home/order/${orderId}/confirmed`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to place order", error);
|
console.error('Failed to place order', error);
|
||||||
router.push('/home/cart/montonio-callback/error');
|
router.push('/home/cart/montonio-callback/error');
|
||||||
} finally {
|
} finally {
|
||||||
setIsProcessing(false);
|
setIsProcessing(false);
|
||||||
@@ -43,9 +48,9 @@ export default function MontonioCallbackClient({ orderToken, error }: {
|
|||||||
}, [orderToken, error, router, hasProcessed, isProcessing]);
|
}, [orderToken, error, router, hasProcessed, isProcessing]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex mt-10 justify-center min-h-screen">
|
<div className="mt-10 flex min-h-screen justify-center">
|
||||||
<div className="text-center">
|
<div className="text-center">
|
||||||
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-primary mx-auto mb-4"></div>
|
<div className="border-primary mx-auto mb-4 h-12 w-12 animate-spin rounded-full border-b-2"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
|
|
||||||
import { PageBody, PageHeader } from '@/packages/ui/src/makerkit/page';
|
|
||||||
import { createI18nServerInstance } from '@/lib/i18n/i18n.server';
|
import { createI18nServerInstance } from '@/lib/i18n/i18n.server';
|
||||||
import { Trans } from '@kit/ui/trans';
|
import { PageBody, PageHeader } from '@/packages/ui/src/makerkit/page';
|
||||||
|
|
||||||
|
import { Button } from '@kit/ui/button';
|
||||||
import { Alert, AlertDescription } from '@kit/ui/shadcn/alert';
|
import { Alert, AlertDescription } from '@kit/ui/shadcn/alert';
|
||||||
import { AlertTitle } from '@kit/ui/shadcn/alert';
|
import { AlertTitle } from '@kit/ui/shadcn/alert';
|
||||||
import { Button } from '@kit/ui/button';
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
export async function generateMetadata() {
|
export async function generateMetadata() {
|
||||||
const { t } = await createI18nServerInstance();
|
const { t } = await createI18nServerInstance();
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
import MontonioCallbackClient from './client-component';
|
import MontonioCallbackClient from './client-component';
|
||||||
|
|
||||||
export default async function MontonioCallbackPage({ searchParams }: {
|
export default async function MontonioCallbackPage({
|
||||||
|
searchParams,
|
||||||
|
}: {
|
||||||
searchParams: Promise<{
|
searchParams: Promise<{
|
||||||
'order-token'?: string;
|
'order-token'?: string;
|
||||||
}>;
|
}>;
|
||||||
}) {
|
}) {
|
||||||
const orderToken = (await searchParams)['order-token'];
|
const orderToken = (await searchParams)['order-token'];
|
||||||
|
|
||||||
if (!orderToken) {
|
if (!orderToken) {
|
||||||
return <MontonioCallbackClient error="Order token is missing" />;
|
return <MontonioCallbackClient error="Order token is missing" />;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
import { createI18nServerInstance } from '@/lib/i18n/i18n.server';
|
|
||||||
import { PageBody, PageHeader } from '@/packages/ui/src/makerkit/page';
|
|
||||||
|
|
||||||
import { notFound } from 'next/navigation';
|
import { notFound } from 'next/navigation';
|
||||||
|
|
||||||
|
import { createI18nServerInstance } from '@/lib/i18n/i18n.server';
|
||||||
|
import { PageBody, PageHeader } from '@/packages/ui/src/makerkit/page';
|
||||||
import { retrieveCart } from '@lib/data/cart';
|
import { retrieveCart } from '@lib/data/cart';
|
||||||
import Cart from '../../_components/cart';
|
|
||||||
import { listProductTypes } from '@lib/data/products';
|
import { listProductTypes } from '@lib/data/products';
|
||||||
import CartTimer from '../../_components/cart/cart-timer';
|
|
||||||
import { Trans } from '@kit/ui/trans';
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
|
|
||||||
|
import Cart from '../../_components/cart';
|
||||||
|
import CartTimer from '../../_components/cart/cart-timer';
|
||||||
|
|
||||||
export async function generateMetadata() {
|
export async function generateMetadata() {
|
||||||
const { t } = await createI18nServerInstance();
|
const { t } = await createI18nServerInstance();
|
||||||
|
|
||||||
@@ -20,34 +22,51 @@ export async function generateMetadata() {
|
|||||||
|
|
||||||
async function CartPage() {
|
async function CartPage() {
|
||||||
const cart = await retrieveCart().catch((error) => {
|
const cart = await retrieveCart().catch((error) => {
|
||||||
console.error("Failed to retrieve cart", error);
|
console.error('Failed to retrieve cart', error);
|
||||||
return notFound();
|
return notFound();
|
||||||
});
|
});
|
||||||
|
|
||||||
const { productTypes } = await listProductTypes();
|
const { productTypes } = await listProductTypes();
|
||||||
const analysisPackagesType = productTypes.find(({ metadata }) => metadata?.handle === 'analysis-packages');
|
const analysisPackagesType = productTypes.find(
|
||||||
const synlabAnalysisType = productTypes.find(({ metadata }) => metadata?.handle === 'synlab-analysis');
|
({ metadata }) => metadata?.handle === 'analysis-packages',
|
||||||
const synlabAnalyses = analysisPackagesType && synlabAnalysisType && cart?.items
|
);
|
||||||
? cart.items.filter((item) => {
|
const synlabAnalysisType = productTypes.find(
|
||||||
const productTypeId = item.product?.type_id;
|
({ metadata }) => metadata?.handle === 'synlab-analysis',
|
||||||
if (!productTypeId) {
|
);
|
||||||
return false;
|
const synlabAnalyses =
|
||||||
}
|
analysisPackagesType && synlabAnalysisType && cart?.items
|
||||||
return [analysisPackagesType.id, synlabAnalysisType.id].includes(productTypeId);
|
? cart.items.filter((item) => {
|
||||||
})
|
const productTypeId = item.product?.type_id;
|
||||||
: [];
|
if (!productTypeId) {
|
||||||
const ttoServiceItems = cart?.items?.filter((item) => !synlabAnalyses.some((analysis) => analysis.id === item.id)) ?? [];
|
return false;
|
||||||
|
}
|
||||||
|
return [analysisPackagesType.id, synlabAnalysisType.id].includes(
|
||||||
|
productTypeId,
|
||||||
|
);
|
||||||
|
})
|
||||||
|
: [];
|
||||||
|
const ttoServiceItems =
|
||||||
|
cart?.items?.filter(
|
||||||
|
(item) => !synlabAnalyses.some((analysis) => analysis.id === item.id),
|
||||||
|
) ?? [];
|
||||||
|
|
||||||
const otherItemsSorted = ttoServiceItems.sort((a, b) => (a.updated_at ?? "") > (b.updated_at ?? "") ? -1 : 1);
|
const otherItemsSorted = ttoServiceItems.sort((a, b) =>
|
||||||
|
(a.updated_at ?? '') > (b.updated_at ?? '') ? -1 : 1,
|
||||||
|
);
|
||||||
const item = otherItemsSorted[0];
|
const item = otherItemsSorted[0];
|
||||||
const isTimerShown = ttoServiceItems.length > 0 && !!item && !!item.updated_at;
|
const isTimerShown =
|
||||||
|
ttoServiceItems.length > 0 && !!item && !!item.updated_at;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageBody>
|
<PageBody>
|
||||||
<PageHeader title={<Trans i18nKey="cart:title" />}>
|
<PageHeader title={<Trans i18nKey="cart:title" />}>
|
||||||
{isTimerShown && <CartTimer cartItem={item} />}
|
{isTimerShown && <CartTimer cartItem={item} />}
|
||||||
</PageHeader>
|
</PageHeader>
|
||||||
<Cart cart={cart} synlabAnalyses={synlabAnalyses} ttoServiceItems={ttoServiceItems} />
|
<Cart
|
||||||
|
cart={cart}
|
||||||
|
synlabAnalyses={synlabAnalyses}
|
||||||
|
ttoServiceItems={ttoServiceItems}
|
||||||
|
/>
|
||||||
</PageBody>
|
</PageBody>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import { Scale } from 'lucide-react';
|
import { Scale } from 'lucide-react';
|
||||||
|
|
||||||
|
import SelectAnalysisPackages from '@kit/shared/components/select-analysis-packages';
|
||||||
|
import { Button } from '@kit/ui/button';
|
||||||
|
import { PageBody } from '@kit/ui/page';
|
||||||
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
|
|
||||||
import { Button } from '@kit/ui/button';
|
|
||||||
import SelectAnalysisPackages from '@kit/shared/components/select-analysis-packages';
|
|
||||||
import { PageBody } from '@kit/ui/page';
|
|
||||||
import { Trans } from '@kit/ui/trans';
|
|
||||||
|
|
||||||
import ComparePackagesModal from '../../_components/compare-packages-modal';
|
import ComparePackagesModal from '../../_components/compare-packages-modal';
|
||||||
import { loadAnalysisPackages } from '../../_lib/server/load-analysis-packages';
|
import { loadAnalysisPackages } from '../../_lib/server/load-analysis-packages';
|
||||||
|
|
||||||
@@ -21,7 +21,8 @@ export const generateMetadata = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
async function OrderAnalysisPackagePage() {
|
async function OrderAnalysisPackagePage() {
|
||||||
const { analysisPackageElements, analysisPackages, countryCode } = await loadAnalysisPackages();
|
const { analysisPackageElements, analysisPackages, countryCode } =
|
||||||
|
await loadAnalysisPackages();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageBody>
|
<PageBody>
|
||||||
@@ -40,7 +41,10 @@ async function OrderAnalysisPackagePage() {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<SelectAnalysisPackages analysisPackages={analysisPackages} countryCode={countryCode} />
|
<SelectAnalysisPackages
|
||||||
|
analysisPackages={analysisPackages}
|
||||||
|
countryCode={countryCode}
|
||||||
|
/>
|
||||||
</PageBody>
|
</PageBody>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
|
||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
|
||||||
|
|
||||||
import { PageBody } from '@kit/ui/page';
|
import { PageBody } from '@kit/ui/page';
|
||||||
import { Trans } from '@kit/ui/trans';
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
|
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
||||||
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
|
import {
|
||||||
|
PageViewAction,
|
||||||
|
createPageViewLog,
|
||||||
|
} from '~/lib/services/audit/pageView.service';
|
||||||
|
|
||||||
import { HomeLayoutPageHeader } from '../../_components/home-page-header';
|
import { HomeLayoutPageHeader } from '../../_components/home-page-header';
|
||||||
import { loadAnalyses } from '../../_lib/server/load-analyses';
|
|
||||||
import OrderAnalysesCards from '../../_components/order-analyses-cards';
|
import OrderAnalysesCards from '../../_components/order-analyses-cards';
|
||||||
import { createPageViewLog, PageViewAction } from '~/lib/services/audit/pageView.service';
|
import { loadAnalyses } from '../../_lib/server/load-analyses';
|
||||||
import { loadCurrentUserAccount } from '../../_lib/server/load-user-account';
|
import { loadCurrentUserAccount } from '../../_lib/server/load-user-account';
|
||||||
|
|
||||||
export const generateMetadata = async () => {
|
export const generateMetadata = async () => {
|
||||||
@@ -24,7 +28,7 @@ async function OrderAnalysisPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { analyses, countryCode } = await loadAnalyses();
|
const { analyses, countryCode } = await loadAnalyses();
|
||||||
|
|
||||||
await createPageViewLog({
|
await createPageViewLog({
|
||||||
accountId: account.id,
|
accountId: account.id,
|
||||||
action: PageViewAction.VIEW_ORDER_ANALYSIS,
|
action: PageViewAction.VIEW_ORDER_ANALYSIS,
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
|
import { PageBody } from '@kit/ui/page';
|
||||||
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
|
|
||||||
import { PageBody } from '@kit/ui/page';
|
|
||||||
import { Trans } from '@kit/ui/trans';
|
|
||||||
import { HomeLayoutPageHeader } from '../../_components/home-page-header';
|
import { HomeLayoutPageHeader } from '../../_components/home-page-header';
|
||||||
|
|
||||||
export const generateMetadata = async () => {
|
export const generateMetadata = async () => {
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
import { redirect } from 'next/navigation';
|
import { redirect } from 'next/navigation';
|
||||||
import { PageBody, PageHeader } from '@kit/ui/page';
|
|
||||||
|
|
||||||
import { createI18nServerInstance } from '@/lib/i18n/i18n.server';
|
import CartTotals from '@/app/home/(user)/_components/order/cart-totals';
|
||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
|
||||||
|
|
||||||
import { getAnalysisOrder } from '~/lib/services/order.service';
|
|
||||||
import { retrieveOrder } from '@lib/data/orders';
|
|
||||||
import { pathsConfig } from '@kit/shared/config';
|
|
||||||
|
|
||||||
import Divider from "@modules/common/components/divider"
|
|
||||||
import OrderDetails from '@/app/home/(user)/_components/order/order-details';
|
import OrderDetails from '@/app/home/(user)/_components/order/order-details';
|
||||||
import OrderItems from '@/app/home/(user)/_components/order/order-items';
|
import OrderItems from '@/app/home/(user)/_components/order/order-items';
|
||||||
import CartTotals from '@/app/home/(user)/_components/order/cart-totals';
|
import { createI18nServerInstance } from '@/lib/i18n/i18n.server';
|
||||||
|
import { retrieveOrder } from '@lib/data/orders';
|
||||||
|
import Divider from '@modules/common/components/divider';
|
||||||
|
|
||||||
|
import { pathsConfig } from '@kit/shared/config';
|
||||||
|
import { PageBody, PageHeader } from '@kit/ui/page';
|
||||||
import { Trans } from '@kit/ui/trans';
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
|
import { getAnalysisOrder } from '~/lib/services/order.service';
|
||||||
|
|
||||||
export async function generateMetadata() {
|
export async function generateMetadata() {
|
||||||
const { t } = await createI18nServerInstance();
|
const { t } = await createI18nServerInstance();
|
||||||
|
|
||||||
@@ -27,12 +27,16 @@ async function OrderConfirmedPage(props: {
|
|||||||
}) {
|
}) {
|
||||||
const params = await props.params;
|
const params = await props.params;
|
||||||
|
|
||||||
const order = await getAnalysisOrder({ analysisOrderId: Number(params.orderId) }).catch(() => null);
|
const order = await getAnalysisOrder({
|
||||||
|
analysisOrderId: Number(params.orderId),
|
||||||
|
}).catch(() => null);
|
||||||
if (!order) {
|
if (!order) {
|
||||||
redirect(pathsConfig.app.myOrders);
|
redirect(pathsConfig.app.myOrders);
|
||||||
}
|
}
|
||||||
|
|
||||||
const medusaOrder = await retrieveOrder(order.medusa_order_id).catch(() => null);
|
const medusaOrder = await retrieveOrder(order.medusa_order_id).catch(
|
||||||
|
() => null,
|
||||||
|
);
|
||||||
if (!medusaOrder) {
|
if (!medusaOrder) {
|
||||||
redirect(pathsConfig.app.myOrders);
|
redirect(pathsConfig.app.myOrders);
|
||||||
}
|
}
|
||||||
@@ -41,7 +45,7 @@ async function OrderConfirmedPage(props: {
|
|||||||
<PageBody>
|
<PageBody>
|
||||||
<PageHeader title={<Trans i18nKey="cart:orderConfirmed.title" />} />
|
<PageHeader title={<Trans i18nKey="cart:orderConfirmed.title" />} />
|
||||||
<Divider />
|
<Divider />
|
||||||
<div className="grid grid-cols-1 small:grid-cols-[1fr_360px] gap-x-40 lg:px-4 gap-y-6">
|
<div className="small:grid-cols-[1fr_360px] grid grid-cols-1 gap-x-40 gap-y-6 lg:px-4">
|
||||||
<OrderDetails order={order} />
|
<OrderDetails order={order} />
|
||||||
<Divider />
|
<Divider />
|
||||||
<OrderItems medusaOrder={medusaOrder} />
|
<OrderItems medusaOrder={medusaOrder} />
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
import { redirect } from 'next/navigation';
|
import { redirect } from 'next/navigation';
|
||||||
import { PageBody, PageHeader } from '@kit/ui/page';
|
|
||||||
|
|
||||||
import { createI18nServerInstance } from '@/lib/i18n/i18n.server';
|
import CartTotals from '@/app/home/(user)/_components/order/cart-totals';
|
||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
|
||||||
|
|
||||||
import { getAnalysisOrder } from '~/lib/services/order.service';
|
|
||||||
import { retrieveOrder } from '@lib/data/orders';
|
|
||||||
import { pathsConfig } from '@kit/shared/config';
|
|
||||||
|
|
||||||
import Divider from "@modules/common/components/divider"
|
|
||||||
import OrderDetails from '@/app/home/(user)/_components/order/order-details';
|
import OrderDetails from '@/app/home/(user)/_components/order/order-details';
|
||||||
import OrderItems from '@/app/home/(user)/_components/order/order-items';
|
import OrderItems from '@/app/home/(user)/_components/order/order-items';
|
||||||
import CartTotals from '@/app/home/(user)/_components/order/cart-totals';
|
import { createI18nServerInstance } from '@/lib/i18n/i18n.server';
|
||||||
|
import { retrieveOrder } from '@lib/data/orders';
|
||||||
|
import Divider from '@modules/common/components/divider';
|
||||||
|
|
||||||
|
import { pathsConfig } from '@kit/shared/config';
|
||||||
|
import { PageBody, PageHeader } from '@kit/ui/page';
|
||||||
import { Trans } from '@kit/ui/trans';
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
|
import { getAnalysisOrder } from '~/lib/services/order.service';
|
||||||
|
|
||||||
export async function generateMetadata() {
|
export async function generateMetadata() {
|
||||||
const { t } = await createI18nServerInstance();
|
const { t } = await createI18nServerInstance();
|
||||||
|
|
||||||
@@ -27,12 +27,16 @@ async function OrderConfirmedPage(props: {
|
|||||||
}) {
|
}) {
|
||||||
const params = await props.params;
|
const params = await props.params;
|
||||||
|
|
||||||
const order = await getAnalysisOrder({ analysisOrderId: Number(params.orderId) }).catch(() => null);
|
const order = await getAnalysisOrder({
|
||||||
|
analysisOrderId: Number(params.orderId),
|
||||||
|
}).catch(() => null);
|
||||||
if (!order) {
|
if (!order) {
|
||||||
redirect(pathsConfig.app.myOrders);
|
redirect(pathsConfig.app.myOrders);
|
||||||
}
|
}
|
||||||
|
|
||||||
const medusaOrder = await retrieveOrder(order.medusa_order_id).catch(() => null);
|
const medusaOrder = await retrieveOrder(order.medusa_order_id).catch(
|
||||||
|
() => null,
|
||||||
|
);
|
||||||
if (!medusaOrder) {
|
if (!medusaOrder) {
|
||||||
redirect(pathsConfig.app.myOrders);
|
redirect(pathsConfig.app.myOrders);
|
||||||
}
|
}
|
||||||
@@ -41,7 +45,7 @@ async function OrderConfirmedPage(props: {
|
|||||||
<PageBody>
|
<PageBody>
|
||||||
<PageHeader title={<Trans i18nKey="cart:order.title" />} />
|
<PageHeader title={<Trans i18nKey="cart:order.title" />} />
|
||||||
<Divider />
|
<Divider />
|
||||||
<div className="grid grid-cols-1 small:grid-cols-[1fr_360px] gap-x-40 lg:px-4 gap-y-6">
|
<div className="small:grid-cols-[1fr_360px] grid grid-cols-1 gap-x-40 gap-y-6 lg:px-4">
|
||||||
<OrderDetails order={order} />
|
<OrderDetails order={order} />
|
||||||
<Divider />
|
<Divider />
|
||||||
<OrderItems medusaOrder={medusaOrder} />
|
<OrderItems medusaOrder={medusaOrder} />
|
||||||
|
|||||||
@@ -1,18 +1,21 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
import { redirect } from 'next/navigation';
|
import { redirect } from 'next/navigation';
|
||||||
|
|
||||||
import { listOrders } from '~/medusa/lib/data/orders';
|
|
||||||
import { createI18nServerInstance } from '@/lib/i18n/i18n.server';
|
import { createI18nServerInstance } from '@/lib/i18n/i18n.server';
|
||||||
import { listProductTypes } from '@lib/data/products';
|
import { listProductTypes } from '@lib/data/products';
|
||||||
import { PageBody } from '@kit/ui/makerkit/page';
|
|
||||||
import { pathsConfig } from '@kit/shared/config';
|
|
||||||
|
|
||||||
import { Trans } from '@kit/ui/trans';
|
|
||||||
import { HomeLayoutPageHeader } from '../../_components/home-page-header';
|
|
||||||
import { getAnalysisOrders } from '~/lib/services/order.service';
|
|
||||||
import OrderBlock from '../../_components/orders/order-block';
|
|
||||||
import React from 'react';
|
|
||||||
import { Divider } from '@medusajs/ui';
|
import { Divider } from '@medusajs/ui';
|
||||||
|
|
||||||
|
import { pathsConfig } from '@kit/shared/config';
|
||||||
|
import { PageBody } from '@kit/ui/makerkit/page';
|
||||||
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
|
import { getAnalysisOrders } from '~/lib/services/order.service';
|
||||||
|
import { listOrders } from '~/medusa/lib/data/orders';
|
||||||
|
|
||||||
|
import { HomeLayoutPageHeader } from '../../_components/home-page-header';
|
||||||
|
import OrderBlock from '../../_components/orders/order-block';
|
||||||
|
|
||||||
export async function generateMetadata() {
|
export async function generateMetadata() {
|
||||||
const { t } = await createI18nServerInstance();
|
const { t } = await createI18nServerInstance();
|
||||||
@@ -31,7 +34,9 @@ async function OrdersPage() {
|
|||||||
redirect(pathsConfig.auth.signIn);
|
redirect(pathsConfig.auth.signIn);
|
||||||
}
|
}
|
||||||
|
|
||||||
const analysisPackagesType = productTypes.find(({ metadata }) => metadata?.handle === 'analysis-packages')!;
|
const analysisPackagesType = productTypes.find(
|
||||||
|
({ metadata }) => metadata?.handle === 'analysis-packages',
|
||||||
|
)!;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -41,14 +46,20 @@ async function OrdersPage() {
|
|||||||
/>
|
/>
|
||||||
<PageBody>
|
<PageBody>
|
||||||
{analysisOrders.map((analysisOrder) => {
|
{analysisOrders.map((analysisOrder) => {
|
||||||
const medusaOrder = medusaOrders.find(({ id }) => id === analysisOrder.medusa_order_id);
|
const medusaOrder = medusaOrders.find(
|
||||||
|
({ id }) => id === analysisOrder.medusa_order_id,
|
||||||
|
);
|
||||||
if (!medusaOrder) {
|
if (!medusaOrder) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const medusaOrderItems = medusaOrder.items || [];
|
const medusaOrderItems = medusaOrder.items || [];
|
||||||
const medusaOrderItemsAnalysisPackages = medusaOrderItems.filter((item) => item.product_type_id === analysisPackagesType?.id);
|
const medusaOrderItemsAnalysisPackages = medusaOrderItems.filter(
|
||||||
const medusaOrderItemsOther = medusaOrderItems.filter((item) => item.product_type_id !== analysisPackagesType?.id);
|
(item) => item.product_type_id === analysisPackagesType?.id,
|
||||||
|
);
|
||||||
|
const medusaOrderItemsOther = medusaOrderItems.filter(
|
||||||
|
(item) => item.product_type_id !== analysisPackagesType?.id,
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment key={analysisOrder.id}>
|
<React.Fragment key={analysisOrder.id}>
|
||||||
@@ -59,7 +70,7 @@ async function OrdersPage() {
|
|||||||
itemsOther={medusaOrderItemsOther}
|
itemsOther={medusaOrderItemsOther}
|
||||||
/>
|
/>
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
)
|
);
|
||||||
})}
|
})}
|
||||||
{analysisOrders.length === 0 && (
|
{analysisOrders.length === 0 && (
|
||||||
<h5 className="mt-6">
|
<h5 className="mt-6">
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import { redirect } from 'next/navigation';
|
import { redirect } from 'next/navigation';
|
||||||
|
|
||||||
import { toTitleCase } from '@/lib/utils';
|
import { toTitleCase } from '@/lib/utils';
|
||||||
import { createUserAnalysesApi } from '@kit/user-analyses/api';
|
|
||||||
import { getSupabaseServerClient } from '@/packages/supabase/src/clients/server-client';
|
import { getSupabaseServerClient } from '@/packages/supabase/src/clients/server-client';
|
||||||
|
|
||||||
import { PageBody, PageHeader } from '@kit/ui/page';
|
import { PageBody, PageHeader } from '@kit/ui/page';
|
||||||
import { Trans } from '@kit/ui/trans';
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
import { createUserAnalysesApi } from '@kit/user-analyses/api';
|
||||||
|
|
||||||
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
"use client"
|
'use client';
|
||||||
|
|
||||||
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
|
import { StoreCart, StoreCartLineItem } from '@medusajs/types';
|
||||||
|
import { useForm } from 'react-hook-form';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
import { useForm } from "react-hook-form";
|
import { z } from 'zod';
|
||||||
import { z } from "zod";
|
|
||||||
import { StoreCart, StoreCartLineItem } from "@medusajs/types"
|
import { Form } from '@kit/ui/form';
|
||||||
import { Form } from "@kit/ui/form";
|
|
||||||
import { Trans } from '@kit/ui/trans';
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
|
||||||
import {
|
import {
|
||||||
Select,
|
Select,
|
||||||
SelectContent,
|
SelectContent,
|
||||||
@@ -17,29 +17,39 @@ import {
|
|||||||
SelectTrigger,
|
SelectTrigger,
|
||||||
SelectValue,
|
SelectValue,
|
||||||
} from '@kit/ui/select';
|
} from '@kit/ui/select';
|
||||||
import { updateCartPartnerLocation } from '../../_lib/server/update-cart-partner-location';
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
|
import { updateCartPartnerLocation } from '../../_lib/server/update-cart-partner-location';
|
||||||
import partnerLocations from './partner-locations.json';
|
import partnerLocations from './partner-locations.json';
|
||||||
|
|
||||||
const AnalysisLocationSchema = z.object({
|
const AnalysisLocationSchema = z.object({
|
||||||
locationId: z.string().min(1),
|
locationId: z.string().min(1),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default function AnalysisLocation({ cart, synlabAnalyses }: { cart: StoreCart, synlabAnalyses: StoreCartLineItem[] }) {
|
export default function AnalysisLocation({
|
||||||
|
cart,
|
||||||
|
synlabAnalyses,
|
||||||
|
}: {
|
||||||
|
cart: StoreCart;
|
||||||
|
synlabAnalyses: StoreCartLineItem[];
|
||||||
|
}) {
|
||||||
const { t } = useTranslation('cart');
|
const { t } = useTranslation('cart');
|
||||||
|
|
||||||
const form = useForm<z.infer<typeof AnalysisLocationSchema>>({
|
const form = useForm<z.infer<typeof AnalysisLocationSchema>>({
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
locationId: cart.metadata?.partner_location_id as string ?? '',
|
locationId: (cart.metadata?.partner_location_id as string) ?? '',
|
||||||
},
|
},
|
||||||
resolver: zodResolver(AnalysisLocationSchema),
|
resolver: zodResolver(AnalysisLocationSchema),
|
||||||
});
|
});
|
||||||
|
|
||||||
const getLocation = (locationId: string) => partnerLocations.find(({ name }) => name === locationId);
|
const getLocation = (locationId: string) =>
|
||||||
|
partnerLocations.find(({ name }) => name === locationId);
|
||||||
|
|
||||||
const selectedLocation = getLocation(form.watch('locationId'));
|
const selectedLocation = getLocation(form.watch('locationId'));
|
||||||
|
|
||||||
const onSubmit = async ({ locationId }: z.infer<typeof AnalysisLocationSchema>) => {
|
const onSubmit = async ({
|
||||||
|
locationId,
|
||||||
|
}: z.infer<typeof AnalysisLocationSchema>) => {
|
||||||
const promise = updateCartPartnerLocation({
|
const promise = updateCartPartnerLocation({
|
||||||
cartId: cart.id,
|
cartId: cart.id,
|
||||||
lineIds: synlabAnalyses.map(({ id }) => id),
|
lineIds: synlabAnalyses.map(({ id }) => id),
|
||||||
@@ -52,18 +62,18 @@ export default function AnalysisLocation({ cart, synlabAnalyses }: { cart: Store
|
|||||||
loading: t(`cart:items.analysisLocation.loading`),
|
loading: t(`cart:items.analysisLocation.loading`),
|
||||||
error: t(`cart:items.analysisLocation.error`),
|
error: t(`cart:items.analysisLocation.error`),
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="w-full h-full bg-white flex flex-col txt-medium gap-y-4">
|
<div className="txt-medium flex h-full w-full flex-col gap-y-4 bg-white">
|
||||||
<p className="text-sm text-muted-foreground">
|
<p className="text-muted-foreground text-sm">
|
||||||
<Trans i18nKey={'cart:locations.description'} />
|
<Trans i18nKey={'cart:locations.description'} />
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form
|
<form
|
||||||
onSubmit={form.handleSubmit((data) => onSubmit(data))}
|
onSubmit={form.handleSubmit((data) => onSubmit(data))}
|
||||||
className="w-full mb-2 flex gap-x-2 flex-1"
|
className="mb-2 flex w-full flex-1 gap-x-2"
|
||||||
>
|
>
|
||||||
<Select
|
<Select
|
||||||
value={form.watch('locationId')}
|
value={form.watch('locationId')}
|
||||||
@@ -82,34 +92,38 @@ export default function AnalysisLocation({ cart, synlabAnalyses }: { cart: Store
|
|||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
|
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
{Object.entries(partnerLocations
|
{Object.entries(
|
||||||
.reduce((acc, curr) => ({
|
partnerLocations.reduce(
|
||||||
...acc,
|
(acc, curr) => ({
|
||||||
[curr.city]: [...((acc[curr.city] as typeof partnerLocations) ?? []), curr],
|
...acc,
|
||||||
}), {} as Record<string, typeof partnerLocations>))
|
[curr.city]: [
|
||||||
.map(([city, locations]) => (
|
...((acc[curr.city] as typeof partnerLocations) ?? []),
|
||||||
<SelectGroup key={city}>
|
curr,
|
||||||
<SelectLabel>{city}</SelectLabel>
|
],
|
||||||
{locations.map((location) => (
|
}),
|
||||||
<SelectItem key={location.name} value={location.name}>{location.name}</SelectItem>
|
{} as Record<string, typeof partnerLocations>,
|
||||||
))}
|
),
|
||||||
</SelectGroup>
|
).map(([city, locations]) => (
|
||||||
))}
|
<SelectGroup key={city}>
|
||||||
|
<SelectLabel>{city}</SelectLabel>
|
||||||
|
{locations.map((location) => (
|
||||||
|
<SelectItem key={location.name} value={location.name}>
|
||||||
|
{location.name}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectGroup>
|
||||||
|
))}
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
</form>
|
</form>
|
||||||
</Form>
|
</Form>
|
||||||
|
|
||||||
{selectedLocation && (
|
{selectedLocation && (
|
||||||
<div className="flex flex-col gap-y-2 mb-4">
|
<div className="mb-4 flex flex-col gap-y-2">
|
||||||
<p className="text-sm">
|
<p className="text-sm">{selectedLocation.address}</p>
|
||||||
{selectedLocation.address}
|
<p className="text-sm">{selectedLocation.hours}</p>
|
||||||
</p>
|
|
||||||
<p className="text-sm">
|
|
||||||
{selectedLocation.hours}
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
"use client";
|
'use client';
|
||||||
|
|
||||||
import { Trash } from "lucide-react";
|
import { useState } from 'react';
|
||||||
import { useState } from "react";
|
|
||||||
import { useTranslation } from "react-i18next";
|
import { Spinner } from '@medusajs/icons';
|
||||||
|
import { Trash } from 'lucide-react';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
|
|
||||||
import { Spinner } from "@medusajs/icons";
|
import { handleDeleteCartItem } from '~/lib/services/medusaCart.service';
|
||||||
import { handleDeleteCartItem } from "~/lib/services/medusaCart.service";
|
|
||||||
|
|
||||||
const CartItemDelete = ({
|
const CartItemDelete = ({
|
||||||
id,
|
id,
|
||||||
@@ -33,9 +34,9 @@ const CartItemDelete = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center justify-between text-small-regular">
|
<div className="text-small-regular flex items-center justify-between">
|
||||||
<button
|
<button
|
||||||
className="flex gap-x-1 text-ui-fg-subtle hover:text-ui-fg-base cursor-pointer"
|
className="text-ui-fg-subtle hover:text-ui-fg-base flex cursor-pointer gap-x-1"
|
||||||
onClick={() => handleDelete()}
|
onClick={() => handleDelete()}
|
||||||
>
|
>
|
||||||
{isDeleting ? <Spinner className="animate-spin" /> : <Trash />}
|
{isDeleting ? <Spinner className="animate-spin" /> : <Trash />}
|
||||||
|
|||||||
@@ -1,23 +1,27 @@
|
|||||||
"use client"
|
'use client';
|
||||||
|
|
||||||
import { HttpTypes } from "@medusajs/types"
|
import { formatCurrency } from '@/packages/shared/src/utils';
|
||||||
import { useTranslation } from "react-i18next"
|
import { HttpTypes } from '@medusajs/types';
|
||||||
import {
|
import { useTranslation } from 'react-i18next';
|
||||||
TableCell,
|
|
||||||
TableRow,
|
|
||||||
} from '@kit/ui/table';
|
|
||||||
import { formatCurrency } from "@/packages/shared/src/utils"
|
|
||||||
import CartItemDelete from "./cart-item-delete";
|
|
||||||
|
|
||||||
export default function CartItem({ item, currencyCode }: {
|
import { TableCell, TableRow } from '@kit/ui/table';
|
||||||
item: HttpTypes.StoreCartLineItem
|
|
||||||
currencyCode: string
|
import CartItemDelete from './cart-item-delete';
|
||||||
|
|
||||||
|
export default function CartItem({
|
||||||
|
item,
|
||||||
|
currencyCode,
|
||||||
|
}: {
|
||||||
|
item: HttpTypes.StoreCartLineItem;
|
||||||
|
currencyCode: string;
|
||||||
}) {
|
}) {
|
||||||
const { i18n: { language } } = useTranslation();
|
const {
|
||||||
|
i18n: { language },
|
||||||
|
} = useTranslation();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TableRow className="w-full" data-testid="product-row">
|
<TableRow className="w-full" data-testid="product-row">
|
||||||
<TableCell className="text-left w-[100%] px-4 sm:px-6">
|
<TableCell className="w-[100%] px-4 text-left sm:px-6">
|
||||||
<p
|
<p
|
||||||
className="txt-medium-plus text-ui-fg-base"
|
className="txt-medium-plus text-ui-fg-base"
|
||||||
data-testid="product-title"
|
data-testid="product-title"
|
||||||
@@ -26,9 +30,7 @@ export default function CartItem({ item, currencyCode }: {
|
|||||||
</p>
|
</p>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
<TableCell className="px-4 sm:px-6">
|
<TableCell className="px-4 sm:px-6">{item.quantity}</TableCell>
|
||||||
{item.quantity}
|
|
||||||
</TableCell>
|
|
||||||
|
|
||||||
<TableCell className="min-w-[80px] px-4 sm:px-6">
|
<TableCell className="min-w-[80px] px-4 sm:px-6">
|
||||||
{formatCurrency({
|
{formatCurrency({
|
||||||
@@ -38,7 +40,7 @@ export default function CartItem({ item, currencyCode }: {
|
|||||||
})}
|
})}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
<TableCell className="min-w-[80px] px-4 sm:px-6 text-right">
|
<TableCell className="min-w-[80px] px-4 text-right sm:px-6">
|
||||||
{formatCurrency({
|
{formatCurrency({
|
||||||
value: item.total,
|
value: item.total,
|
||||||
currencyCode,
|
currencyCode,
|
||||||
@@ -46,11 +48,11 @@ export default function CartItem({ item, currencyCode }: {
|
|||||||
})}
|
})}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
<TableCell className="text-right px-4 sm:px-6">
|
<TableCell className="px-4 text-right sm:px-6">
|
||||||
<span className="flex gap-x-1 justify-end w-[60px]">
|
<span className="flex w-[60px] justify-end gap-x-1">
|
||||||
<CartItemDelete id={item.id} />
|
<CartItemDelete id={item.id} />
|
||||||
</span>
|
</span>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,21 @@
|
|||||||
import { StoreCart, StoreCartLineItem } from "@medusajs/types"
|
import { StoreCart, StoreCartLineItem } from '@medusajs/types';
|
||||||
import { Trans } from '@kit/ui/trans';
|
|
||||||
import CartItem from "./cart-item";
|
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
TableHead,
|
TableHead,
|
||||||
TableRow,
|
|
||||||
TableHeader,
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
} from '@kit/ui/table';
|
} from '@kit/ui/table';
|
||||||
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
export default function CartItems({ cart, items, productColumnLabelKey }: {
|
import CartItem from './cart-item';
|
||||||
|
|
||||||
|
export default function CartItems({
|
||||||
|
cart,
|
||||||
|
items,
|
||||||
|
productColumnLabelKey,
|
||||||
|
}: {
|
||||||
cart: StoreCart;
|
cart: StoreCart;
|
||||||
items: StoreCartLineItem[];
|
items: StoreCartLineItem[];
|
||||||
productColumnLabelKey: string;
|
productColumnLabelKey: string;
|
||||||
@@ -19,7 +25,7 @@ export default function CartItems({ cart, items, productColumnLabelKey }: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Table className="rounded-lg border border-separate">
|
<Table className="border-separate rounded-lg border">
|
||||||
<TableHeader className="text-ui-fg-subtle txt-medium-plus">
|
<TableHeader className="text-ui-fg-subtle txt-medium-plus">
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableHead className="px-4 sm:px-6">
|
<TableHead className="px-4 sm:px-6">
|
||||||
@@ -28,19 +34,20 @@ export default function CartItems({ cart, items, productColumnLabelKey }: {
|
|||||||
<TableHead className="px-4 sm:px-6">
|
<TableHead className="px-4 sm:px-6">
|
||||||
<Trans i18nKey="cart:table.quantity" />
|
<Trans i18nKey="cart:table.quantity" />
|
||||||
</TableHead>
|
</TableHead>
|
||||||
<TableHead className="px-4 sm:px-6 min-w-[100px]">
|
<TableHead className="min-w-[100px] px-4 sm:px-6">
|
||||||
<Trans i18nKey="cart:table.price" />
|
<Trans i18nKey="cart:table.price" />
|
||||||
</TableHead>
|
</TableHead>
|
||||||
<TableHead className="px-4 sm:px-6 min-w-[100px] text-right">
|
<TableHead className="min-w-[100px] px-4 text-right sm:px-6">
|
||||||
<Trans i18nKey="cart:table.total" />
|
<Trans i18nKey="cart:table.total" />
|
||||||
</TableHead>
|
</TableHead>
|
||||||
<TableHead className="px-4 sm:px-6">
|
<TableHead className="px-4 sm:px-6"></TableHead>
|
||||||
</TableHead>
|
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{items
|
{items
|
||||||
.sort((a, b) => (a.created_at ?? "") > (b.created_at ?? "") ? -1 : 1)
|
.sort((a, b) =>
|
||||||
|
(a.created_at ?? '') > (b.created_at ?? '') ? -1 : 1,
|
||||||
|
)
|
||||||
.map((item) => (
|
.map((item) => (
|
||||||
<CartItem
|
<CartItem
|
||||||
key={item.id}
|
key={item.id}
|
||||||
@@ -50,5 +57,5 @@ export default function CartItems({ cart, items, productColumnLabelKey }: {
|
|||||||
))}
|
))}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
"use client";
|
'use client';
|
||||||
|
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
|
import { handleLineItemTimeout } from '@/lib/services/medusaCart.service';
|
||||||
|
import { StoreCartLineItem } from '@medusajs/types';
|
||||||
|
import { Timer } from 'lucide-react';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import { Button } from '@kit/ui/button';
|
|
||||||
import {
|
import {
|
||||||
AlertDialog,
|
AlertDialog,
|
||||||
AlertDialogAction,
|
AlertDialogAction,
|
||||||
@@ -8,18 +14,17 @@ import {
|
|||||||
AlertDialogDescription,
|
AlertDialogDescription,
|
||||||
AlertDialogFooter,
|
AlertDialogFooter,
|
||||||
AlertDialogHeader,
|
AlertDialogHeader,
|
||||||
AlertDialogTitle
|
AlertDialogTitle,
|
||||||
} from "@kit/ui/alert-dialog";
|
} from '@kit/ui/alert-dialog';
|
||||||
|
import { Button } from '@kit/ui/button';
|
||||||
import { Timer } from 'lucide-react';
|
|
||||||
import { useEffect, useState } from 'react';
|
|
||||||
import { useTranslation } from 'react-i18next';
|
|
||||||
import { StoreCartLineItem } from '@medusajs/types';
|
|
||||||
import { handleLineItemTimeout } from '@/lib/services/medusaCart.service';
|
|
||||||
|
|
||||||
const TIMEOUT_MINUTES = 15;
|
const TIMEOUT_MINUTES = 15;
|
||||||
|
|
||||||
export default function CartTimer({ cartItem }: { cartItem: StoreCartLineItem }) {
|
export default function CartTimer({
|
||||||
|
cartItem,
|
||||||
|
}: {
|
||||||
|
cartItem: StoreCartLineItem;
|
||||||
|
}) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [timeLeft, setTimeLeft] = useState<number | null>(null);
|
const [timeLeft, setTimeLeft] = useState<number | null>(null);
|
||||||
const [isDialogOpen, setDialogOpen] = useState(false);
|
const [isDialogOpen, setDialogOpen] = useState(false);
|
||||||
@@ -39,7 +44,9 @@ export default function CartTimer({ cartItem }: { cartItem: StoreCartLineItem })
|
|||||||
return () => clearInterval(interval);
|
return () => clearInterval(interval);
|
||||||
}, [updatedAt]);
|
}, [updatedAt]);
|
||||||
|
|
||||||
const minutes = timeLeft ? Math.floor((timeLeft % (1000 * 60 * 60)) / (1000 * 60)) : 0;
|
const minutes = timeLeft
|
||||||
|
? Math.floor((timeLeft % (1000 * 60 * 60)) / (1000 * 60))
|
||||||
|
: 0;
|
||||||
const seconds = timeLeft ? Math.floor((timeLeft % (1000 * 60)) / 1000) : 0;
|
const seconds = timeLeft ? Math.floor((timeLeft % (1000 * 60)) / 1000) : 0;
|
||||||
|
|
||||||
const isTimeLeftPositive = timeLeft === null || timeLeft > 0;
|
const isTimeLeftPositive = timeLeft === null || timeLeft > 0;
|
||||||
@@ -53,13 +60,16 @@ export default function CartTimer({ cartItem }: { cartItem: StoreCartLineItem })
|
|||||||
}, [isTimeLeftPositive, cartItem.id]);
|
}, [isTimeLeftPositive, cartItem.id]);
|
||||||
|
|
||||||
if (timeLeft === null) {
|
if (timeLeft === null) {
|
||||||
return <div className='min-h-[40px]' />;
|
return <div className="min-h-[40px]" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="ml-auto">
|
<div className="ml-auto">
|
||||||
<Button variant="outline" className="flex items-center gap-x-2 bg-accent hover:bg-accent px-4 cursor-default">
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
className="bg-accent hover:bg-accent flex cursor-default items-center gap-x-2 px-4"
|
||||||
|
>
|
||||||
<Timer />
|
<Timer />
|
||||||
<span className="text-sm">
|
<span className="text-sm">
|
||||||
{t('cart:checkout.timeLeft', {
|
{t('cart:checkout.timeLeft', {
|
||||||
@@ -76,7 +86,9 @@ export default function CartTimer({ cartItem }: { cartItem: StoreCartLineItem })
|
|||||||
{t('cart:checkout.timeoutTitle')}
|
{t('cart:checkout.timeoutTitle')}
|
||||||
</AlertDialogTitle>
|
</AlertDialogTitle>
|
||||||
<AlertDialogDescription>
|
<AlertDialogDescription>
|
||||||
{t('cart:checkout.timeoutDescription', { productTitle: cartItem.product?.title })}
|
{t('cart:checkout.timeoutDescription', {
|
||||||
|
productTitle: cartItem.product?.title,
|
||||||
|
})}
|
||||||
</AlertDialogDescription>
|
</AlertDialogDescription>
|
||||||
</AlertDialogHeader>
|
</AlertDialogHeader>
|
||||||
<AlertDialogFooter>
|
<AlertDialogFooter>
|
||||||
@@ -87,5 +99,5 @@ export default function CartTimer({ cartItem }: { cartItem: StoreCartLineItem })
|
|||||||
</AlertDialogContent>
|
</AlertDialogContent>
|
||||||
</AlertDialog>
|
</AlertDialog>
|
||||||
</>
|
</>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use server"
|
'use server';
|
||||||
|
|
||||||
import { applyPromotions } from "@lib/data/cart"
|
import { applyPromotions } from '@lib/data/cart';
|
||||||
|
|
||||||
export async function addPromotionCodeAction(code: string) {
|
export async function addPromotionCodeAction(code: string) {
|
||||||
try {
|
try {
|
||||||
@@ -12,9 +12,14 @@ export async function addPromotionCodeAction(code: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function removePromotionCodeAction(codeToRemove: string, appliedCodes: string[]) {
|
export async function removePromotionCodeAction(
|
||||||
|
codeToRemove: string,
|
||||||
|
appliedCodes: string[],
|
||||||
|
) {
|
||||||
try {
|
try {
|
||||||
const updatedCodes = appliedCodes.filter((appliedCode) => appliedCode !== codeToRemove);
|
const updatedCodes = appliedCodes.filter(
|
||||||
|
(appliedCode) => appliedCode !== codeToRemove,
|
||||||
|
);
|
||||||
await applyPromotions(updatedCodes);
|
await applyPromotions(updatedCodes);
|
||||||
return { success: true, message: 'Discount code removed successfully' };
|
return { success: true, message: 'Discount code removed successfully' };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -1,30 +1,37 @@
|
|||||||
"use client"
|
'use client';
|
||||||
|
|
||||||
import { Badge, Text } from "@medusajs/ui"
|
import React from 'react';
|
||||||
import { toast } from '@kit/ui/sonner';
|
|
||||||
import React from "react";
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
|
import { convertToLocale } from '@lib/util/money';
|
||||||
|
import { StoreCart, StorePromotion } from '@medusajs/types';
|
||||||
|
import { Badge, Text } from '@medusajs/ui';
|
||||||
|
import Trash from '@modules/common/icons/trash';
|
||||||
|
import { useForm } from 'react-hook-form';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { z } from 'zod';
|
||||||
|
|
||||||
import { convertToLocale } from "@lib/util/money"
|
|
||||||
import { StoreCart, StorePromotion } from "@medusajs/types"
|
|
||||||
import Trash from "@modules/common/icons/trash"
|
|
||||||
import { Button } from '@kit/ui/button';
|
import { Button } from '@kit/ui/button';
|
||||||
import { Form, FormControl, FormField, FormItem } from "@kit/ui/form";
|
import { Form, FormControl, FormField, FormItem } from '@kit/ui/form';
|
||||||
|
import { Input } from '@kit/ui/input';
|
||||||
|
import { toast } from '@kit/ui/sonner';
|
||||||
import { Trans } from '@kit/ui/trans';
|
import { Trans } from '@kit/ui/trans';
|
||||||
import { Input } from "@kit/ui/input";
|
|
||||||
import { useTranslation } from "react-i18next";
|
import {
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
addPromotionCodeAction,
|
||||||
import { useForm } from "react-hook-form";
|
removePromotionCodeAction,
|
||||||
import { z } from "zod";
|
} from './discount-code-actions';
|
||||||
import { addPromotionCodeAction, removePromotionCodeAction } from "./discount-code-actions";
|
|
||||||
|
|
||||||
const DiscountCodeSchema = z.object({
|
const DiscountCodeSchema = z.object({
|
||||||
code: z.string().min(1),
|
code: z.string().min(1),
|
||||||
})
|
});
|
||||||
|
|
||||||
export default function DiscountCode({ cart }: {
|
export default function DiscountCode({
|
||||||
|
cart,
|
||||||
|
}: {
|
||||||
cart: StoreCart & {
|
cart: StoreCart & {
|
||||||
promotions: StorePromotion[]
|
promotions: StorePromotion[];
|
||||||
}
|
};
|
||||||
}) {
|
}) {
|
||||||
const { t } = useTranslation('cart');
|
const { t } = useTranslation('cart');
|
||||||
|
|
||||||
@@ -33,11 +40,11 @@ export default function DiscountCode({ cart }: {
|
|||||||
const removePromotionCode = async (code: string) => {
|
const removePromotionCode = async (code: string) => {
|
||||||
const appliedCodes = promotions
|
const appliedCodes = promotions
|
||||||
.filter((p) => p.code !== undefined)
|
.filter((p) => p.code !== undefined)
|
||||||
.map((p) => p.code!)
|
.map((p) => p.code!);
|
||||||
|
|
||||||
const loading = toast.loading(t('cart:discountCode.removeLoading'));
|
const loading = toast.loading(t('cart:discountCode.removeLoading'));
|
||||||
|
|
||||||
const result = await removePromotionCodeAction(code, appliedCodes)
|
const result = await removePromotionCodeAction(code, appliedCodes);
|
||||||
|
|
||||||
toast.dismiss(loading);
|
toast.dismiss(loading);
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
@@ -45,21 +52,20 @@ export default function DiscountCode({ cart }: {
|
|||||||
} else {
|
} else {
|
||||||
toast.error(t('cart:discountCode.removeError'));
|
toast.error(t('cart:discountCode.removeError'));
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
const addPromotionCode = async (code: string) => {
|
const addPromotionCode = async (code: string) => {
|
||||||
const loading = toast.loading(t('cart:discountCode.addLoading'));
|
const loading = toast.loading(t('cart:discountCode.addLoading'));
|
||||||
const result = await addPromotionCodeAction(code)
|
const result = await addPromotionCodeAction(code);
|
||||||
|
|
||||||
toast.dismiss(loading);
|
toast.dismiss(loading);
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
toast.success(t('cart:discountCode.addSuccess'));
|
toast.success(t('cart:discountCode.addSuccess'));
|
||||||
form.reset()
|
form.reset();
|
||||||
} else {
|
} else {
|
||||||
toast.error(t('cart:discountCode.addError'));
|
toast.error(t('cart:discountCode.addError'));
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
const form = useForm<z.infer<typeof DiscountCodeSchema>>({
|
const form = useForm<z.infer<typeof DiscountCodeSchema>>({
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
@@ -69,40 +75,41 @@ export default function DiscountCode({ cart }: {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="w-full h-full bg-white flex flex-col txt-medium gap-y-4">
|
<div className="txt-medium flex h-full w-full flex-col gap-y-4 bg-white">
|
||||||
<p className="text-sm text-muted-foreground">
|
<p className="text-muted-foreground text-sm">
|
||||||
<Trans i18nKey={'cart:discountCode.subtitle'} />
|
<Trans i18nKey={'cart:discountCode.subtitle'} />
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form
|
<form
|
||||||
onSubmit={form.handleSubmit((data) => addPromotionCode(data.code))}
|
onSubmit={form.handleSubmit((data) => addPromotionCode(data.code))}
|
||||||
className="w-full mb-2 flex gap-x-2 sm:flex-row flex-col gap-y-2 flex-1"
|
className="mb-2 flex w-full flex-1 flex-col gap-x-2 gap-y-2 sm:flex-row"
|
||||||
>
|
>
|
||||||
<FormField
|
<FormField
|
||||||
name={'code'}
|
name={'code'}
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem className="flex-1">
|
<FormItem className="flex-1">
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input required type="text" {...field} placeholder={t('cart:discountCode.placeholder')} />
|
<Input
|
||||||
|
required
|
||||||
|
type="text"
|
||||||
|
{...field}
|
||||||
|
placeholder={t('cart:discountCode.placeholder')}
|
||||||
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Button
|
<Button type="submit" variant="secondary" className="h-min">
|
||||||
type="submit"
|
|
||||||
variant="secondary"
|
|
||||||
className="h-min"
|
|
||||||
>
|
|
||||||
<Trans i18nKey={'cart:discountCode.apply'} />
|
<Trans i18nKey={'cart:discountCode.apply'} />
|
||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
</Form>
|
</Form>
|
||||||
|
|
||||||
{promotions.length > 0 && (
|
{promotions.length > 0 && (
|
||||||
<div className="w-full flex items-center mt-4">
|
<div className="mt-4 flex w-full items-center">
|
||||||
<div className="flex flex-col w-full gap-y-2">
|
<div className="flex w-full flex-col gap-y-2">
|
||||||
<p>
|
<p>
|
||||||
<Trans i18nKey={'cart:discountCode.appliedCodes'} />
|
<Trans i18nKey={'cart:discountCode.appliedCodes'} />
|
||||||
</p>
|
</p>
|
||||||
@@ -111,32 +118,32 @@ export default function DiscountCode({ cart }: {
|
|||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={promotion.id}
|
key={promotion.id}
|
||||||
className="flex items-center justify-between w-full max-w-full mb-2"
|
className="mb-2 flex w-full max-w-full items-center justify-between"
|
||||||
data-testid="discount-row"
|
data-testid="discount-row"
|
||||||
>
|
>
|
||||||
<Text className="flex gap-x-1 items-baseline text-sm w-4/5 pr-1">
|
<Text className="flex w-4/5 items-baseline gap-x-1 pr-1 text-sm">
|
||||||
<span className="truncate" data-testid="discount-code">
|
<span className="truncate" data-testid="discount-code">
|
||||||
<Badge
|
<Badge
|
||||||
color={promotion.is_automatic ? "green" : "grey"}
|
color={promotion.is_automatic ? 'green' : 'grey'}
|
||||||
size="small"
|
size="small"
|
||||||
className="px-4 text-sm"
|
className="px-4 text-sm"
|
||||||
>
|
>
|
||||||
{promotion.code}
|
{promotion.code}
|
||||||
</Badge>{" "}
|
</Badge>{' '}
|
||||||
(
|
(
|
||||||
{promotion.application_method?.value !== undefined &&
|
{promotion.application_method?.value !== undefined &&
|
||||||
promotion.application_method.currency_code !==
|
promotion.application_method.currency_code !==
|
||||||
undefined && (
|
undefined && (
|
||||||
<>
|
<>
|
||||||
{promotion.application_method.type ===
|
{promotion.application_method.type === 'percentage'
|
||||||
"percentage"
|
|
||||||
? `${promotion.application_method.value}%`
|
? `${promotion.application_method.value}%`
|
||||||
: convertToLocale({
|
: convertToLocale({
|
||||||
amount: Number(promotion.application_method.value),
|
amount: Number(
|
||||||
currency_code:
|
promotion.application_method.value,
|
||||||
promotion.application_method
|
),
|
||||||
.currency_code,
|
currency_code:
|
||||||
})}
|
promotion.application_method.currency_code,
|
||||||
|
})}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
)
|
)
|
||||||
@@ -152,10 +159,10 @@ export default function DiscountCode({ cart }: {
|
|||||||
className="flex items-center"
|
className="flex items-center"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (!promotion.code) {
|
if (!promotion.code) {
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
removePromotionCode(promotion.code)
|
removePromotionCode(promotion.code);
|
||||||
}}
|
}}
|
||||||
data-testid="remove-discount-button"
|
data-testid="remove-discount-button"
|
||||||
>
|
>
|
||||||
@@ -166,11 +173,11 @@ export default function DiscountCode({ cart }: {
|
|||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,21 @@
|
|||||||
"use client";
|
'use client';
|
||||||
|
|
||||||
|
import { useState } from 'react';
|
||||||
|
|
||||||
|
import { handleNavigateToPayment } from '@/lib/services/medusaCart.service';
|
||||||
|
import { formatCurrency } from '@/packages/shared/src/utils';
|
||||||
|
import { initiatePaymentSession } from '@lib/data/cart';
|
||||||
|
import { StoreCart, StoreCartLineItem } from '@medusajs/types';
|
||||||
|
import { Loader2 } from 'lucide-react';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import { useState } from "react";
|
|
||||||
import { Loader2 } from "lucide-react";
|
|
||||||
import { StoreCart, StoreCartLineItem } from "@medusajs/types"
|
|
||||||
import CartItems from "./cart-items"
|
|
||||||
import { Trans } from '@kit/ui/trans';
|
|
||||||
import { Button } from '@kit/ui/button';
|
import { Button } from '@kit/ui/button';
|
||||||
import {
|
import { Card, CardContent, CardHeader } from '@kit/ui/card';
|
||||||
Card,
|
import { Trans } from '@kit/ui/trans';
|
||||||
CardContent,
|
|
||||||
CardHeader,
|
import AnalysisLocation from './analysis-location';
|
||||||
} from '@kit/ui/card';
|
import CartItems from './cart-items';
|
||||||
import DiscountCode from "./discount-code";
|
import DiscountCode from './discount-code';
|
||||||
import { initiatePaymentSession } from "@lib/data/cart";
|
|
||||||
import { formatCurrency } from "@/packages/shared/src/utils";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { handleNavigateToPayment } from "@/lib/services/medusaCart.service";
|
|
||||||
import AnalysisLocation from "./analysis-location";
|
|
||||||
|
|
||||||
const IS_DISCOUNT_SHOWN = true as boolean;
|
const IS_DISCOUNT_SHOWN = true as boolean;
|
||||||
|
|
||||||
@@ -25,11 +24,13 @@ export default function Cart({
|
|||||||
synlabAnalyses,
|
synlabAnalyses,
|
||||||
ttoServiceItems,
|
ttoServiceItems,
|
||||||
}: {
|
}: {
|
||||||
cart: StoreCart | null
|
cart: StoreCart | null;
|
||||||
synlabAnalyses: StoreCartLineItem[];
|
synlabAnalyses: StoreCartLineItem[];
|
||||||
ttoServiceItems: StoreCartLineItem[];
|
ttoServiceItems: StoreCartLineItem[];
|
||||||
}) {
|
}) {
|
||||||
const { i18n: { language } } = useTranslation();
|
const {
|
||||||
|
i18n: { language },
|
||||||
|
} = useTranslation();
|
||||||
|
|
||||||
const [isInitiatingSession, setIsInitiatingSession] = useState(false);
|
const [isInitiatingSession, setIsInitiatingSession] = useState(false);
|
||||||
|
|
||||||
@@ -39,7 +40,10 @@ export default function Cart({
|
|||||||
return (
|
return (
|
||||||
<div className="content-container py-5 lg:px-4">
|
<div className="content-container py-5 lg:px-4">
|
||||||
<div>
|
<div>
|
||||||
<div className="flex flex-col justify-center items-center" data-testid="empty-cart-message">
|
<div
|
||||||
|
className="flex flex-col items-center justify-center"
|
||||||
|
data-testid="empty-cart-message"
|
||||||
|
>
|
||||||
<h4 className="text-center">
|
<h4 className="text-center">
|
||||||
<Trans i18nKey="cart:emptyCartMessage" />
|
<Trans i18nKey="cart:emptyCartMessage" />
|
||||||
</h4>
|
</h4>
|
||||||
@@ -71,21 +75,29 @@ export default function Cart({
|
|||||||
const isLocationsShown = synlabAnalyses.length > 0;
|
const isLocationsShown = synlabAnalyses.length > 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="grid grid-cols-1 small:grid-cols-[1fr_360px] gap-x-40 lg:px-4">
|
<div className="small:grid-cols-[1fr_360px] grid grid-cols-1 gap-x-40 lg:px-4">
|
||||||
<div className="flex flex-col bg-white gap-y-6">
|
<div className="flex flex-col gap-y-6 bg-white">
|
||||||
<CartItems cart={cart} items={synlabAnalyses} productColumnLabelKey="cart:items.synlabAnalyses.productColumnLabel" />
|
<CartItems
|
||||||
<CartItems cart={cart} items={ttoServiceItems} productColumnLabelKey="cart:items.ttoServices.productColumnLabel" />
|
cart={cart}
|
||||||
|
items={synlabAnalyses}
|
||||||
|
productColumnLabelKey="cart:items.synlabAnalyses.productColumnLabel"
|
||||||
|
/>
|
||||||
|
<CartItems
|
||||||
|
cart={cart}
|
||||||
|
items={ttoServiceItems}
|
||||||
|
productColumnLabelKey="cart:items.ttoServices.productColumnLabel"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
{hasCartItems && (
|
{hasCartItems && (
|
||||||
<>
|
<>
|
||||||
<div className="flex sm:justify-end gap-x-4 px-4 sm:px-6 pt-2 sm:pt-4">
|
<div className="flex gap-x-4 px-4 pt-2 sm:justify-end sm:px-6 sm:pt-4">
|
||||||
<div className="w-full sm:w-auto sm:mr-[42px]">
|
<div className="w-full sm:mr-[42px] sm:w-auto">
|
||||||
<p className="ml-0 font-bold text-sm text-muted-foreground">
|
<p className="text-muted-foreground ml-0 text-sm font-bold">
|
||||||
<Trans i18nKey="cart:order.subtotal" />
|
<Trans i18nKey="cart:order.subtotal" />
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className={`sm:mr-[112px] sm:w-[50px]`}>
|
<div className={`sm:mr-[112px] sm:w-[50px]`}>
|
||||||
<p className="text-sm text-right">
|
<p className="text-right text-sm">
|
||||||
{formatCurrency({
|
{formatCurrency({
|
||||||
value: cart.subtotal,
|
value: cart.subtotal,
|
||||||
currencyCode: cart.currency_code,
|
currencyCode: cart.currency_code,
|
||||||
@@ -94,14 +106,14 @@ export default function Cart({
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex sm:justify-end gap-x-4 px-4 sm:px-6 py-2 sm:py-4">
|
<div className="flex gap-x-4 px-4 py-2 sm:justify-end sm:px-6 sm:py-4">
|
||||||
<div className="w-full sm:w-auto sm:mr-[42px]">
|
<div className="w-full sm:mr-[42px] sm:w-auto">
|
||||||
<p className="ml-0 font-bold text-sm text-muted-foreground">
|
<p className="text-muted-foreground ml-0 text-sm font-bold">
|
||||||
<Trans i18nKey="cart:order.promotionsTotal" />
|
<Trans i18nKey="cart:order.promotionsTotal" />
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className={`sm:mr-[112px] sm:w-[50px]`}>
|
<div className={`sm:mr-[112px] sm:w-[50px]`}>
|
||||||
<p className="text-sm text-right">
|
<p className="text-right text-sm">
|
||||||
{formatCurrency({
|
{formatCurrency({
|
||||||
value: cart.discount_total,
|
value: cart.discount_total,
|
||||||
currencyCode: cart.currency_code,
|
currencyCode: cart.currency_code,
|
||||||
@@ -110,14 +122,14 @@ export default function Cart({
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex sm:justify-end gap-x-4 px-4 sm:px-6">
|
<div className="flex gap-x-4 px-4 sm:justify-end sm:px-6">
|
||||||
<div className="w-full sm:w-auto sm:mr-[42px]">
|
<div className="w-full sm:mr-[42px] sm:w-auto">
|
||||||
<p className="ml-0 font-bold text-sm">
|
<p className="ml-0 text-sm font-bold">
|
||||||
<Trans i18nKey="cart:order.total" />
|
<Trans i18nKey="cart:order.total" />
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className={`sm:mr-[112px] sm:w-[50px]`}>
|
<div className={`sm:mr-[112px] sm:w-[50px]`}>
|
||||||
<p className="text-sm text-right">
|
<p className="text-right text-sm">
|
||||||
{formatCurrency({
|
{formatCurrency({
|
||||||
value: cart.total,
|
value: cart.total,
|
||||||
currencyCode: cart.currency_code,
|
currencyCode: cart.currency_code,
|
||||||
@@ -129,11 +141,9 @@ export default function Cart({
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="flex sm:flex-row flex-col gap-y-6 py-4 sm:py-8 gap-x-4">
|
<div className="flex flex-col gap-x-4 gap-y-6 py-4 sm:flex-row sm:py-8">
|
||||||
{IS_DISCOUNT_SHOWN && (
|
{IS_DISCOUNT_SHOWN && (
|
||||||
<Card
|
<Card className="flex w-full flex-col justify-between sm:w-1/2">
|
||||||
className="flex flex-col justify-between w-full sm:w-1/2"
|
|
||||||
>
|
|
||||||
<CardHeader className="pb-4">
|
<CardHeader className="pb-4">
|
||||||
<h5>
|
<h5>
|
||||||
<Trans i18nKey="cart:discountCode.title" />
|
<Trans i18nKey="cart:discountCode.title" />
|
||||||
@@ -146,24 +156,31 @@ export default function Cart({
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{isLocationsShown && (
|
{isLocationsShown && (
|
||||||
<Card
|
<Card className="flex w-full flex-col justify-between sm:w-1/2">
|
||||||
className="flex flex-col justify-between w-full sm:w-1/2"
|
|
||||||
>
|
|
||||||
<CardHeader className="pb-4">
|
<CardHeader className="pb-4">
|
||||||
<h5>
|
<h5>
|
||||||
<Trans i18nKey="cart:locations.title" />
|
<Trans i18nKey="cart:locations.title" />
|
||||||
</h5>
|
</h5>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="h-full">
|
<CardContent className="h-full">
|
||||||
<AnalysisLocation cart={{ ...cart }} synlabAnalyses={synlabAnalyses} />
|
<AnalysisLocation
|
||||||
|
cart={{ ...cart }}
|
||||||
|
synlabAnalyses={synlabAnalyses}
|
||||||
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<Button className="h-10" onClick={initiatePayment} disabled={isInitiatingSession}>
|
<Button
|
||||||
{isInitiatingSession && <Loader2 className="w-4 h-4 mr-2 animate-spin" />}
|
className="h-10"
|
||||||
|
onClick={initiatePayment}
|
||||||
|
disabled={isInitiatingSession}
|
||||||
|
>
|
||||||
|
{isInitiatingSession && (
|
||||||
|
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||||
|
)}
|
||||||
<Trans i18nKey="cart:checkout.goToCheckout" />
|
<Trans i18nKey="cart:checkout.goToCheckout" />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -119,4 +119,4 @@
|
|||||||
"hours": "Verevõtt tööpäeviti 8.00-12.00",
|
"hours": "Verevõtt tööpäeviti 8.00-12.00",
|
||||||
"city": "Otepää"
|
"city": "Otepää"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ export interface MontonioOrderToken {
|
|||||||
merchantReference: string;
|
merchantReference: string;
|
||||||
merchantReferenceDisplay: string;
|
merchantReferenceDisplay: string;
|
||||||
paymentStatus:
|
paymentStatus:
|
||||||
| 'PAID'
|
| 'PAID'
|
||||||
| 'FAILED'
|
| 'FAILED'
|
||||||
| 'CANCELLED'
|
| 'CANCELLED'
|
||||||
| 'PENDING'
|
| 'PENDING'
|
||||||
| 'EXPIRED'
|
| 'EXPIRED'
|
||||||
| 'REFUNDED';
|
| 'REFUNDED';
|
||||||
paymentMethod: string;
|
paymentMethod: string;
|
||||||
grandTotal: number;
|
grandTotal: number;
|
||||||
currency: string;
|
currency: string;
|
||||||
@@ -19,4 +19,4 @@ export interface MontonioOrderToken {
|
|||||||
paymentLinkUuid: string;
|
paymentLinkUuid: string;
|
||||||
iat: number;
|
iat: number;
|
||||||
exp: number;
|
exp: number;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
import { JSX } from 'react';
|
import { JSX } from 'react';
|
||||||
|
|
||||||
|
import { StoreProduct } from '@medusajs/types';
|
||||||
import { QuestionMarkCircledIcon } from '@radix-ui/react-icons';
|
import { QuestionMarkCircledIcon } from '@radix-ui/react-icons';
|
||||||
import { VisuallyHidden } from '@radix-ui/react-visually-hidden';
|
import { VisuallyHidden } from '@radix-ui/react-visually-hidden';
|
||||||
import { Check, X } from 'lucide-react';
|
import { Check, X } from 'lucide-react';
|
||||||
|
|
||||||
|
import { PackageHeader } from '@kit/shared/components/package-header';
|
||||||
|
import { AnalysisPackageWithVariant } from '@kit/shared/components/select-analysis-package';
|
||||||
|
import { InfoTooltip } from '@kit/shared/components/ui/info-tooltip';
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
@@ -18,14 +22,14 @@ import {
|
|||||||
TableHeader,
|
TableHeader,
|
||||||
TableRow,
|
TableRow,
|
||||||
} from '@kit/ui/table';
|
} from '@kit/ui/table';
|
||||||
|
|
||||||
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
||||||
import { PackageHeader } from '@kit/shared/components/package-header';
|
|
||||||
import { InfoTooltip } from '@kit/shared/components/ui/info-tooltip';
|
|
||||||
import { StoreProduct } from '@medusajs/types';
|
|
||||||
import { AnalysisPackageWithVariant } from '@kit/shared/components/select-analysis-package';
|
|
||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
|
|
||||||
export type AnalysisPackageElement = Pick<StoreProduct, 'title' | 'id' | 'description'> & {
|
export type AnalysisPackageElement = Pick<
|
||||||
|
StoreProduct,
|
||||||
|
'title' | 'id' | 'description'
|
||||||
|
> & {
|
||||||
isIncludedInStandard: boolean;
|
isIncludedInStandard: boolean;
|
||||||
isIncludedInStandardPlus: boolean;
|
isIncludedInStandardPlus: boolean;
|
||||||
isIncludedInPremium: boolean;
|
isIncludedInPremium: boolean;
|
||||||
@@ -39,7 +43,11 @@ const CheckWithBackground = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const PackageTableHead = async ({ product }: { product: AnalysisPackageWithVariant }) => {
|
const PackageTableHead = async ({
|
||||||
|
product,
|
||||||
|
}: {
|
||||||
|
product: AnalysisPackageWithVariant;
|
||||||
|
}) => {
|
||||||
const { t, language } = await createI18nServerInstance();
|
const { t, language } = await createI18nServerInstance();
|
||||||
|
|
||||||
const { title, price, nrOfAnalyses } = product;
|
const { title, price, nrOfAnalyses } = product;
|
||||||
@@ -48,14 +56,14 @@ const PackageTableHead = async ({ product }: { product: AnalysisPackageWithVaria
|
|||||||
<TableHead className="py-2">
|
<TableHead className="py-2">
|
||||||
<PackageHeader
|
<PackageHeader
|
||||||
title={t(title)}
|
title={t(title)}
|
||||||
tagColor='bg-cyan'
|
tagColor="bg-cyan"
|
||||||
analysesNr={t('product:nrOfAnalyses', { nr: nrOfAnalyses })}
|
analysesNr={t('product:nrOfAnalyses', { nr: nrOfAnalyses })}
|
||||||
language={language}
|
language={language}
|
||||||
price={price}
|
price={price}
|
||||||
/>
|
/>
|
||||||
</TableHead>
|
</TableHead>
|
||||||
)
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
const ComparePackagesModal = async ({
|
const ComparePackagesModal = async ({
|
||||||
analysisPackages,
|
analysisPackages,
|
||||||
@@ -69,7 +77,9 @@ const ComparePackagesModal = async ({
|
|||||||
const { t } = await createI18nServerInstance();
|
const { t } = await createI18nServerInstance();
|
||||||
|
|
||||||
const standardPackage = analysisPackages.find(({ isStandard }) => isStandard);
|
const standardPackage = analysisPackages.find(({ isStandard }) => isStandard);
|
||||||
const standardPlusPackage = analysisPackages.find(({ isStandardPlus }) => isStandardPlus);
|
const standardPlusPackage = analysisPackages.find(
|
||||||
|
({ isStandardPlus }) => isStandardPlus,
|
||||||
|
);
|
||||||
const premiumPackage = analysisPackages.find(({ isPremium }) => isPremium);
|
const premiumPackage = analysisPackages.find(({ isPremium }) => isPremium);
|
||||||
|
|
||||||
if (!standardPackage || !standardPlusPackage || !premiumPackage) {
|
if (!standardPackage || !standardPlusPackage || !premiumPackage) {
|
||||||
@@ -100,7 +110,7 @@ const ComparePackagesModal = async ({
|
|||||||
<p className="text-muted-foreground mx-auto w-3/5 text-sm">
|
<p className="text-muted-foreground mx-auto w-3/5 text-sm">
|
||||||
{t('product:healthPackageComparison.description')}
|
{t('product:healthPackageComparison.description')}
|
||||||
</p>
|
</p>
|
||||||
<div className="rounded-md border max-h-[80vh] overflow-y-auto">
|
<div className="max-h-[80vh] overflow-y-auto rounded-md border">
|
||||||
<Table>
|
<Table>
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
@@ -112,16 +122,14 @@ const ComparePackagesModal = async ({
|
|||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{analysisPackageElements.map(
|
{analysisPackageElements.map(
|
||||||
(
|
({
|
||||||
{
|
title,
|
||||||
title,
|
id,
|
||||||
id,
|
description,
|
||||||
description,
|
isIncludedInStandard,
|
||||||
isIncludedInStandard,
|
isIncludedInStandardPlus,
|
||||||
isIncludedInStandardPlus,
|
isIncludedInPremium,
|
||||||
isIncludedInPremium,
|
}) => {
|
||||||
},
|
|
||||||
) => {
|
|
||||||
if (!title) {
|
if (!title) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -130,20 +138,28 @@ const ComparePackagesModal = async ({
|
|||||||
<TableRow key={id}>
|
<TableRow key={id}>
|
||||||
<TableCell className="py-6 sm:max-w-[30vw]">
|
<TableCell className="py-6 sm:max-w-[30vw]">
|
||||||
{title}{' '}
|
{title}{' '}
|
||||||
{description && (<InfoTooltip content={description} icon={<QuestionMarkCircledIcon />} />)}
|
{description && (
|
||||||
|
<InfoTooltip
|
||||||
|
content={description}
|
||||||
|
icon={<QuestionMarkCircledIcon />}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell align="center" className="py-6">
|
<TableCell align="center" className="py-6">
|
||||||
{isIncludedInStandard && <CheckWithBackground />}
|
{isIncludedInStandard && <CheckWithBackground />}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell align="center" className="py-6">
|
<TableCell align="center" className="py-6">
|
||||||
{isIncludedInStandardPlus && <CheckWithBackground />}
|
{isIncludedInStandardPlus && (
|
||||||
|
<CheckWithBackground />
|
||||||
|
)}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell align="center" className="py-6">
|
<TableCell align="center" className="py-6">
|
||||||
{isIncludedInPremium && <CheckWithBackground />}
|
{isIncludedInPremium && <CheckWithBackground />}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
);
|
);
|
||||||
})}
|
},
|
||||||
|
)}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export default function DashboardCards() {
|
|||||||
<div className="flex gap-4">
|
<div className="flex gap-4">
|
||||||
<Card
|
<Card
|
||||||
variant="gradient-success"
|
variant="gradient-success"
|
||||||
className="xs:w-1/2 sm:w-auto flex w-full flex-col justify-between"
|
className="xs:w-1/2 flex w-full flex-col justify-between sm:w-auto"
|
||||||
>
|
>
|
||||||
<CardHeader className="flex-row">
|
<CardHeader className="flex-row">
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -3,17 +3,11 @@
|
|||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
|
|
||||||
import { BlendingModeIcon } from '@radix-ui/react-icons';
|
import { BlendingModeIcon } from '@radix-ui/react-icons';
|
||||||
import {
|
import { Droplets } from 'lucide-react';
|
||||||
Droplets,
|
|
||||||
} from 'lucide-react';
|
|
||||||
|
|
||||||
import { InfoTooltip } from '@kit/shared/components/ui/info-tooltip';
|
import { InfoTooltip } from '@kit/shared/components/ui/info-tooltip';
|
||||||
import { Button } from '@kit/ui/button';
|
import { Button } from '@kit/ui/button';
|
||||||
import {
|
import { Card, CardContent, CardHeader } from '@kit/ui/card';
|
||||||
Card,
|
|
||||||
CardContent,
|
|
||||||
CardHeader,
|
|
||||||
} from '@kit/ui/card';
|
|
||||||
import { Trans } from '@kit/ui/trans';
|
import { Trans } from '@kit/ui/trans';
|
||||||
import { cn } from '@kit/ui/utils';
|
import { cn } from '@kit/ui/utils';
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
|
|
||||||
import type { AccountWithParams } from '@kit/accounts/types/accounts';
|
|
||||||
import { Database } from '@/packages/supabase/src/database.types';
|
import { Database } from '@/packages/supabase/src/database.types';
|
||||||
import { BlendingModeIcon, RulerHorizontalIcon } from '@radix-ui/react-icons';
|
import { BlendingModeIcon, RulerHorizontalIcon } from '@radix-ui/react-icons';
|
||||||
|
import { isNil } from 'lodash';
|
||||||
import {
|
import {
|
||||||
Activity,
|
Activity,
|
||||||
ChevronRight,
|
ChevronRight,
|
||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
User,
|
User,
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
|
|
||||||
|
import type { AccountWithParams } from '@kit/accounts/types/accounts';
|
||||||
import { pathsConfig } from '@kit/shared/config';
|
import { pathsConfig } from '@kit/shared/config';
|
||||||
import { Button } from '@kit/ui/button';
|
import { Button } from '@kit/ui/button';
|
||||||
import {
|
import {
|
||||||
@@ -27,13 +28,13 @@ import {
|
|||||||
import { Trans } from '@kit/ui/trans';
|
import { Trans } from '@kit/ui/trans';
|
||||||
import { cn } from '@kit/ui/utils';
|
import { cn } from '@kit/ui/utils';
|
||||||
|
|
||||||
import { isNil } from 'lodash';
|
|
||||||
import { BmiCategory } from '~/lib/types/bmi';
|
import { BmiCategory } from '~/lib/types/bmi';
|
||||||
import PersonalCode, {
|
import PersonalCode, {
|
||||||
bmiFromMetric,
|
bmiFromMetric,
|
||||||
getBmiBackgroundColor,
|
getBmiBackgroundColor,
|
||||||
getBmiStatus,
|
getBmiStatus,
|
||||||
} from '~/lib/utils';
|
} from '~/lib/utils';
|
||||||
|
|
||||||
import DashboardRecommendations from './dashboard-recommendations';
|
import DashboardRecommendations from './dashboard-recommendations';
|
||||||
|
|
||||||
const getCardVariant = (isSuccess: boolean | null): CardProps['variant'] => {
|
const getCardVariant = (isSuccess: boolean | null): CardProps['variant'] => {
|
||||||
@@ -57,80 +58,78 @@ const cards = ({
|
|||||||
bmiStatus: BmiCategory | null;
|
bmiStatus: BmiCategory | null;
|
||||||
smoking?: boolean | null;
|
smoking?: boolean | null;
|
||||||
}) => [
|
}) => [
|
||||||
{
|
{
|
||||||
title: 'dashboard:gender',
|
title: 'dashboard:gender',
|
||||||
description: gender ?? '-',
|
description: gender ?? '-',
|
||||||
icon: <User />,
|
icon: <User />,
|
||||||
iconBg: 'bg-success',
|
iconBg: 'bg-success',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'dashboard:age',
|
title: 'dashboard:age',
|
||||||
description: age ? `${age}` : '-',
|
description: age ? `${age}` : '-',
|
||||||
icon: <Clock9 />,
|
icon: <Clock9 />,
|
||||||
iconBg: 'bg-success',
|
iconBg: 'bg-success',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'dashboard:height',
|
title: 'dashboard:height',
|
||||||
description: height ? `${height}cm` : '-',
|
description: height ? `${height}cm` : '-',
|
||||||
icon: <RulerHorizontalIcon className="size-4" />,
|
icon: <RulerHorizontalIcon className="size-4" />,
|
||||||
iconBg: 'bg-success',
|
iconBg: 'bg-success',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'dashboard:weight',
|
title: 'dashboard:weight',
|
||||||
description: weight ? `${weight}kg` : '-',
|
description: weight ? `${weight}kg` : '-',
|
||||||
icon: <Scale />,
|
icon: <Scale />,
|
||||||
iconBg: 'bg-success',
|
iconBg: 'bg-success',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'dashboard:bmi',
|
title: 'dashboard:bmi',
|
||||||
description: bmiFromMetric(weight || 0, height || 0)?.toString() ?? '-',
|
description: bmiFromMetric(weight || 0, height || 0)?.toString() ?? '-',
|
||||||
icon: <TrendingUp />,
|
icon: <TrendingUp />,
|
||||||
iconBg: getBmiBackgroundColor(bmiStatus),
|
iconBg: getBmiBackgroundColor(bmiStatus),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'dashboard:bloodPressure',
|
title: 'dashboard:bloodPressure',
|
||||||
description: '-',
|
description: '-',
|
||||||
icon: <Activity />,
|
icon: <Activity />,
|
||||||
iconBg: 'bg-warning',
|
iconBg: 'bg-warning',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'dashboard:cholesterol',
|
title: 'dashboard:cholesterol',
|
||||||
description: '-',
|
description: '-',
|
||||||
icon: <BlendingModeIcon className="size-4" />,
|
icon: <BlendingModeIcon className="size-4" />,
|
||||||
iconBg: 'bg-destructive',
|
iconBg: 'bg-destructive',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'dashboard:ldlCholesterol',
|
title: 'dashboard:ldlCholesterol',
|
||||||
description: '-',
|
description: '-',
|
||||||
icon: <Pill />,
|
icon: <Pill />,
|
||||||
iconBg: 'bg-warning',
|
iconBg: 'bg-warning',
|
||||||
},
|
},
|
||||||
// {
|
// {
|
||||||
// title: 'Score 2',
|
// title: 'Score 2',
|
||||||
// description: 'Normis',
|
// description: 'Normis',
|
||||||
// icon: <LineChart />,
|
// icon: <LineChart />,
|
||||||
// iconBg: 'bg-success',
|
// iconBg: 'bg-success',
|
||||||
// },
|
// },
|
||||||
{
|
{
|
||||||
title: 'dashboard:smoking',
|
title: 'dashboard:smoking',
|
||||||
description:
|
description: isNil(smoking)
|
||||||
isNil(smoking)
|
? 'dashboard:respondToQuestion'
|
||||||
? 'dashboard:respondToQuestion'
|
: smoking
|
||||||
: !!smoking
|
? 'common:yes'
|
||||||
? 'common:yes'
|
: 'common:no',
|
||||||
: 'common:no',
|
descriptionColor: 'text-primary',
|
||||||
descriptionColor: 'text-primary',
|
icon: isNil(smoking) ? (
|
||||||
icon:
|
<Link href={pathsConfig.app.personalAccountSettings}>
|
||||||
isNil(smoking) ? (
|
<Button size="icon" variant="outline" className="px-2 text-black">
|
||||||
<Link href={pathsConfig.app.personalAccountSettings}>
|
<ChevronRight className="size-4 stroke-2" />
|
||||||
<Button size="icon" variant="outline" className="px-2 text-black">
|
</Button>
|
||||||
<ChevronRight className="size-4 stroke-2" />
|
</Link>
|
||||||
</Button>
|
) : null,
|
||||||
</Link>
|
cardVariant: getCardVariant(isNil(smoking) ? null : !smoking),
|
||||||
) : null,
|
},
|
||||||
cardVariant: getCardVariant(isNil(smoking) ? null : !smoking),
|
];
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const IS_SHOWN_RECOMMENDATIONS = false as boolean;
|
const IS_SHOWN_RECOMMENDATIONS = false as boolean;
|
||||||
|
|
||||||
@@ -146,13 +145,15 @@ export default function Dashboard({
|
|||||||
}) {
|
}) {
|
||||||
const height = account.accountParams?.height || 0;
|
const height = account.accountParams?.height || 0;
|
||||||
const weight = account.accountParams?.weight || 0;
|
const weight = account.accountParams?.weight || 0;
|
||||||
|
|
||||||
let age: number = 0;
|
let age: number = 0;
|
||||||
let gender: { label: string; value: string } | null = null;
|
let gender: { label: string; value: string } | null = null;
|
||||||
try {
|
try {
|
||||||
({ age = 0, gender } = PersonalCode.parsePersonalCode(account.personal_code!));
|
({ age = 0, gender } = PersonalCode.parsePersonalCode(
|
||||||
|
account.personal_code!,
|
||||||
|
));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Failed to parse personal code", e);
|
console.error('Failed to parse personal code', e);
|
||||||
}
|
}
|
||||||
const bmiStatus = getBmiStatus(bmiThresholds, { age, height, weight });
|
const bmiStatus = getBmiStatus(bmiThresholds, { age, height, weight });
|
||||||
|
|
||||||
|
|||||||
@@ -5,11 +5,9 @@ import { useContext } from 'react';
|
|||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
|
|
||||||
import { AccountSelector } from '@kit/accounts/account-selector';
|
import { AccountSelector } from '@kit/accounts/account-selector';
|
||||||
|
import { featureFlagsConfig, pathsConfig } from '@kit/shared/config';
|
||||||
import { SidebarContext } from '@kit/ui/shadcn-sidebar';
|
import { SidebarContext } from '@kit/ui/shadcn-sidebar';
|
||||||
|
|
||||||
import { pathsConfig, featureFlagsConfig } from '@kit/shared/config';
|
|
||||||
|
|
||||||
|
|
||||||
const features = {
|
const features = {
|
||||||
enableTeamCreation: featureFlagsConfig.enableTeamCreation,
|
enableTeamCreation: featureFlagsConfig.enableTeamCreation,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ export function HomeLayoutPageHeader(
|
|||||||
}>,
|
}>,
|
||||||
) {
|
) {
|
||||||
return (
|
return (
|
||||||
<PageHeader description={props.description} title={props.title}>{props.children}</PageHeader>
|
<PageHeader description={props.description} title={props.title}>
|
||||||
|
{props.children}
|
||||||
|
</PageHeader>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,23 @@
|
|||||||
"use client";
|
'use client';
|
||||||
|
|
||||||
|
import { useState } from 'react';
|
||||||
|
|
||||||
|
import { formatCurrency } from '@/packages/shared/src/utils';
|
||||||
|
import { StoreProduct } from '@medusajs/types';
|
||||||
import { HeartPulse, Loader2, ShoppingCart } from 'lucide-react';
|
import { HeartPulse, Loader2, ShoppingCart } from 'lucide-react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import { Button } from '@kit/ui/button';
|
|
||||||
import {
|
|
||||||
Card,
|
|
||||||
CardHeader,
|
|
||||||
CardFooter,
|
|
||||||
CardDescription,
|
|
||||||
} from '@kit/ui/card';
|
|
||||||
import { StoreProduct } from '@medusajs/types';
|
|
||||||
import { useState } from 'react';
|
|
||||||
import { handleAddToCart } from '~/lib/services/medusaCart.service';
|
|
||||||
import { InfoTooltip } from '@kit/shared/components/ui/info-tooltip';
|
import { InfoTooltip } from '@kit/shared/components/ui/info-tooltip';
|
||||||
import { Trans } from '@kit/ui/trans';
|
import { Button } from '@kit/ui/button';
|
||||||
|
import { Card, CardDescription, CardFooter, CardHeader } from '@kit/ui/card';
|
||||||
import { toast } from '@kit/ui/sonner';
|
import { toast } from '@kit/ui/sonner';
|
||||||
import { formatCurrency } from '@/packages/shared/src/utils';
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
|
import { handleAddToCart } from '~/lib/services/medusaCart.service';
|
||||||
|
|
||||||
export type OrderAnalysisCard = Pick<
|
export type OrderAnalysisCard = Pick<
|
||||||
StoreProduct, 'title' | 'description' | 'subtitle'
|
StoreProduct,
|
||||||
|
'title' | 'description' | 'subtitle'
|
||||||
> & {
|
> & {
|
||||||
variant: { id: string };
|
variant: { id: string };
|
||||||
price: number | null;
|
price: number | null;
|
||||||
@@ -32,10 +30,13 @@ export default function OrderAnalysesCards({
|
|||||||
analyses: OrderAnalysisCard[];
|
analyses: OrderAnalysisCard[];
|
||||||
countryCode: string;
|
countryCode: string;
|
||||||
}) {
|
}) {
|
||||||
|
const {
|
||||||
|
i18n: { language },
|
||||||
|
} = useTranslation();
|
||||||
|
|
||||||
const { i18n: { language } } = useTranslation()
|
const [variantAddingToCart, setVariantAddingToCart] = useState<string | null>(
|
||||||
|
null,
|
||||||
const [variantAddingToCart, setVariantAddingToCart] = useState<string | null>(null);
|
);
|
||||||
const handleSelect = async (variantId: string) => {
|
const handleSelect = async (variantId: string) => {
|
||||||
if (variantAddingToCart) {
|
if (variantAddingToCart) {
|
||||||
return null;
|
return null;
|
||||||
@@ -54,24 +55,19 @@ export default function OrderAnalysesCards({
|
|||||||
setVariantAddingToCart(null);
|
setVariantAddingToCart(null);
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="grid xs:grid-cols-3 gap-6 mt-4">
|
<div className="xs:grid-cols-3 mt-4 grid gap-6">
|
||||||
{analyses.map(({
|
{analyses.map(({ title, variant, description, subtitle, price }) => {
|
||||||
title,
|
const formattedPrice =
|
||||||
variant,
|
typeof price === 'number'
|
||||||
description,
|
? formatCurrency({
|
||||||
subtitle,
|
currencyCode: 'eur',
|
||||||
price,
|
locale: language,
|
||||||
}) => {
|
value: price,
|
||||||
const formattedPrice = typeof price === 'number'
|
})
|
||||||
? formatCurrency({
|
: null;
|
||||||
currencyCode: 'eur',
|
|
||||||
locale: language,
|
|
||||||
value: price,
|
|
||||||
})
|
|
||||||
: null;
|
|
||||||
return (
|
return (
|
||||||
<Card
|
<Card
|
||||||
key={title}
|
key={title}
|
||||||
@@ -80,23 +76,29 @@ export default function OrderAnalysesCards({
|
|||||||
>
|
>
|
||||||
<CardHeader className="flex-row">
|
<CardHeader className="flex-row">
|
||||||
<div
|
<div
|
||||||
className={'flex size-8 items-center-safe justify-center-safe rounded-full text-white bg-primary\/10 mb-6'}
|
className={
|
||||||
|
'bg-primary/10 mb-6 flex size-8 items-center-safe justify-center-safe rounded-full text-white'
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<HeartPulse className="size-4 fill-green-500" />
|
<HeartPulse className="size-4 fill-green-500" />
|
||||||
</div>
|
</div>
|
||||||
<div className='ml-auto flex size-8 items-center-safe justify-center-safe rounded-full text-white bg-warning'>
|
<div className="bg-warning ml-auto flex size-8 items-center-safe justify-center-safe rounded-full text-white">
|
||||||
<Button
|
<Button
|
||||||
size="icon"
|
size="icon"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className="px-2 text-black"
|
className="px-2 text-black"
|
||||||
onClick={() => handleSelect(variant.id)}
|
onClick={() => handleSelect(variant.id)}
|
||||||
>
|
>
|
||||||
{variantAddingToCart === variant.id ? <Loader2 className="size-4 stroke-2 animate-spin" /> : <ShoppingCart className="size-4 stroke-2" />}
|
{variantAddingToCart === variant.id ? (
|
||||||
|
<Loader2 className="size-4 animate-spin stroke-2" />
|
||||||
|
) : (
|
||||||
|
<ShoppingCart className="size-4 stroke-2" />
|
||||||
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardFooter className="flex gap-2">
|
<CardFooter className="flex gap-2">
|
||||||
<div className="flex flex-col items-start gap-2 flex-1">
|
<div className="flex flex-1 flex-col items-start gap-2">
|
||||||
<h5>
|
<h5>
|
||||||
{title}
|
{title}
|
||||||
{description && (
|
{description && (
|
||||||
@@ -104,7 +106,7 @@ export default function OrderAnalysesCards({
|
|||||||
{' '}
|
{' '}
|
||||||
<InfoTooltip
|
<InfoTooltip
|
||||||
content={
|
content={
|
||||||
<div className='flex flex-col gap-2'>
|
<div className="flex flex-col gap-2">
|
||||||
<span>{formattedPrice}</span>
|
<span>{formattedPrice}</span>
|
||||||
<span>{description}</span>
|
<span>{description}</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -113,11 +115,7 @@ export default function OrderAnalysesCards({
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</h5>
|
</h5>
|
||||||
{subtitle && (
|
{subtitle && <CardDescription>{subtitle}</CardDescription>}
|
||||||
<CardDescription>
|
|
||||||
{subtitle}
|
|
||||||
</CardDescription>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col items-end gap-2 self-end text-sm">
|
<div className="flex flex-col items-end gap-2 self-end text-sm">
|
||||||
<span>{formattedPrice}</span>
|
<span>{formattedPrice}</span>
|
||||||
|
|||||||
@@ -1,15 +1,21 @@
|
|||||||
"use client"
|
'use client';
|
||||||
|
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import { formatCurrency } from '@/packages/shared/src/utils';
|
||||||
|
import { StoreOrder } from '@medusajs/types';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import { formatCurrency } from "@/packages/shared/src/utils"
|
|
||||||
import { StoreOrder } from "@medusajs/types"
|
|
||||||
import React from "react"
|
|
||||||
import { useTranslation } from "react-i18next"
|
|
||||||
import { Trans } from '@kit/ui/trans';
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
export default function CartTotals({ medusaOrder }: {
|
export default function CartTotals({
|
||||||
medusaOrder: StoreOrder
|
medusaOrder,
|
||||||
|
}: {
|
||||||
|
medusaOrder: StoreOrder;
|
||||||
}) {
|
}) {
|
||||||
const { i18n: { language } } = useTranslation()
|
const {
|
||||||
|
i18n: { language },
|
||||||
|
} = useTranslation();
|
||||||
const {
|
const {
|
||||||
currency_code,
|
currency_code,
|
||||||
total,
|
total,
|
||||||
@@ -17,29 +23,39 @@ export default function CartTotals({ medusaOrder }: {
|
|||||||
tax_total,
|
tax_total,
|
||||||
discount_total,
|
discount_total,
|
||||||
gift_card_total,
|
gift_card_total,
|
||||||
} = medusaOrder
|
} = medusaOrder;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="flex flex-col gap-y-2 txt-medium text-ui-fg-subtle ">
|
<div className="txt-medium text-ui-fg-subtle flex flex-col gap-y-2">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<span className="flex gap-x-1 items-center">
|
<span className="flex items-center gap-x-1">
|
||||||
<Trans i18nKey="cart:order.subtotal" />
|
<Trans i18nKey="cart:order.subtotal" />
|
||||||
</span>
|
</span>
|
||||||
<span data-testid="cart-subtotal" data-value={subtotal || 0}>
|
<span data-testid="cart-subtotal" data-value={subtotal || 0}>
|
||||||
{formatCurrency({ value: subtotal ?? 0, currencyCode: currency_code, locale: language })}
|
{formatCurrency({
|
||||||
|
value: subtotal ?? 0,
|
||||||
|
currencyCode: currency_code,
|
||||||
|
locale: language,
|
||||||
|
})}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{!!discount_total && (
|
{!!discount_total && (
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<span><Trans i18nKey="cart:order.promotionsTotal" /></span>
|
<span>
|
||||||
|
<Trans i18nKey="cart:order.promotionsTotal" />
|
||||||
|
</span>
|
||||||
<span
|
<span
|
||||||
className="text-ui-fg-interactive"
|
className="text-ui-fg-interactive"
|
||||||
data-testid="cart-discount"
|
data-testid="cart-discount"
|
||||||
data-value={discount_total || 0}
|
data-value={discount_total || 0}
|
||||||
>
|
>
|
||||||
-{" "}
|
-{' '}
|
||||||
{formatCurrency({ value: discount_total ?? 0, currencyCode: currency_code, locale: language })}
|
{formatCurrency({
|
||||||
|
value: discount_total ?? 0,
|
||||||
|
currencyCode: currency_code,
|
||||||
|
locale: language,
|
||||||
|
})}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -53,30 +69,42 @@ export default function CartTotals({ medusaOrder }: {
|
|||||||
</div> */}
|
</div> */}
|
||||||
{!!gift_card_total && (
|
{!!gift_card_total && (
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<span><Trans i18nKey="cart:order.giftCard" /></span>
|
<span>
|
||||||
|
<Trans i18nKey="cart:order.giftCard" />
|
||||||
|
</span>
|
||||||
<span
|
<span
|
||||||
className="text-ui-fg-interactive"
|
className="text-ui-fg-interactive"
|
||||||
data-testid="cart-gift-card-amount"
|
data-testid="cart-gift-card-amount"
|
||||||
data-value={gift_card_total || 0}
|
data-value={gift_card_total || 0}
|
||||||
>
|
>
|
||||||
-{" "}
|
-{' '}
|
||||||
{formatCurrency({ value: gift_card_total ?? 0, currencyCode: currency_code, locale: language })}
|
{formatCurrency({
|
||||||
|
value: gift_card_total ?? 0,
|
||||||
|
currencyCode: currency_code,
|
||||||
|
locale: language,
|
||||||
|
})}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="h-px w-full border-b border-gray-200 my-4" />
|
<div className="my-4 h-px w-full border-b border-gray-200" />
|
||||||
<div className="flex items-center justify-between text-ui-fg-base mb-2 txt-medium ">
|
<div className="text-ui-fg-base txt-medium mb-2 flex items-center justify-between">
|
||||||
<span className="font-bold"><Trans i18nKey="cart:order.total" /></span>
|
<span className="font-bold">
|
||||||
|
<Trans i18nKey="cart:order.total" />
|
||||||
|
</span>
|
||||||
<span
|
<span
|
||||||
className="txt-xlarge-plus"
|
className="txt-xlarge-plus"
|
||||||
data-testid="cart-total"
|
data-testid="cart-total"
|
||||||
data-value={total || 0}
|
data-value={total || 0}
|
||||||
>
|
>
|
||||||
{formatCurrency({ value: total ?? 0, currencyCode: currency_code, locale: language })}
|
{formatCurrency({
|
||||||
|
value: total ?? 0,
|
||||||
|
currencyCode: currency_code,
|
||||||
|
locale: language,
|
||||||
|
})}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="h-px w-full border-b border-gray-200 mt-4" />
|
<div className="mt-4 h-px w-full border-b border-gray-200" />
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +1,25 @@
|
|||||||
import { Trans } from '@kit/ui/trans';
|
|
||||||
import { formatDate } from 'date-fns';
|
import { formatDate } from 'date-fns';
|
||||||
import type { AnalysisOrder } from "~/lib/types/analysis-order";
|
|
||||||
|
|
||||||
export default function OrderDetails({ order }: {
|
import { Trans } from '@kit/ui/trans';
|
||||||
order: AnalysisOrder
|
|
||||||
}) {
|
import type { AnalysisOrder } from '~/lib/types/analysis-order';
|
||||||
|
|
||||||
|
export default function OrderDetails({ order }: { order: AnalysisOrder }) {
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-y-2">
|
<div className="flex flex-col gap-y-2">
|
||||||
<div>
|
<div>
|
||||||
<span className="font-bold">
|
<span className="font-bold">
|
||||||
<Trans i18nKey="cart:orderConfirmed.orderNumber" />:{" "}
|
<Trans i18nKey="cart:orderConfirmed.orderNumber" />:{' '}
|
||||||
</span>
|
|
||||||
<span>
|
|
||||||
{order.medusa_order_id}
|
|
||||||
</span>
|
</span>
|
||||||
|
<span>{order.medusa_order_id}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<span className="font-bold">
|
<span className="font-bold">
|
||||||
<Trans i18nKey="cart:orderConfirmed.orderDate" />:{" "}
|
<Trans i18nKey="cart:orderConfirmed.orderDate" />:{' '}
|
||||||
</span>
|
|
||||||
<span>
|
|
||||||
{formatDate(order.created_at, 'dd.MM.yyyy HH:mm')}
|
|
||||||
</span>
|
</span>
|
||||||
|
<span>{formatDate(order.created_at, 'dd.MM.yyyy HH:mm')}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
import { StoreCartLineItem, StoreOrderLineItem } from "@medusajs/types"
|
import { StoreCartLineItem, StoreOrderLineItem } from '@medusajs/types';
|
||||||
import { TableCell, TableRow } from "@kit/ui/table"
|
|
||||||
|
|
||||||
// import LineItemOptions from "@modules/common/components/line-item-options"
|
// import LineItemOptions from "@modules/common/components/line-item-options"
|
||||||
import LineItemPrice from "@modules/common/components/line-item-price"
|
import LineItemPrice from '@modules/common/components/line-item-price';
|
||||||
import LineItemUnitPrice from "@modules/common/components/line-item-unit-price"
|
import LineItemUnitPrice from '@modules/common/components/line-item-unit-price';
|
||||||
|
|
||||||
export default function OrderItem({ item, currencyCode }: {
|
import { TableCell, TableRow } from '@kit/ui/table';
|
||||||
item: StoreCartLineItem | StoreOrderLineItem
|
|
||||||
currencyCode: string
|
export default function OrderItem({
|
||||||
|
item,
|
||||||
|
currencyCode,
|
||||||
|
}: {
|
||||||
|
item: StoreCartLineItem | StoreOrderLineItem;
|
||||||
|
currencyCode: string;
|
||||||
}) {
|
}) {
|
||||||
const partnerLocationName = item.metadata?.partner_location_name;
|
const partnerLocationName = item.metadata?.partner_location_name;
|
||||||
return (
|
return (
|
||||||
@@ -18,22 +21,21 @@ export default function OrderItem({ item, currencyCode }: {
|
|||||||
</div>
|
</div>
|
||||||
</TableCell> */}
|
</TableCell> */}
|
||||||
|
|
||||||
<TableCell className="text-left px-6">
|
<TableCell className="px-6 text-left">
|
||||||
<span
|
<span
|
||||||
className="txt-medium-plus text-ui-fg-base"
|
className="txt-medium-plus text-ui-fg-base"
|
||||||
data-testid="product-name"
|
data-testid="product-name"
|
||||||
>
|
>
|
||||||
{item.product_title}{` ${partnerLocationName ? `(${partnerLocationName})` : ''}`}
|
{item.product_title}
|
||||||
|
{` ${partnerLocationName ? `(${partnerLocationName})` : ''}`}
|
||||||
</span>
|
</span>
|
||||||
{/* <LineItemOptions variant={item.variant} data-testid="product-variant" /> */}
|
{/* <LineItemOptions variant={item.variant} data-testid="product-variant" /> */}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
<TableCell className="px-6">
|
<TableCell className="px-6">
|
||||||
<span className="flex flex-col items-end h-full justify-center">
|
<span className="flex h-full flex-col items-end justify-center">
|
||||||
<span className="flex gap-x-1 ">
|
<span className="flex gap-x-1">
|
||||||
<span className="text-ui-fg-muted">
|
<span className="text-ui-fg-muted">{item.quantity}x </span>
|
||||||
{item.quantity}x{" "}
|
|
||||||
</span>
|
|
||||||
<LineItemUnitPrice
|
<LineItemUnitPrice
|
||||||
item={item}
|
item={item}
|
||||||
style="tight"
|
style="tight"
|
||||||
@@ -49,5 +51,5 @@ export default function OrderItem({ item, currencyCode }: {
|
|||||||
</span>
|
</span>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,39 +1,44 @@
|
|||||||
import repeat from "@lib/util/repeat"
|
import repeat from '@lib/util/repeat';
|
||||||
import { StoreOrder } from "@medusajs/types"
|
import { StoreOrder } from '@medusajs/types';
|
||||||
import { Table, TableBody } from "@kit/ui/table"
|
import SkeletonLineItem from '@modules/skeletons/components/skeleton-line-item';
|
||||||
|
|
||||||
import SkeletonLineItem from "@modules/skeletons/components/skeleton-line-item"
|
import { Heading } from '@kit/ui/heading';
|
||||||
import OrderItem from "./order-item"
|
import { Table, TableBody } from '@kit/ui/table';
|
||||||
import { Heading } from "@kit/ui/heading"
|
|
||||||
import { Trans } from '@kit/ui/trans';
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
export default function OrderItems({ medusaOrder }: {
|
import OrderItem from './order-item';
|
||||||
medusaOrder: StoreOrder
|
|
||||||
|
export default function OrderItems({
|
||||||
|
medusaOrder,
|
||||||
|
}: {
|
||||||
|
medusaOrder: StoreOrder;
|
||||||
}) {
|
}) {
|
||||||
const items = medusaOrder.items
|
const items = medusaOrder.items;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-y-4">
|
<div className="flex flex-col gap-y-4">
|
||||||
<Heading level={5} className="flex flex-row text-3xl-regular">
|
<Heading level={5} className="text-3xl-regular flex flex-row">
|
||||||
<Trans i18nKey="cart:orderConfirmed.summary" />
|
<Trans i18nKey="cart:orderConfirmed.summary" />
|
||||||
</Heading>
|
</Heading>
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
<Table className="rounded-lg border border-separate">
|
<Table className="border-separate rounded-lg border">
|
||||||
<TableBody data-testid="products-table">
|
<TableBody data-testid="products-table">
|
||||||
{items?.length
|
{items?.length
|
||||||
? items
|
? items
|
||||||
.sort((a, b) => (a.created_at ?? "") > (b.created_at ?? "") ? -1 : 1)
|
.sort((a, b) =>
|
||||||
.map((item) => (
|
(a.created_at ?? '') > (b.created_at ?? '') ? -1 : 1,
|
||||||
<OrderItem
|
)
|
||||||
key={item.id}
|
.map((item) => (
|
||||||
item={item}
|
<OrderItem
|
||||||
currencyCode={medusaOrder.currency_code}
|
key={item.id}
|
||||||
/>
|
item={item}
|
||||||
))
|
currencyCode={medusaOrder.currency_code}
|
||||||
|
/>
|
||||||
|
))
|
||||||
: repeat(5).map((i) => <SkeletonLineItem key={i} />)}
|
: repeat(5).map((i) => <SkeletonLineItem key={i} />)}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,15 @@
|
|||||||
'use server';
|
'use server';
|
||||||
|
|
||||||
import { createPageViewLog, PageViewAction } from "~/lib/services/audit/pageView.service";
|
import {
|
||||||
import { loadCurrentUserAccount } from "../../_lib/server/load-user-account";
|
PageViewAction,
|
||||||
|
createPageViewLog,
|
||||||
|
} from '~/lib/services/audit/pageView.service';
|
||||||
|
|
||||||
export async function logAnalysisResultsNavigateAction(analysisOrderId: string) {
|
import { loadCurrentUserAccount } from '../../_lib/server/load-user-account';
|
||||||
|
|
||||||
|
export async function logAnalysisResultsNavigateAction(
|
||||||
|
analysisOrderId: string,
|
||||||
|
) {
|
||||||
const { account } = await loadCurrentUserAccount();
|
const { account } = await loadCurrentUserAccount();
|
||||||
if (!account) {
|
if (!account) {
|
||||||
throw new Error('Account not found');
|
throw new Error('Account not found');
|
||||||
|
|||||||
@@ -1,37 +1,57 @@
|
|||||||
import type { AnalysisOrder } from "~/lib/types/analysis-order";
|
import Link from 'next/link';
|
||||||
import { Trans } from '@kit/ui/makerkit/trans';
|
|
||||||
import { StoreOrderLineItem } from "@medusajs/types";
|
|
||||||
import OrderItemsTable from "./order-items-table";
|
|
||||||
import Link from "next/link";
|
|
||||||
import { Eye } from "lucide-react";
|
|
||||||
|
|
||||||
export default function OrderBlock({ analysisOrder, itemsAnalysisPackage, itemsOther }: {
|
import { StoreOrderLineItem } from '@medusajs/types';
|
||||||
analysisOrder: AnalysisOrder,
|
import { Eye } from 'lucide-react';
|
||||||
itemsAnalysisPackage: StoreOrderLineItem[],
|
|
||||||
itemsOther: StoreOrderLineItem[],
|
import { Trans } from '@kit/ui/makerkit/trans';
|
||||||
|
|
||||||
|
import type { AnalysisOrder } from '~/lib/types/analysis-order';
|
||||||
|
|
||||||
|
import OrderItemsTable from './order-items-table';
|
||||||
|
|
||||||
|
export default function OrderBlock({
|
||||||
|
analysisOrder,
|
||||||
|
itemsAnalysisPackage,
|
||||||
|
itemsOther,
|
||||||
|
}: {
|
||||||
|
analysisOrder: AnalysisOrder;
|
||||||
|
itemsAnalysisPackage: StoreOrderLineItem[];
|
||||||
|
itemsOther: StoreOrderLineItem[];
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
<h4>
|
<h4>
|
||||||
<Trans i18nKey="analysis-results:orderTitle" values={{ orderNumber: analysisOrder.medusa_order_id }} />
|
<Trans
|
||||||
|
i18nKey="analysis-results:orderTitle"
|
||||||
|
values={{ orderNumber: analysisOrder.medusa_order_id }}
|
||||||
|
/>
|
||||||
{` (${analysisOrder.id})`}
|
{` (${analysisOrder.id})`}
|
||||||
</h4>
|
</h4>
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
<h5>
|
<h5>
|
||||||
<Trans i18nKey={`orders:status.${analysisOrder.status}`} />
|
<Trans i18nKey={`orders:status.${analysisOrder.status}`} />
|
||||||
</h5>
|
</h5>
|
||||||
<Link href={`/home/order/${analysisOrder.id}`} className="flex items-center justify-between text-small-regular">
|
<Link
|
||||||
<button
|
href={`/home/order/${analysisOrder.id}`}
|
||||||
className="flex gap-x-1 text-ui-fg-subtle hover:text-ui-fg-base cursor-pointer"
|
className="text-small-regular flex items-center justify-between"
|
||||||
>
|
>
|
||||||
|
<button className="text-ui-fg-subtle hover:text-ui-fg-base flex cursor-pointer gap-x-1">
|
||||||
<Eye />
|
<Eye />
|
||||||
</button>
|
</button>
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
<OrderItemsTable items={itemsAnalysisPackage} title="orders:table.analysisPackage" analysisOrder={analysisOrder} />
|
<OrderItemsTable
|
||||||
<OrderItemsTable items={itemsOther} title="orders:table.otherOrders" analysisOrder={analysisOrder} />
|
items={itemsAnalysisPackage}
|
||||||
|
title="orders:table.analysisPackage"
|
||||||
|
analysisOrder={analysisOrder}
|
||||||
|
/>
|
||||||
|
<OrderItemsTable
|
||||||
|
items={itemsOther}
|
||||||
|
title="orders:table.otherOrders"
|
||||||
|
analysisOrder={analysisOrder}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ export default function OrderItemsTable({
|
|||||||
)
|
)
|
||||||
.map((orderItem) => (
|
.map((orderItem) => (
|
||||||
<TableRow className="w-full" key={orderItem.id}>
|
<TableRow className="w-full" key={orderItem.id}>
|
||||||
<TableCell className="text-left w-[100%] px-6">
|
<TableCell className="w-[100%] px-6 text-left">
|
||||||
<p className="txt-medium-plus text-ui-fg-base">
|
<p className="txt-medium-plus text-ui-fg-base">
|
||||||
{orderItem.product_title}
|
{orderItem.product_title}
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user