Compare commits
16 Commits
84c8dcc792
...
keycloak2
| Author | SHA1 | Date | |
|---|---|---|---|
| ab92c3b4d0 | |||
| e324872c3c | |||
| a44f9c9207 | |||
| 0cf04b4f55 | |||
| 84216c3ced | |||
| 0037241558 | |||
| c7f89723e3 | |||
| 4a06059a25 | |||
| a0abb44257 | |||
| 283b502963 | |||
| 5c8f8b73d7 | |||
| 5b52da0a62 | |||
|
|
21375cf55f | ||
|
|
9122acc89f | ||
|
|
152ec5f36b | ||
|
|
5176ecdddc |
2
.dockerignore
Normal file
2
.dockerignore
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
.git
|
||||||
|
Dockerfile
|
||||||
5
.env
5
.env
@@ -13,7 +13,7 @@ NEXT_PUBLIC_THEME_COLOR="#ffffff"
|
|||||||
NEXT_PUBLIC_THEME_COLOR_DARK="#0a0a0a"
|
NEXT_PUBLIC_THEME_COLOR_DARK="#0a0a0a"
|
||||||
|
|
||||||
# AUTH
|
# AUTH
|
||||||
NEXT_PUBLIC_AUTH_PASSWORD=true
|
NEXT_PUBLIC_AUTH_PASSWORD=false
|
||||||
NEXT_PUBLIC_AUTH_MAGIC_LINK=false
|
NEXT_PUBLIC_AUTH_MAGIC_LINK=false
|
||||||
NEXT_PUBLIC_CAPTCHA_SITE_KEY=
|
NEXT_PUBLIC_CAPTCHA_SITE_KEY=
|
||||||
|
|
||||||
@@ -65,3 +65,6 @@ NEXT_PUBLIC_TEAM_NAVIGATION_STYLE=custom
|
|||||||
NEXT_PUBLIC_USER_NAVIGATION_STYLE=custom
|
NEXT_PUBLIC_USER_NAVIGATION_STYLE=custom
|
||||||
|
|
||||||
NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY=
|
NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY=
|
||||||
|
|
||||||
|
# Configure Medusa password secret for Keycloak users
|
||||||
|
MEDUSA_PASSWORD_SECRET=ODEwMGNiMmUtOGMxYS0xMWYwLWJlZDYtYTM3YzYyMWY0NGEzCg==
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
# SITE
|
# SITE
|
||||||
NEXT_PUBLIC_SITE_URL=http://localhost:3000
|
NEXT_PUBLIC_SITE_URL=http://localhost:3000
|
||||||
|
NEXT_PUBLIC_AUTH_PASSWORD=true
|
||||||
|
|
||||||
# SUPABASE DEVELOPMENT
|
# SUPABASE DEVELOPMENT
|
||||||
|
|
||||||
@@ -25,14 +26,65 @@ EMAIL_PORT=1025 # or 465 for SSL
|
|||||||
EMAIL_TLS=false
|
EMAIL_TLS=false
|
||||||
NODE_TLS_REJECT_UNAUTHORIZED=0
|
NODE_TLS_REJECT_UNAUTHORIZED=0
|
||||||
|
|
||||||
|
# MEDIPOST
|
||||||
|
|
||||||
|
MEDIPOST_URL=https://meditest.medisoft.ee:7443/Medipost/MedipostServlet
|
||||||
|
MEDIPOST_USER=trvurgtst
|
||||||
|
MEDIPOST_PASSWORD=SRB48HZMV
|
||||||
|
MEDIPOST_RECIPIENT=trvurgtst
|
||||||
|
MEDIPOST_MESSAGE_SENDER=trvurgtst
|
||||||
|
|
||||||
|
#MEDIPOST_URL=https://medipost2.medisoft.ee:8443/Medipost/MedipostServlet
|
||||||
|
#MEDIPOST_USER=medreport
|
||||||
|
#MEDIPOST_PASSWORD=85MXFFDB7
|
||||||
|
#MEDIPOST_RECIPIENT=HTI
|
||||||
|
#MEDIPOST_MESSAGE_SENDER=medreport
|
||||||
|
|
||||||
# MEDUSA
|
# MEDUSA
|
||||||
MEDUSA_BACKEND_URL=http://localhost:9000
|
MEDUSA_BACKEND_URL=http://localhost:9000
|
||||||
MEDUSA_BACKEND_PUBLIC_URL=http://localhost:9000
|
MEDUSA_BACKEND_PUBLIC_URL=http://localhost:9000
|
||||||
|
MEDUSA_SECRET_API_KEY=sk_b332d525212ab4078ef73fb2b8232c3beebccc4a460e2c7abf6e187a458d60cf
|
||||||
|
NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY=pk_e23a820689a07d55aa0a0ad187268559f5d6288ecb0768ff4520516285bdef84
|
||||||
|
|
||||||
|
#MEDUSA_BACKEND_URL=https://backoffice-test.medreport.ee
|
||||||
|
#MEDUSA_BACKEND_PUBLIC_URL=https://backoffice-test.medreport.ee
|
||||||
|
#MEDUSA_SECRET_API_KEY=sk_fdb1808fbabf62979cc46316aa997378ffbb87882883e8f5c3ee47cee39dcac5
|
||||||
|
#NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY=pk_827a2ab863021cb67993f1d81078f81bfce4b4e0da642d8c0f5398ded9d8fd32
|
||||||
|
|
||||||
|
#MEDUSA_BACKEND_URL=https://backoffice.medreport.ee
|
||||||
|
#MEDUSA_BACKEND_PUBLIC_URL=https://backoffice.medreport.ee
|
||||||
|
#NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY=pk_068d930c33fea53608a410d84a51935f6ce2ccec5bef8e0ecf75eaee602ac486
|
||||||
|
#MEDUSA_SECRET_API_KEY=sk_fdb1808fbabf62979cc46316aa997378ffbb87882883e8f5c3ee47cee39dcac5
|
||||||
|
|
||||||
|
#MEDUSA_BACKEND_URL=http://5.181.51.38:9000
|
||||||
|
#MEDUSA_BACKEND_PUBLIC_URL=http://5.181.51.38:9000
|
||||||
|
#NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY=pk_0ec86252438b38ce18d5601f7877e4395d7e0a6afa8687dfea8d37af33015633
|
||||||
|
|
||||||
# MONTONIO
|
# MONTONIO
|
||||||
NEXT_PUBLIC_MONTONIO_ACCESS_KEY=7da5d7fa-3383-4997-9435-46aa818f4ead
|
NEXT_PUBLIC_MONTONIO_ACCESS_KEY=7da5d7fa-3383-4997-9435-46aa818f4ead
|
||||||
MONTONIO_SECRET_KEY=rNZkzwxOiH93mzkdV53AvhSsbGidrgO2Kl5lE/IT7cvo
|
MONTONIO_SECRET_KEY=rNZkzwxOiH93mzkdV53AvhSsbGidrgO2Kl5lE/IT7cvo
|
||||||
MONTONIO_API_URL=https://sandbox-stargate.montonio.com
|
MONTONIO_API_URL=https://sandbox-stargate.montonio.com
|
||||||
|
|
||||||
|
#NEXT_PUBLIC_MONTONIO_ACCESS_KEY=13e3686a-e7ad-41f6-998b-3f7d7de17654
|
||||||
|
#MONTONIO_SECRET_KEY=wTd4BZ01h80KZLMPL4mjt0RCFxKaYRSu9mMB1PQZCxnw
|
||||||
|
#MONTONIO_API_URL=https://stargate.montonio.com
|
||||||
|
|
||||||
# JOBS
|
# JOBS
|
||||||
JOBS_API_TOKEN=73ce073c-6dd4-11f0-8e75-8fee89786197
|
JOBS_API_TOKEN=73ce073c-6dd4-11f0-8e75-8fee89786197
|
||||||
|
|
||||||
|
# SUPABASE
|
||||||
|
NEXT_PUBLIC_SUPABASE_URL=https://klocrucggryikaxzvxgc.supabase.co
|
||||||
|
NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imtsb2NydWNnZ3J5aWtheHp2eGdjIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTY5ODQ2MjgsImV4cCI6MjA3MjU2MDYyOH0.2XOQngowcymiSUZO_XEEWAWzco2uRIjwG7TAeRRLIdU
|
||||||
|
SUPABASE_SERVICE_ROLE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imtsb2NydWNnZ3J5aWtheHp2eGdjIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTc1Njk4NDYyOCwiZXhwIjoyMDcyNTYwNjI4fQ.1UZR7AqSD9bOy1gtZRGhOCNoESsw2W-DoFDDsNNMwoE
|
||||||
|
|
||||||
|
#NEXT_PUBLIC_SUPABASE_URL=https://oqsdacktkhmbylmzstjq.supabase.co
|
||||||
|
#NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im9xc2RhY2t0a2htYnlsbXpzdGpxIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDY1MjgxMjMsImV4cCI6MjA2MjEwNDEyM30.LdHCTWxijFmhXdnT9KVuLRAVbtSwY7OO-oLtpd8GmO0
|
||||||
|
#SUPABASE_SERVICE_ROLE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im9xc2RhY2t0a2htYnlsbXpzdGpxIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTc0NjUyODEyMywiZXhwIjoyMDYyMTA0MTIzfQ.KVcnkZ21Pd0XkJho23dZqFHawVTLQqfvF7l2RxsELLk
|
||||||
|
|
||||||
|
#NEXT_PUBLIC_SUPABASE_URL=http://5.181.51.38:54321
|
||||||
|
#NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0
|
||||||
|
#SUPABASE_SERVICE_ROLE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU
|
||||||
|
|
||||||
|
### TEST.MEDREPORT.ee ###
|
||||||
|
|
||||||
|
DB_PASSWORD=T#u-$M7%RjbA@L@
|
||||||
|
|||||||
@@ -13,10 +13,7 @@ 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 } from '@kit/shared/config';
|
import { authConfig, featureFlagsConfig, pathsConfig } from '@kit/shared/config';
|
||||||
|
|
||||||
import { pathsConfig } from '@kit/shared/config';
|
|
||||||
|
|
||||||
|
|
||||||
const ModeToggle = dynamic(() =>
|
const ModeToggle = dynamic(() =>
|
||||||
import('@kit/ui/mode-toggle').then((mod) => ({
|
import('@kit/ui/mode-toggle').then((mod) => ({
|
||||||
@@ -75,11 +72,13 @@ function AuthButtons() {
|
|||||||
</Link>
|
</Link>
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button asChild className="text-xs md:text-sm" variant={'default'}>
|
{authConfig.providers.password && (
|
||||||
<Link href={pathsConfig.auth.signUp}>
|
<Button asChild className="text-xs md:text-sm" variant={'default'}>
|
||||||
<Trans i18nKey={'auth:signUp'} />
|
<Link href={pathsConfig.auth.signUp}>
|
||||||
</Link>
|
<Trans i18nKey={'auth:signUp'} />
|
||||||
</Button>
|
</Link>
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -9,18 +9,16 @@ import { ContactEmailSchema } from '../contact-email.schema';
|
|||||||
|
|
||||||
const contactEmail = z
|
const contactEmail = z
|
||||||
.string({
|
.string({
|
||||||
description: `The email where you want to receive the contact form submissions.`,
|
error:
|
||||||
required_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.`)
|
||||||
.parse(process.env.CONTACT_EMAIL);
|
.parse(process.env.CONTACT_EMAIL);
|
||||||
|
|
||||||
const emailFrom = z
|
const emailFrom = z
|
||||||
.string({
|
.string({
|
||||||
description: `The email sending address.`,
|
error:
|
||||||
required_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.`)
|
||||||
.parse(process.env.EMAIL_SENDER);
|
.parse(process.env.EMAIL_SENDER);
|
||||||
|
|
||||||
export const sendContactEmail = enhanceAction(
|
export const sendContactEmail = enhanceAction(
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
|
|
||||||
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 { ArrowRightIcon } from 'lucide-react';
|
import { ArrowRightIcon } from 'lucide-react';
|
||||||
|
|
||||||
import { CtaButton, Hero } from '@kit/ui/marketing';
|
import { CtaButton, Hero } from '@kit/ui/marketing';
|
||||||
@@ -32,7 +33,7 @@ function MainCallToActionButton() {
|
|||||||
return (
|
return (
|
||||||
<div className={'flex space-x-4'}>
|
<div className={'flex space-x-4'}>
|
||||||
<CtaButton>
|
<CtaButton>
|
||||||
<Link href={'/auth/sign-up'}>
|
<Link href={pathsConfig.auth.signUp}>
|
||||||
<span className={'flex items-center space-x-0.5'}>
|
<span className={'flex items-center space-x-0.5'}>
|
||||||
<span>
|
<span>
|
||||||
<Trans i18nKey={'common:getStarted'} />
|
<Trans i18nKey={'common:getStarted'} />
|
||||||
|
|||||||
21
app/api/email-template-test/route.ts
Normal file
21
app/api/email-template-test/route.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { sendEmail } from "~/lib/services/mailer.service";
|
||||||
|
|
||||||
|
export const GET = async () => {
|
||||||
|
const { renderInviteEmail } = await import('@kit/email-templates');
|
||||||
|
|
||||||
|
const html = await renderInviteEmail({
|
||||||
|
language: 'en',
|
||||||
|
teamName: 'Test Team',
|
||||||
|
invitedUserEmail: 'test@example.com',
|
||||||
|
productName: 'Test Product',
|
||||||
|
teamLogo: 'https://placehold.co/100x100',
|
||||||
|
inviter: 'John Doe',
|
||||||
|
link: 'https://www.google.com',
|
||||||
|
});
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
html,
|
||||||
|
length: html.html.length,
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -2,10 +2,10 @@ 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 { createAnalysisGroup, getAnalysisGroups } from '~/lib/services/analysis-group.service';
|
||||||
import { IMedipostPublicMessageDataParsed } from '~/lib/services/medipost.types';
|
import { IMedipostPublicMessageDataParsed, IUuringElement } from '~/lib/services/medipost.types';
|
||||||
import { createAnalysis, createNoDataReceivedEntry, createNoNewDataReceivedEntry, createSyncFailEntry, createSyncSuccessEntry } from '~/lib/services/analyses.service';
|
import { createAnalysis, createNoDataReceivedEntry, createNoNewDataReceivedEntry, createSyncFailEntry, createSyncSuccessEntry } from '~/lib/services/analyses.service';
|
||||||
import { getLastCheckedDate } from '~/lib/services/sync-entries.service';
|
import { getLastCheckedDate } from '~/lib/services/sync-entries.service';
|
||||||
import { createAnalysisElement } from '~/lib/services/analysis-element.service';
|
import { createAnalysisElement, getAnalysisElements } from '~/lib/services/analysis-element.service';
|
||||||
import { createCodes } from '~/lib/services/codes.service';
|
import { createCodes } from '~/lib/services/codes.service';
|
||||||
import { getLatestPublicMessageListItem } from '~/lib/services/medipost.service';
|
import { getLatestPublicMessageListItem } from '~/lib/services/medipost.service';
|
||||||
import type { ICode } from '~/lib/types/code';
|
import type { ICode } from '~/lib/types/code';
|
||||||
@@ -80,81 +80,92 @@ export default async function syncAnalysisGroups() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const codes: ICode[] = [];
|
const codes: ICode[] = [];
|
||||||
|
const analysesToCreate: { analysisGroupId: number, analyses: IUuringElement[], analysisElementId: number }[] = [];
|
||||||
for (const analysisGroup of analysisGroups) {
|
for (const analysisGroup of analysisGroups) {
|
||||||
|
let analysisGroupId: number | undefined;
|
||||||
const existingAnalysisGroup = existingAnalysisGroups?.find(({ original_id }) => original_id === analysisGroup.UuringuGruppId);
|
const existingAnalysisGroup = existingAnalysisGroups?.find(({ original_id }) => original_id === analysisGroup.UuringuGruppId);
|
||||||
if (existingAnalysisGroup) {
|
if (existingAnalysisGroup) {
|
||||||
console.info(`Analysis group '${analysisGroup.UuringuGruppNimi}' already exists`);
|
console.info(`Analysis group '${analysisGroup.UuringuGruppNimi}' already exists`);
|
||||||
continue;
|
analysisGroupId = existingAnalysisGroup.id;
|
||||||
|
} else {
|
||||||
|
// SAVE ANALYSIS GROUP
|
||||||
|
analysisGroupId = await createAnalysisGroup({
|
||||||
|
id: analysisGroup.UuringuGruppId,
|
||||||
|
name: analysisGroup.UuringuGruppNimi,
|
||||||
|
order: analysisGroup.UuringuGruppJarjekord,
|
||||||
|
});
|
||||||
|
|
||||||
|
const analysisGroupCodes = toArray(analysisGroup.Kood);
|
||||||
|
codes.push(
|
||||||
|
...analysisGroupCodes.map((kood) => ({
|
||||||
|
hk_code: kood.HkKood,
|
||||||
|
hk_code_multiplier: kood.HkKoodiKordaja,
|
||||||
|
coefficient: kood.Koefitsient,
|
||||||
|
price: kood.Hind,
|
||||||
|
analysis_group_id: analysisGroupId!,
|
||||||
|
analysis_element_id: null,
|
||||||
|
analysis_id: null,
|
||||||
|
})),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SAVE ANALYSIS GROUP
|
|
||||||
const analysisGroupId = await createAnalysisGroup({
|
|
||||||
id: analysisGroup.UuringuGruppId,
|
|
||||||
name: analysisGroup.UuringuGruppNimi,
|
|
||||||
order: analysisGroup.UuringuGruppJarjekord,
|
|
||||||
});
|
|
||||||
|
|
||||||
const analysisGroupCodes = toArray(analysisGroup.Kood);
|
|
||||||
codes.push(
|
|
||||||
...analysisGroupCodes.map((kood) => ({
|
|
||||||
hk_code: kood.HkKood,
|
|
||||||
hk_code_multiplier: kood.HkKoodiKordaja,
|
|
||||||
coefficient: kood.Koefitsient,
|
|
||||||
price: kood.Hind,
|
|
||||||
analysis_group_id: analysisGroupId,
|
|
||||||
analysis_element_id: null,
|
|
||||||
analysis_id: null,
|
|
||||||
})),
|
|
||||||
);
|
|
||||||
|
|
||||||
const analysisGroupItems = toArray(analysisGroup.Uuring);
|
const analysisGroupItems = toArray(analysisGroup.Uuring);
|
||||||
|
|
||||||
for (const item of analysisGroupItems) {
|
for (const item of analysisGroupItems) {
|
||||||
const analysisElement = item.UuringuElement;
|
const analysisElement = item.UuringuElement;
|
||||||
|
|
||||||
const insertedAnalysisElementId = await createAnalysisElement({
|
let insertedAnalysisElementId: number | undefined;
|
||||||
analysisElement,
|
const existingAnalysisElement = (await getAnalysisElements({ originalIds: [analysisElement.UuringId] }))?.[0];
|
||||||
analysisGroupId,
|
if (existingAnalysisElement) {
|
||||||
materialGroups: toArray(item.MaterjalideGrupp),
|
console.info(`Analysis element '${analysisElement.UuringNimi}' already exists`);
|
||||||
});
|
insertedAnalysisElementId = existingAnalysisElement.id;
|
||||||
|
} else {
|
||||||
|
insertedAnalysisElementId = await createAnalysisElement({
|
||||||
|
analysisElement,
|
||||||
|
analysisGroupId: analysisGroupId!,
|
||||||
|
materialGroups: toArray(item.MaterjalideGrupp),
|
||||||
|
});
|
||||||
|
if (analysisElement.Kood) {
|
||||||
|
const analysisElementCodes = toArray(analysisElement.Kood);
|
||||||
|
codes.push(
|
||||||
|
...analysisElementCodes.map((kood) => ({
|
||||||
|
hk_code: kood.HkKood,
|
||||||
|
hk_code_multiplier: kood.HkKoodiKordaja,
|
||||||
|
coefficient: kood.Koefitsient,
|
||||||
|
price: kood.Hind,
|
||||||
|
analysis_group_id: null,
|
||||||
|
analysis_element_id: insertedAnalysisElementId!,
|
||||||
|
analysis_id: null,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const analyses = toArray(analysisElement.UuringuElement);
|
||||||
|
if (analyses?.length && insertedAnalysisElementId) {
|
||||||
|
analysesToCreate.push({ analysisGroupId: analysisGroupId!, analyses, analysisElementId: insertedAnalysisElementId });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const { analysisGroupId, analyses, analysisElementId } of analysesToCreate) {
|
||||||
|
for (const analysis of analyses) {
|
||||||
|
const insertedAnalysisId = await createAnalysis(analysis, analysisElementId);
|
||||||
|
if (analysis.Kood) {
|
||||||
|
const analysisCodes = toArray(analysis.Kood);
|
||||||
|
|
||||||
if (analysisElement.Kood) {
|
|
||||||
const analysisElementCodes = toArray(analysisElement.Kood);
|
|
||||||
codes.push(
|
codes.push(
|
||||||
...analysisElementCodes.map((kood) => ({
|
...analysisCodes.map((kood) => ({
|
||||||
hk_code: kood.HkKood,
|
hk_code: kood.HkKood,
|
||||||
hk_code_multiplier: kood.HkKoodiKordaja,
|
hk_code_multiplier: kood.HkKoodiKordaja,
|
||||||
coefficient: kood.Koefitsient,
|
coefficient: kood.Koefitsient,
|
||||||
price: kood.Hind,
|
price: kood.Hind,
|
||||||
analysis_group_id: null,
|
analysis_group_id: null,
|
||||||
analysis_element_id: insertedAnalysisElementId,
|
analysis_element_id: null,
|
||||||
analysis_id: null,
|
analysis_id: insertedAnalysisId,
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const analyses = analysisElement.UuringuElement;
|
|
||||||
if (analyses?.length) {
|
|
||||||
for (const analysis of analyses) {
|
|
||||||
const insertedAnalysisId = await createAnalysis(analysis, analysisGroupId);
|
|
||||||
|
|
||||||
if (analysis.Kood) {
|
|
||||||
const analysisCodes = toArray(analysis.Kood);
|
|
||||||
|
|
||||||
codes.push(
|
|
||||||
...analysisCodes.map((kood) => ({
|
|
||||||
hk_code: kood.HkKood,
|
|
||||||
hk_code_multiplier: kood.HkKoodiKordaja,
|
|
||||||
coefficient: kood.Koefitsient,
|
|
||||||
price: kood.Hind,
|
|
||||||
analysis_group_id: null,
|
|
||||||
analysis_element_id: null,
|
|
||||||
analysis_id: insertedAnalysisId,
|
|
||||||
})),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
import loadEnv from "../handler/load-env";
|
import loadEnv from "../handler/load-env";
|
||||||
import validateApiKey from "../handler/validate-api-key";
|
import validateApiKey from "../handler/validate-api-key";
|
||||||
import { getOrderedAnalysisElementsIds, sendOrderToMedipost } from "~/lib/services/medipost.service";
|
import { getOrderedAnalysisIds, sendOrderToMedipost } from "~/lib/services/medipost.service";
|
||||||
import { retrieveOrder } from "@lib/data/orders";
|
import { retrieveOrder } from "@lib/data/orders";
|
||||||
import { getMedipostDispatchTries } from "~/lib/services/audit.service";
|
import { getMedipostDispatchTries } from "~/lib/services/audit.service";
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ export const POST = async (request: NextRequest) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const medusaOrder = await retrieveOrder(medusaOrderId);
|
const medusaOrder = await retrieveOrder(medusaOrderId);
|
||||||
const orderedAnalysisElements = await getOrderedAnalysisElementsIds({ 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({
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ export const POST = async (request: NextRequest) => {
|
|||||||
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',
|
message: 'Failed to sync analysis groups',
|
||||||
|
error: e instanceof Error ? JSON.stringify(e, undefined, 2) : 'Unknown error',
|
||||||
}, { status: 500 });
|
}, { status: 500 });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { getAnalysisOrdersAdmin } from "~/lib/services/order.service";
|
|||||||
import { composeOrderTestResponseXML, sendPrivateMessageTestResponse } from "~/lib/services/medipostTest.service";
|
import { composeOrderTestResponseXML, sendPrivateMessageTestResponse } from "~/lib/services/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 { getOrderedAnalysisElementsIds } from "~/lib/services/medipost.service";
|
import { getOrderedAnalysisIds } from "~/lib/services/medipost.service";
|
||||||
import loadEnv from "../handler/load-env";
|
import loadEnv from "../handler/load-env";
|
||||||
import validateApiKey from "../handler/validate-api-key";
|
import validateApiKey from "../handler/validate-api-key";
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ export async function POST(request: NextRequest) {
|
|||||||
const medusaOrder = await retrieveOrder(medusaOrderId)
|
const medusaOrder = await retrieveOrder(medusaOrderId)
|
||||||
|
|
||||||
const account = await getAccountAdmin({ primaryOwnerUserId: medreportOrder.user_id });
|
const account = await getAccountAdmin({ primaryOwnerUserId: medreportOrder.user_id });
|
||||||
const orderedAnalysisElementsIds = await getOrderedAnalysisElementsIds({ medusaOrder });
|
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;
|
||||||
@@ -35,8 +35,8 @@ 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),
|
orderedAnalysisElementsIds: idsToSend.map(({ analysisElementId }) => analysisElementId).filter(Boolean) as number[],
|
||||||
orderedAnalysesIds: [],
|
orderedAnalysesIds: idsToSend.map(({ analysisId }) => analysisId).filter(Boolean) as number[],
|
||||||
orderId: medusaOrderId,
|
orderId: medusaOrderId,
|
||||||
orderCreatedAt: new Date(medreportOrder.created_at),
|
orderCreatedAt: new Date(medreportOrder.created_at),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { getOrder } from "~/lib/services/order.service";
|
|||||||
import { composeOrderTestResponseXML, sendPrivateMessageTestResponse } from "~/lib/services/medipostTest.service";
|
import { composeOrderTestResponseXML, sendPrivateMessageTestResponse } from "~/lib/services/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 { createMedipostActionLog, getOrderedAnalysisElementsIds } from "~/lib/services/medipost.service";
|
import { createMedipostActionLog, getOrderedAnalysisIds } from "~/lib/services/medipost.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';
|
||||||
@@ -11,16 +11,15 @@ export async function POST(request: Request) {
|
|||||||
// return NextResponse.json({ error: 'This endpoint is only available in development mode' }, { status: 403 });
|
// return NextResponse.json({ error: 'This endpoint is only available in development mode' }, { status: 403 });
|
||||||
// }
|
// }
|
||||||
|
|
||||||
const { medusaOrderId, maxItems = null } = await request.json();
|
const { medusaOrderId } = await request.json();
|
||||||
|
|
||||||
const medusaOrder = await retrieveOrder(medusaOrderId)
|
const medusaOrder = await retrieveOrder(medusaOrderId)
|
||||||
const medreportOrder = await getOrder({ medusaOrderId });
|
const medreportOrder = await getOrder({ medusaOrderId });
|
||||||
|
|
||||||
const account = await getAccountAdmin({ primaryOwnerUserId: medreportOrder.user_id });
|
const account = await getAccountAdmin({ primaryOwnerUserId: medreportOrder.user_id });
|
||||||
const orderedAnalysisElementsIds = await getOrderedAnalysisElementsIds({ medusaOrder });
|
const orderedAnalysisElementsIds = await getOrderedAnalysisIds({ medusaOrder });
|
||||||
|
|
||||||
console.info(`Sending test response for order=${medusaOrderId} with ${orderedAnalysisElementsIds.length} (${maxItems ?? 'all'}) ordered analysis elements`);
|
console.info(`Sending test response for order=${medusaOrderId} with ${orderedAnalysisElementsIds.length} ordered analysis elements`);
|
||||||
const idsToSend = typeof maxItems === 'number' ? orderedAnalysisElementsIds.slice(0, maxItems) : orderedAnalysisElementsIds;
|
|
||||||
const messageXml = await composeOrderTestResponseXML({
|
const messageXml = await composeOrderTestResponseXML({
|
||||||
person: {
|
person: {
|
||||||
idCode: account.personal_code!,
|
idCode: account.personal_code!,
|
||||||
@@ -28,8 +27,8 @@ export async function POST(request: Request) {
|
|||||||
lastName: account.last_name ?? '',
|
lastName: account.last_name ?? '',
|
||||||
phone: account.phone ?? '',
|
phone: account.phone ?? '',
|
||||||
},
|
},
|
||||||
orderedAnalysisElementsIds: idsToSend.map(({ analysisElementId }) => analysisElementId),
|
orderedAnalysisElementsIds: orderedAnalysisElementsIds.map(({ analysisElementId }) => analysisElementId).filter(Boolean) as number[],
|
||||||
orderedAnalysesIds: [],
|
orderedAnalysesIds: orderedAnalysisElementsIds.map(({ analysisId }) => analysisId).filter(Boolean) as number[],
|
||||||
orderId: medusaOrderId,
|
orderId: medusaOrderId,
|
||||||
orderCreatedAt: new Date(medreportOrder.created_at),
|
orderCreatedAt: new Date(medreportOrder.created_at),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,19 +1,62 @@
|
|||||||
import { redirect } from 'next/navigation';
|
import { redirect } from 'next/navigation';
|
||||||
import type { NextRequest } from 'next/server';
|
import type { NextRequest } from 'next/server';
|
||||||
|
|
||||||
import { createAuthCallbackService } from '@kit/supabase/auth';
|
import { createAuthCallbackService, getErrorURLParameters } from '@kit/supabase/auth';
|
||||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
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';
|
||||||
|
|
||||||
|
const ERROR_PATH = '/auth/callback/error';
|
||||||
|
|
||||||
|
const redirectOnError = (searchParams?: string) => {
|
||||||
|
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 error = searchParams.get('error');
|
||||||
|
if (error) {
|
||||||
|
const { searchParams } = getErrorURLParameters({ error });
|
||||||
|
return redirectOnError(searchParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
const authCode = searchParams.get('code');
|
||||||
|
if (!authCode) {
|
||||||
|
return redirectOnError();
|
||||||
|
}
|
||||||
|
|
||||||
|
let redirectPath = searchParams.get('next') || pathsConfig.app.home;
|
||||||
|
// if we have an invite token, we redirect to the join team page
|
||||||
|
// instead of the default next url. This is because the user is trying
|
||||||
|
// to join a team and we want to make sure they are redirected to the
|
||||||
|
// correct page.
|
||||||
|
const inviteToken = searchParams.get('invite_token');
|
||||||
|
if (inviteToken) {
|
||||||
|
const urlParams = new URLSearchParams({
|
||||||
|
invite_token: inviteToken,
|
||||||
|
email: searchParams.get('email') ?? '',
|
||||||
|
});
|
||||||
|
|
||||||
|
redirectPath = `${pathsConfig.app.joinTeam}?${urlParams.toString()}`;
|
||||||
|
}
|
||||||
|
|
||||||
const service = createAuthCallbackService(getSupabaseServerClient());
|
const service = createAuthCallbackService(getSupabaseServerClient());
|
||||||
|
const oauthResult = await service.exchangeCodeForSession(authCode);
|
||||||
|
if (!("isSuccess" in oauthResult)) {
|
||||||
|
return redirectOnError(oauthResult.searchParams);
|
||||||
|
}
|
||||||
|
|
||||||
const { nextPath } = await service.exchangeCodeForSession(request, {
|
const api = createAccountsApi(getSupabaseServerClient());
|
||||||
joinTeamPath: pathsConfig.app.joinTeam,
|
|
||||||
redirectPath: pathsConfig.app.home,
|
|
||||||
});
|
|
||||||
|
|
||||||
return redirect(nextPath);
|
const account = await api.getPersonalAccountByUserId(
|
||||||
|
oauthResult.user.id,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!account.email || !account.name || !account.last_name) {
|
||||||
|
return redirect(pathsConfig.auth.updateAccount);
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect(redirectPath);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
|||||||
|
|
||||||
import { pathsConfig } from '@kit/shared/config';
|
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());
|
||||||
|
|
||||||
|
|||||||
54
app/auth/sign-in/components/PasswordOption.tsx
Normal file
54
app/auth/sign-in/components/PasswordOption.tsx
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
import Link from 'next/link';
|
||||||
|
|
||||||
|
import { SignInMethodsContainer } from '@kit/auth/sign-in';
|
||||||
|
import { authConfig, pathsConfig } from '@kit/shared/config';
|
||||||
|
import { Button } from '@kit/ui/button';
|
||||||
|
import { Heading } from '@kit/ui/heading';
|
||||||
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
|
export default function PasswordOption({
|
||||||
|
inviteToken,
|
||||||
|
returnPath,
|
||||||
|
}: {
|
||||||
|
inviteToken?: string;
|
||||||
|
returnPath?: string;
|
||||||
|
}) {
|
||||||
|
const signUpPath =
|
||||||
|
pathsConfig.auth.signUp +
|
||||||
|
(inviteToken ? `?invite_token=${inviteToken}` : '');
|
||||||
|
|
||||||
|
const paths = {
|
||||||
|
callback: pathsConfig.auth.callback,
|
||||||
|
returnPath: returnPath ?? pathsConfig.app.home,
|
||||||
|
joinTeam: pathsConfig.app.joinTeam,
|
||||||
|
updateAccount: pathsConfig.auth.updateAccount,
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className={'flex flex-col items-center gap-1'}>
|
||||||
|
<Heading level={4} className={'tracking-tight'}>
|
||||||
|
<Trans i18nKey={'auth:signInHeading'} />
|
||||||
|
</Heading>
|
||||||
|
|
||||||
|
<p className={'text-muted-foreground text-sm'}>
|
||||||
|
<Trans i18nKey={'auth:signInSubheading'} />
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<SignInMethodsContainer
|
||||||
|
inviteToken={inviteToken}
|
||||||
|
paths={paths}
|
||||||
|
providers={authConfig.providers}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className={'flex justify-center'}>
|
||||||
|
<Button asChild variant={'link'} size={'sm'}>
|
||||||
|
<Link href={signUpPath} prefetch={true}>
|
||||||
|
<Trans i18nKey={'auth:doNotHaveAccountYet'} />
|
||||||
|
</Link>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
37
app/auth/sign-in/components/SignInPageClientRedirect.tsx
Normal file
37
app/auth/sign-in/components/SignInPageClientRedirect.tsx
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import Loading from '@/app/home/loading';
|
||||||
|
import { useEffect } from 'react';
|
||||||
|
import { getSupabaseBrowserClient } from '@/packages/supabase/src/clients/browser-client';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
|
||||||
|
export function SignInPageClientRedirect() {
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
async function signIn() {
|
||||||
|
const { data, error } = await getSupabaseBrowserClient()
|
||||||
|
.auth
|
||||||
|
.signInWithOAuth({
|
||||||
|
provider: 'keycloak',
|
||||||
|
options: {
|
||||||
|
redirectTo: `${window.location.origin}/auth/callback`,
|
||||||
|
queryParams: {
|
||||||
|
prompt: 'login',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
console.error('OAuth error', error);
|
||||||
|
router.push('/');
|
||||||
|
} else if (data.url) {
|
||||||
|
router.push(data.url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
signIn();
|
||||||
|
}, [router]);
|
||||||
|
|
||||||
|
return <Loading />;
|
||||||
|
}
|
||||||
@@ -1,14 +1,9 @@
|
|||||||
import Link from 'next/link';
|
import { pathsConfig, authConfig } from '@kit/shared/config';
|
||||||
|
|
||||||
|
|
||||||
import { SignInMethodsContainer } from '@kit/auth/sign-in';
|
|
||||||
import { authConfig, pathsConfig } from '@kit/shared/config';
|
|
||||||
import { Button } from '@kit/ui/button';
|
|
||||||
import { Heading } from '@kit/ui/heading';
|
|
||||||
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 { SignInPageClientRedirect } from './components/SignInPageClientRedirect';
|
||||||
|
import PasswordOption from './components/PasswordOption';
|
||||||
|
|
||||||
interface SignInPageProps {
|
interface SignInPageProps {
|
||||||
searchParams: Promise<{
|
searchParams: Promise<{
|
||||||
@@ -26,47 +21,14 @@ export const generateMetadata = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
async function SignInPage({ searchParams }: SignInPageProps) {
|
async function SignInPage({ searchParams }: SignInPageProps) {
|
||||||
const { invite_token: inviteToken, next = pathsConfig.app.home } =
|
const { invite_token: inviteToken, next: returnPath = pathsConfig.app.home } =
|
||||||
await searchParams;
|
await searchParams;
|
||||||
|
|
||||||
const signUpPath =
|
if (authConfig.providers.password) {
|
||||||
pathsConfig.auth.signUp +
|
return <PasswordOption inviteToken={inviteToken} returnPath={returnPath} />;
|
||||||
(inviteToken ? `?invite_token=${inviteToken}` : '');
|
}
|
||||||
|
|
||||||
const paths = {
|
return <SignInPageClientRedirect />;
|
||||||
callback: pathsConfig.auth.callback,
|
|
||||||
returnPath: next ?? pathsConfig.app.home,
|
|
||||||
joinTeam: pathsConfig.app.joinTeam,
|
|
||||||
updateAccount: pathsConfig.auth.updateAccount,
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<div className={'flex flex-col items-center gap-1'}>
|
|
||||||
<Heading level={4} className={'tracking-tight'}>
|
|
||||||
<Trans i18nKey={'auth:signInHeading'} />
|
|
||||||
</Heading>
|
|
||||||
|
|
||||||
<p className={'text-muted-foreground text-sm'}>
|
|
||||||
<Trans i18nKey={'auth:signInSubheading'} />
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<SignInMethodsContainer
|
|
||||||
inviteToken={inviteToken}
|
|
||||||
paths={paths}
|
|
||||||
providers={authConfig.providers}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div className={'flex justify-center'}>
|
|
||||||
<Button asChild variant={'link'} size={'sm'}>
|
|
||||||
<Link href={signUpPath} prefetch={true}>
|
|
||||||
<Trans i18nKey={'auth:doNotHaveAccountYet'} />
|
|
||||||
</Link>
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default withI18n(SignInPage);
|
export default withI18n(SignInPage);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
|
import { redirect } from 'next/navigation';
|
||||||
|
|
||||||
import { SignUpMethodsContainer } from '@kit/auth/sign-up';
|
import { SignUpMethodsContainer } from '@kit/auth/sign-up';
|
||||||
import { authConfig, pathsConfig } from '@kit/shared/config';
|
import { authConfig, pathsConfig } from '@kit/shared/config';
|
||||||
@@ -37,6 +38,10 @@ async function SignUpPage({ searchParams }: Props) {
|
|||||||
pathsConfig.auth.signIn +
|
pathsConfig.auth.signIn +
|
||||||
(inviteToken ? `?invite_token=${inviteToken}` : '');
|
(inviteToken ? `?invite_token=${inviteToken}` : '');
|
||||||
|
|
||||||
|
if (!authConfig.providers.password) {
|
||||||
|
return redirect('/');
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className={'flex flex-col items-center gap-1'}>
|
<div className={'flex flex-col items-center gap-1'}>
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
|
|
||||||
import { User } from '@supabase/supabase-js';
|
|
||||||
|
|
||||||
import { ExternalLink } from '@/public/assets/external-link';
|
import { ExternalLink } from '@/public/assets/external-link';
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { useForm } from 'react-hook-form';
|
import { useForm } from 'react-hook-form';
|
||||||
@@ -23,31 +21,52 @@ import { Trans } from '@kit/ui/trans';
|
|||||||
|
|
||||||
import { UpdateAccountSchema } from '../_lib/schemas/update-account.schema';
|
import { UpdateAccountSchema } from '../_lib/schemas/update-account.schema';
|
||||||
import { onUpdateAccount } from '../_lib/server/update-account';
|
import { onUpdateAccount } from '../_lib/server/update-account';
|
||||||
|
import { z } from 'zod';
|
||||||
|
|
||||||
export function UpdateAccountForm({ user }: { user: User }) {
|
type UpdateAccountFormValues = z.infer<typeof UpdateAccountSchema>;
|
||||||
|
|
||||||
|
export function UpdateAccountForm({
|
||||||
|
defaultValues,
|
||||||
|
}: {
|
||||||
|
defaultValues: UpdateAccountFormValues,
|
||||||
|
}) {
|
||||||
const form = useForm({
|
const form = useForm({
|
||||||
resolver: zodResolver(UpdateAccountSchema),
|
resolver: zodResolver(UpdateAccountSchema),
|
||||||
mode: 'onChange',
|
mode: 'onChange',
|
||||||
defaultValues: {
|
defaultValues,
|
||||||
firstName: '',
|
|
||||||
lastName: '',
|
|
||||||
personalCode: '',
|
|
||||||
email: user.email,
|
|
||||||
phone: '',
|
|
||||||
city: '',
|
|
||||||
weight: 0,
|
|
||||||
height: 0,
|
|
||||||
userConsent: false,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { firstName, lastName, personalCode, email, weight, height, userConsent } = defaultValues;
|
||||||
|
|
||||||
|
const hasFirstName = !!firstName;
|
||||||
|
const hasLastName = !!lastName;
|
||||||
|
const hasPersonalCode = !!personalCode;
|
||||||
|
const hasEmail = !!email;
|
||||||
|
const hasWeight = !!weight;
|
||||||
|
const hasHeight = !!height;
|
||||||
|
const hasUserConsent = !!userConsent;
|
||||||
|
|
||||||
|
const onUpdateAccountOptions = async (values: UpdateAccountFormValues) =>
|
||||||
|
onUpdateAccount({
|
||||||
|
...values,
|
||||||
|
...(hasFirstName && { firstName }),
|
||||||
|
...(hasLastName && { lastName }),
|
||||||
|
...(hasPersonalCode && { personalCode }),
|
||||||
|
...(hasEmail && { email }),
|
||||||
|
...(hasWeight && { weight: values.weight ?? weight }),
|
||||||
|
...(hasHeight && { height: values.height ?? height }),
|
||||||
|
...(hasUserConsent && { userConsent: values.userConsent ?? userConsent }),
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form
|
<form
|
||||||
className="flex flex-col gap-6 px-6 pt-10 text-left"
|
className="flex flex-col gap-6 px-6 pt-10 text-left"
|
||||||
onSubmit={form.handleSubmit(onUpdateAccount)}
|
onSubmit={form.handleSubmit(onUpdateAccountOptions)}
|
||||||
>
|
>
|
||||||
<FormField
|
<FormField
|
||||||
name="firstName"
|
name="firstName"
|
||||||
|
disabled={hasFirstName}
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>
|
<FormLabel>
|
||||||
@@ -63,6 +82,7 @@ export function UpdateAccountForm({ user }: { user: User }) {
|
|||||||
|
|
||||||
<FormField
|
<FormField
|
||||||
name="lastName"
|
name="lastName"
|
||||||
|
disabled={hasLastName}
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>
|
<FormLabel>
|
||||||
@@ -78,6 +98,7 @@ export function UpdateAccountForm({ user }: { user: User }) {
|
|||||||
|
|
||||||
<FormField
|
<FormField
|
||||||
name="personalCode"
|
name="personalCode"
|
||||||
|
disabled={hasPersonalCode}
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>
|
<FormLabel>
|
||||||
@@ -93,13 +114,14 @@ export function UpdateAccountForm({ user }: { user: User }) {
|
|||||||
|
|
||||||
<FormField
|
<FormField
|
||||||
name="email"
|
name="email"
|
||||||
|
disabled={hasEmail}
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>
|
<FormLabel>
|
||||||
<Trans i18nKey={'common:formField:email'} />
|
<Trans i18nKey={'common:formField:email'} />
|
||||||
</FormLabel>
|
</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input {...field} disabled />
|
<Input {...field} />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
|||||||
@@ -1,19 +1,20 @@
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
import parsePhoneNumber from 'libphonenumber-js/min';
|
||||||
|
|
||||||
export const UpdateAccountSchema = z.object({
|
export const UpdateAccountSchema = z.object({
|
||||||
firstName: z
|
firstName: z
|
||||||
.string({
|
.string({
|
||||||
required_error: 'First name is required',
|
error: 'First name is required',
|
||||||
})
|
})
|
||||||
.nonempty(),
|
.nonempty(),
|
||||||
lastName: z
|
lastName: z
|
||||||
.string({
|
.string({
|
||||||
required_error: 'Last name is required',
|
error: 'Last name is required',
|
||||||
})
|
})
|
||||||
.nonempty(),
|
.nonempty(),
|
||||||
personalCode: z
|
personalCode: z
|
||||||
.string({
|
.string({
|
||||||
required_error: 'Personal code is required',
|
error: 'Personal code is required',
|
||||||
})
|
})
|
||||||
.nonempty(),
|
.nonempty(),
|
||||||
email: z.string().email({
|
email: z.string().email({
|
||||||
@@ -21,21 +22,38 @@ export const UpdateAccountSchema = z.object({
|
|||||||
}),
|
}),
|
||||||
phone: z
|
phone: z
|
||||||
.string({
|
.string({
|
||||||
required_error: 'Phone number is required',
|
error: 'Phone number is required',
|
||||||
})
|
})
|
||||||
.nonempty(),
|
.nonempty()
|
||||||
|
.refine(
|
||||||
|
(phone) => {
|
||||||
|
try {
|
||||||
|
const phoneNumber = parsePhoneNumber(phone);
|
||||||
|
return !!phoneNumber && phoneNumber.isValid() && phoneNumber.country === 'EE';
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
message: 'common:formFieldError.invalidPhoneNumber',
|
||||||
|
}
|
||||||
|
),
|
||||||
city: z.string().optional(),
|
city: z.string().optional(),
|
||||||
weight: z
|
weight: z
|
||||||
.number({
|
.number({
|
||||||
required_error: 'Weight is required',
|
error: (issue) =>
|
||||||
invalid_type_error: 'Weight must be a number',
|
issue.input === undefined
|
||||||
|
? 'Weight is required'
|
||||||
|
: 'Weight must be a number',
|
||||||
})
|
})
|
||||||
.gt(0, { message: 'Weight must be greater than 0' }),
|
.gt(0, { message: 'Weight must be greater than 0' }),
|
||||||
|
|
||||||
height: z
|
height: z
|
||||||
.number({
|
.number({
|
||||||
required_error: 'Height is required',
|
error: (issue) =>
|
||||||
invalid_type_error: 'Height must be a number',
|
issue.input === undefined
|
||||||
|
? 'Height is required'
|
||||||
|
: 'Height must be a number',
|
||||||
})
|
})
|
||||||
.gt(0, { message: 'Height must be greater than 0' }),
|
.gt(0, { message: 'Height must be greater than 0' }),
|
||||||
userConsent: z.boolean().refine((val) => val === true, {
|
userConsent: z.boolean().refine((val) => val === true, {
|
||||||
|
|||||||
@@ -28,11 +28,15 @@ export const onUpdateAccount = enhanceAction(
|
|||||||
console.warn('On update account error: ', err);
|
console.warn('On update account error: ', err);
|
||||||
}
|
}
|
||||||
|
|
||||||
await updateCustomer({
|
try {
|
||||||
first_name: params.firstName,
|
await updateCustomer({
|
||||||
last_name: params.lastName,
|
first_name: params.firstName,
|
||||||
phone: params.phone,
|
last_name: params.lastName,
|
||||||
});
|
phone: params.phone,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Failed to update Medusa customer", e);
|
||||||
|
}
|
||||||
|
|
||||||
const hasUnseenMembershipConfirmation =
|
const hasUnseenMembershipConfirmation =
|
||||||
await api.hasUnseenMembershipConfirmation();
|
await api.hasUnseenMembershipConfirmation();
|
||||||
|
|||||||
@@ -11,18 +11,39 @@ import { Trans } from '@kit/ui/trans';
|
|||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
|
|
||||||
import { UpdateAccountForm } from './_components/update-account-form';
|
import { UpdateAccountForm } from './_components/update-account-form';
|
||||||
|
import { loadCurrentUserAccount } from '@/app/home/(user)/_lib/server/load-user-account';
|
||||||
|
import { toTitleCase } from '~/lib/utils';
|
||||||
|
|
||||||
async function UpdateAccount() {
|
async function UpdateAccount() {
|
||||||
const client = getSupabaseServerClient();
|
const client = getSupabaseServerClient();
|
||||||
|
const account = await loadCurrentUserAccount();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: { user },
|
data: { user },
|
||||||
} = await client.auth.getUser();
|
} = await client.auth.getUser();
|
||||||
|
const isKeycloakUser = user?.app_metadata?.provider === 'keycloak';
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
redirect(pathsConfig.auth.signIn);
|
redirect(pathsConfig.auth.signIn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const defaultValues = {
|
||||||
|
firstName: account?.name ? toTitleCase(account.name) : '',
|
||||||
|
lastName: account?.last_name ? toTitleCase(account.last_name) : '',
|
||||||
|
personalCode: account?.personal_code ?? '',
|
||||||
|
email: (() => {
|
||||||
|
if (isKeycloakUser) {
|
||||||
|
return account?.email ?? '';
|
||||||
|
}
|
||||||
|
return account?.email ?? user?.email ?? '';
|
||||||
|
})(),
|
||||||
|
phone: account?.phone ?? '',
|
||||||
|
city: account?.city ?? '',
|
||||||
|
weight: account?.accountParams?.weight ?? 0,
|
||||||
|
height: account?.accountParams?.height ?? 0,
|
||||||
|
userConsent: account?.has_consent_personal_data ?? false,
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="border-border flex max-w-5xl flex-row overflow-hidden rounded-3xl border">
|
<div className="border-border flex max-w-5xl flex-row overflow-hidden rounded-3xl border">
|
||||||
<div className="relative flex min-w-md flex-col px-12 pt-7 pb-22 text-center md:w-1/2">
|
<div className="relative flex min-w-md flex-col px-12 pt-7 pb-22 text-center md:w-1/2">
|
||||||
@@ -34,7 +55,7 @@ async function UpdateAccount() {
|
|||||||
<p className="text-muted-foreground pt-1 text-sm">
|
<p className="text-muted-foreground pt-1 text-sm">
|
||||||
<Trans i18nKey={'account:updateAccount:description'} />
|
<Trans i18nKey={'account:updateAccount:description'} />
|
||||||
</p>
|
</p>
|
||||||
<UpdateAccountForm user={user} />
|
<UpdateAccountForm defaultValues={defaultValues} />
|
||||||
</div>
|
</div>
|
||||||
<div className="hidden w-1/2 min-w-[460px] bg-[url(/assets/med-report-logo-big.png)] bg-cover bg-center bg-no-repeat md:block"></div>
|
<div className="hidden w-1/2 min-w-[460px] bg-[url(/assets/med-report-logo-big.png)] bg-cover bg-center bg-no-repeat md:block"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { listProductTypes } from "@lib/data/products";
|
|||||||
import { placeOrder, retrieveCart } from "@lib/data/cart";
|
import { placeOrder, retrieveCart } from "@lib/data/cart";
|
||||||
import { createI18nServerInstance } from "~/lib/i18n/i18n.server";
|
import { createI18nServerInstance } from "~/lib/i18n/i18n.server";
|
||||||
import { createOrder } from '~/lib/services/order.service';
|
import { createOrder } from '~/lib/services/order.service';
|
||||||
import { getOrderedAnalysisElementsIds, sendOrderToMedipost } from '~/lib/services/medipost.service';
|
import { getOrderedAnalysisIds, sendOrderToMedipost } from '~/lib/services/medipost.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 { AccountWithParams } from '@kit/accounts/api';
|
import { AccountWithParams } from '@kit/accounts/api';
|
||||||
@@ -20,12 +20,12 @@ const env = () => z
|
|||||||
.object({
|
.object({
|
||||||
emailSender: z
|
emailSender: z
|
||||||
.string({
|
.string({
|
||||||
required_error: 'EMAIL_SENDER is required',
|
error: 'EMAIL_SENDER is required',
|
||||||
})
|
})
|
||||||
.min(1),
|
.min(1),
|
||||||
siteUrl: z
|
siteUrl: z
|
||||||
.string({
|
.string({
|
||||||
required_error: 'NEXT_PUBLIC_SITE_URL is required',
|
error: 'NEXT_PUBLIC_SITE_URL is required',
|
||||||
})
|
})
|
||||||
.min(1),
|
.min(1),
|
||||||
})
|
})
|
||||||
@@ -114,7 +114,7 @@ export async function processMontonioCallback(orderToken: string) {
|
|||||||
|
|
||||||
|
|
||||||
const medusaOrder = await placeOrder(cartId, { revalidateCacheTags: false });
|
const medusaOrder = await placeOrder(cartId, { revalidateCacheTags: false });
|
||||||
const orderedAnalysisElements = await getOrderedAnalysisElementsIds({ medusaOrder });
|
const orderedAnalysisElements = await getOrderedAnalysisIds({ medusaOrder });
|
||||||
const orderId = await createOrder({ medusaOrder, orderedAnalysisElements });
|
const orderId = await createOrder({ medusaOrder, orderedAnalysisElements });
|
||||||
|
|
||||||
const { productTypes } = await listProductTypes();
|
const { productTypes } = await listProductTypes();
|
||||||
|
|||||||
@@ -1,17 +1,11 @@
|
|||||||
import { use } from 'react';
|
import { use } from 'react';
|
||||||
|
|
||||||
import { cookies } from 'next/headers';
|
|
||||||
|
|
||||||
import { retrieveCart } from '@lib/data/cart';
|
import { retrieveCart } from '@lib/data/cart';
|
||||||
import { StoreCart } from '@medusajs/types';
|
import { StoreCart } from '@medusajs/types';
|
||||||
import { z } from 'zod';
|
|
||||||
|
|
||||||
import { UserWorkspaceContextProvider } from '@kit/accounts/components';
|
import { UserWorkspaceContextProvider } from '@kit/accounts/components';
|
||||||
import { AppLogo } from '@kit/shared/components/app-logo';
|
import { AppLogo } from '@kit/shared/components/app-logo';
|
||||||
import {
|
import { pathsConfig } from '@kit/shared/config';
|
||||||
pathsConfig,
|
|
||||||
personalAccountNavigationConfig,
|
|
||||||
} from '@kit/shared/config';
|
|
||||||
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';
|
||||||
|
|
||||||
@@ -24,40 +18,11 @@ import { HomeSidebar } from '../_components/home-sidebar';
|
|||||||
import { loadUserWorkspace } from '../_lib/server/load-user-workspace';
|
import { loadUserWorkspace } from '../_lib/server/load-user-workspace';
|
||||||
|
|
||||||
function UserHomeLayout({ children }: React.PropsWithChildren) {
|
function UserHomeLayout({ children }: React.PropsWithChildren) {
|
||||||
const state = use(getLayoutState());
|
|
||||||
|
|
||||||
if (state.style === 'sidebar') {
|
|
||||||
return <SidebarLayout>{children}</SidebarLayout>;
|
|
||||||
}
|
|
||||||
|
|
||||||
return <HeaderLayout>{children}</HeaderLayout>;
|
return <HeaderLayout>{children}</HeaderLayout>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default withI18n(UserHomeLayout);
|
export default withI18n(UserHomeLayout);
|
||||||
|
|
||||||
function SidebarLayout({ children }: React.PropsWithChildren) {
|
|
||||||
const workspace = use(loadUserWorkspace());
|
|
||||||
const state = use(getLayoutState());
|
|
||||||
|
|
||||||
return (
|
|
||||||
<UserWorkspaceContextProvider value={workspace}>
|
|
||||||
<SidebarProvider defaultOpen={state.open}>
|
|
||||||
<Page style={'sidebar'}>
|
|
||||||
<PageNavigation>
|
|
||||||
<HomeSidebar />
|
|
||||||
</PageNavigation>
|
|
||||||
|
|
||||||
<PageMobileNavigation className={'flex items-center justify-between'}>
|
|
||||||
<MobileNavigation workspace={workspace} cart={null} />
|
|
||||||
</PageMobileNavigation>
|
|
||||||
|
|
||||||
{children}
|
|
||||||
</Page>
|
|
||||||
</SidebarProvider>
|
|
||||||
</UserWorkspaceContextProvider>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function HeaderLayout({ children }: React.PropsWithChildren) {
|
function HeaderLayout({ children }: React.PropsWithChildren) {
|
||||||
const workspace = use(loadUserWorkspace());
|
const workspace = use(loadUserWorkspace());
|
||||||
const cart = use(retrieveCart());
|
const cart = use(retrieveCart());
|
||||||
@@ -101,27 +66,3 @@ function MobileNavigation({
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getLayoutState() {
|
|
||||||
const cookieStore = await cookies();
|
|
||||||
|
|
||||||
const LayoutStyleSchema = z.enum(['sidebar', 'header', 'custom']);
|
|
||||||
|
|
||||||
const layoutStyleCookie = cookieStore.get('layout-style');
|
|
||||||
const sidebarOpenCookie = cookieStore.get('sidebar:state');
|
|
||||||
|
|
||||||
const sidebarOpen = sidebarOpenCookie
|
|
||||||
? sidebarOpenCookie.value === 'false'
|
|
||||||
: !personalAccountNavigationConfig.sidebarCollapsed;
|
|
||||||
|
|
||||||
const parsedStyle = LayoutStyleSchema.safeParse(layoutStyleCookie?.value);
|
|
||||||
|
|
||||||
const style = parsedStyle.success
|
|
||||||
? parsedStyle.data
|
|
||||||
: personalAccountNavigationConfig.style;
|
|
||||||
|
|
||||||
return {
|
|
||||||
open: sidebarOpen,
|
|
||||||
style,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ async function UserHomePage() {
|
|||||||
const client = getSupabaseServerClient();
|
const client = getSupabaseServerClient();
|
||||||
|
|
||||||
const account = await loadCurrentUserAccount();
|
const account = await loadCurrentUserAccount();
|
||||||
const api = await createAccountsApi(client);
|
const api = createAccountsApi(client);
|
||||||
const bmiThresholds = await api.fetchBmiThresholds();
|
const bmiThresholds = await api.fetchBmiThresholds();
|
||||||
|
|
||||||
if (!account) {
|
if (!account) {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import { formatCurrency } from "@/packages/shared/src/utils";
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { handleNavigateToPayment } from "@/lib/services/medusaCart.service";
|
import { handleNavigateToPayment } from "@/lib/services/medusaCart.service";
|
||||||
import AnalysisLocation from "./analysis-location";
|
import AnalysisLocation from "./analysis-location";
|
||||||
|
import { composeOrderXML, getOrderedAnalysisIds } from "~/lib/services/medipost.service";
|
||||||
|
|
||||||
const IS_DISCOUNT_SHOWN = false as boolean;
|
const IS_DISCOUNT_SHOWN = false as boolean;
|
||||||
|
|
||||||
@@ -133,6 +134,26 @@ export default function Cart({
|
|||||||
<Trans i18nKey="cart:checkout.goToCheckout" />
|
<Trans i18nKey="cart:checkout.goToCheckout" />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<Button type='button' onClick={async () => {
|
||||||
|
const orderedAnalysisElementsIds = await getOrderedAnalysisIds({ medusaOrder: { items: cart.items ?? [] } });
|
||||||
|
const xml = await composeOrderXML({
|
||||||
|
person: {
|
||||||
|
idCode: '1234567890',
|
||||||
|
firstName: 'John',
|
||||||
|
lastName: 'Doe',
|
||||||
|
phone: '1234567890',
|
||||||
|
},
|
||||||
|
orderedAnalysisElementsIds: orderedAnalysisElementsIds.map(({ analysisElementId }) => analysisElementId).filter(Boolean) as number[],
|
||||||
|
orderedAnalysesIds: orderedAnalysisElementsIds.map(({ analysisId }) => analysisId).filter(Boolean) as number[],
|
||||||
|
orderId: '1234567890',
|
||||||
|
orderCreatedAt: new Date(),
|
||||||
|
});
|
||||||
|
console.log('test', { items: cart.items, ids: orderedAnalysisElementsIds, xml });
|
||||||
|
console.log('test', xml);
|
||||||
|
}}>
|
||||||
|
Test
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
128
app/home/(user)/_components/dashboard-recommendations.tsx
Normal file
128
app/home/(user)/_components/dashboard-recommendations.tsx
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import Link from 'next/link';
|
||||||
|
|
||||||
|
import { BlendingModeIcon } from '@radix-ui/react-icons';
|
||||||
|
import {
|
||||||
|
Droplets,
|
||||||
|
} from 'lucide-react';
|
||||||
|
|
||||||
|
import { InfoTooltip } from '@kit/shared/components/ui/info-tooltip';
|
||||||
|
import { Button } from '@kit/ui/button';
|
||||||
|
import {
|
||||||
|
Card,
|
||||||
|
CardContent,
|
||||||
|
CardHeader,
|
||||||
|
} from '@kit/ui/card';
|
||||||
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
import { cn } from '@kit/ui/utils';
|
||||||
|
|
||||||
|
const dummyRecommendations = [
|
||||||
|
{
|
||||||
|
icon: <BlendingModeIcon className="size-4" />,
|
||||||
|
color: 'bg-cyan/10 text-cyan',
|
||||||
|
title: 'Kolesterooli kontroll',
|
||||||
|
description: 'HDL-kolestrool',
|
||||||
|
tooltipContent: 'Selgitus',
|
||||||
|
price: '20,00 €',
|
||||||
|
buttonText: 'Telli',
|
||||||
|
href: '/home/booking',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: <BlendingModeIcon className="size-4" />,
|
||||||
|
color: 'bg-primary/10 text-primary',
|
||||||
|
title: 'Kolesterooli kontroll',
|
||||||
|
tooltipContent: 'Selgitus',
|
||||||
|
description: 'LDL-Kolesterool',
|
||||||
|
buttonText: 'Broneeri',
|
||||||
|
href: '/home/booking',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: <Droplets />,
|
||||||
|
color: 'bg-destructive/10 text-destructive',
|
||||||
|
title: 'Vererõhu kontroll',
|
||||||
|
tooltipContent: 'Selgitus',
|
||||||
|
description: 'Score-Risk 2',
|
||||||
|
price: '20,00 €',
|
||||||
|
buttonText: 'Telli',
|
||||||
|
href: '/home/booking',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export default function DashboardRecommendations() {
|
||||||
|
return (
|
||||||
|
<Card>
|
||||||
|
<CardHeader className="items-start">
|
||||||
|
<h4>
|
||||||
|
<Trans i18nKey="dashboard:recommendedForYou" />
|
||||||
|
</h4>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="space-y-6">
|
||||||
|
{dummyRecommendations.map(
|
||||||
|
(
|
||||||
|
{
|
||||||
|
icon,
|
||||||
|
color,
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
tooltipContent,
|
||||||
|
price,
|
||||||
|
buttonText,
|
||||||
|
href,
|
||||||
|
},
|
||||||
|
index,
|
||||||
|
) => {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className="flex w-full justify-between gap-3 overflow-scroll"
|
||||||
|
key={index}
|
||||||
|
>
|
||||||
|
<div className="mr-4 flex min-w-fit flex-row items-center gap-4">
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
'flex size-8 items-center-safe justify-center-safe rounded-full text-white',
|
||||||
|
color,
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{icon}
|
||||||
|
</div>
|
||||||
|
<div className="min-w-fit">
|
||||||
|
<div className="inline-flex items-center gap-1 align-baseline text-sm font-medium">
|
||||||
|
{title}
|
||||||
|
<InfoTooltip content={tooltipContent} />
|
||||||
|
</div>
|
||||||
|
<p className="text-muted-foreground text-sm">
|
||||||
|
{description}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="grid w-36 min-w-fit auto-rows-fr grid-cols-2 items-center gap-4">
|
||||||
|
<p className="text-sm font-medium"> {price}</p>
|
||||||
|
{href ? (
|
||||||
|
<Link href={href}>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="secondary"
|
||||||
|
className="w-full min-w-fit"
|
||||||
|
>
|
||||||
|
{buttonText}
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
) : (
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="secondary"
|
||||||
|
className="w-full min-w-fit"
|
||||||
|
>
|
||||||
|
{buttonText}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
)}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -7,33 +7,41 @@ 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 {
|
import {
|
||||||
Activity,
|
Activity,
|
||||||
|
ChevronRight,
|
||||||
Clock9,
|
Clock9,
|
||||||
Droplets,
|
|
||||||
Pill,
|
Pill,
|
||||||
Scale,
|
Scale,
|
||||||
TrendingUp,
|
TrendingUp,
|
||||||
User,
|
User,
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
|
|
||||||
import { InfoTooltip } from '@kit/shared/components/ui/info-tooltip';
|
import { pathsConfig } from '@kit/shared/config';
|
||||||
import { getPersonParameters } from '@kit/shared/utils';
|
import { getPersonParameters } from '@kit/shared/utils';
|
||||||
import { Button } from '@kit/ui/button';
|
import { Button } from '@kit/ui/button';
|
||||||
import {
|
import {
|
||||||
Card,
|
Card,
|
||||||
CardContent,
|
|
||||||
CardDescription,
|
CardDescription,
|
||||||
CardFooter,
|
CardFooter,
|
||||||
CardHeader,
|
CardHeader,
|
||||||
|
CardProps,
|
||||||
} from '@kit/ui/card';
|
} 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';
|
||||||
|
|
||||||
|
import { isNil } from 'lodash';
|
||||||
import { BmiCategory } from '~/lib/types/bmi';
|
import { BmiCategory } from '~/lib/types/bmi';
|
||||||
import {
|
import {
|
||||||
bmiFromMetric,
|
bmiFromMetric,
|
||||||
getBmiBackgroundColor,
|
getBmiBackgroundColor,
|
||||||
getBmiStatus,
|
getBmiStatus,
|
||||||
} from '~/lib/utils';
|
} from '~/lib/utils';
|
||||||
|
import DashboardRecommendations from './dashboard-recommendations';
|
||||||
|
|
||||||
|
const getCardVariant = (isSuccess: boolean | null): CardProps['variant'] => {
|
||||||
|
if (isSuccess === null) return 'default';
|
||||||
|
if (isSuccess) return 'gradient-success';
|
||||||
|
return 'gradient-destructive';
|
||||||
|
};
|
||||||
|
|
||||||
const cards = ({
|
const cards = ({
|
||||||
gender,
|
gender,
|
||||||
@@ -41,111 +49,91 @@ const cards = ({
|
|||||||
height,
|
height,
|
||||||
weight,
|
weight,
|
||||||
bmiStatus,
|
bmiStatus,
|
||||||
|
smoking,
|
||||||
}: {
|
}: {
|
||||||
gender?: string;
|
gender?: string;
|
||||||
age?: number;
|
age?: number;
|
||||||
height?: number | null;
|
height?: number | null;
|
||||||
weight?: number | null;
|
weight?: number | null;
|
||||||
bmiStatus: BmiCategory | null;
|
bmiStatus: BmiCategory | null;
|
||||||
|
smoking?: boolean | null;
|
||||||
}) => [
|
}) => [
|
||||||
{
|
{
|
||||||
title: 'dashboard:gender',
|
title: 'dashboard:gender',
|
||||||
description: gender ?? 'dashboard:male',
|
description: gender ?? 'dashboard:male',
|
||||||
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: 'dashboard:respondToQuestion',
|
description:
|
||||||
// descriptionColor: 'text-primary',
|
isNil(smoking)
|
||||||
// icon: (
|
? 'dashboard:respondToQuestion'
|
||||||
// <Button size="icon" variant="outline" className="px-2 text-black">
|
: !!smoking
|
||||||
// <ChevronRight className="size-4 stroke-2" />
|
? 'common:yes'
|
||||||
// </Button>
|
: 'common:no',
|
||||||
// ),
|
descriptionColor: 'text-primary',
|
||||||
// cardVariant: 'gradient-success' as CardProps['variant'],
|
icon:
|
||||||
// },
|
isNil(smoking) ? (
|
||||||
];
|
<Link href={pathsConfig.app.personalAccountSettings}>
|
||||||
|
<Button size="icon" variant="outline" className="px-2 text-black">
|
||||||
|
<ChevronRight className="size-4 stroke-2" />
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
) : null,
|
||||||
|
cardVariant: getCardVariant(isNil(smoking) ? null : !smoking),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
const dummyRecommendations = [
|
const IS_SHOWN_RECOMMENDATIONS = false as boolean;
|
||||||
{
|
|
||||||
icon: <BlendingModeIcon className="size-4" />,
|
|
||||||
color: 'bg-cyan/10 text-cyan',
|
|
||||||
title: 'Kolesterooli kontroll',
|
|
||||||
description: 'HDL-kolestrool',
|
|
||||||
tooltipContent: 'Selgitus',
|
|
||||||
price: '20,00 €',
|
|
||||||
buttonText: 'Telli',
|
|
||||||
href: '/home/booking',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: <BlendingModeIcon className="size-4" />,
|
|
||||||
color: 'bg-primary/10 text-primary',
|
|
||||||
title: 'Kolesterooli kontroll',
|
|
||||||
tooltipContent: 'Selgitus',
|
|
||||||
description: 'LDL-Kolesterool',
|
|
||||||
buttonText: 'Broneeri',
|
|
||||||
href: '/home/booking',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: <Droplets />,
|
|
||||||
color: 'bg-destructive/10 text-destructive',
|
|
||||||
title: 'Vererõhu kontroll',
|
|
||||||
tooltipContent: 'Selgitus',
|
|
||||||
description: 'Score-Risk 2',
|
|
||||||
price: '20,00 €',
|
|
||||||
buttonText: 'Telli',
|
|
||||||
href: '/home/booking',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
export default function Dashboard({
|
export default function Dashboard({
|
||||||
account,
|
account,
|
||||||
@@ -160,8 +148,8 @@ export default function Dashboard({
|
|||||||
const params = getPersonParameters(account.personal_code!);
|
const params = getPersonParameters(account.personal_code!);
|
||||||
const bmiStatus = getBmiStatus(bmiThresholds, {
|
const bmiStatus = getBmiStatus(bmiThresholds, {
|
||||||
age: params?.age || 0,
|
age: params?.age || 0,
|
||||||
height: account.account_params?.[0]?.height || 0,
|
height: account.accountParams?.height || 0,
|
||||||
weight: account.account_params?.[0]?.weight || 0,
|
weight: account.accountParams?.weight || 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -170,21 +158,22 @@ export default function Dashboard({
|
|||||||
{cards({
|
{cards({
|
||||||
gender: params?.gender,
|
gender: params?.gender,
|
||||||
age: params?.age,
|
age: params?.age,
|
||||||
height: account.account_params?.[0]?.height,
|
height: account.accountParams?.height,
|
||||||
weight: account.account_params?.[0]?.weight,
|
weight: account.accountParams?.weight,
|
||||||
bmiStatus,
|
bmiStatus,
|
||||||
|
smoking: account.accountParams?.isSmoker,
|
||||||
}).map(
|
}).map(
|
||||||
({
|
({
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
icon,
|
icon,
|
||||||
iconBg,
|
iconBg,
|
||||||
// cardVariant,
|
cardVariant,
|
||||||
// descriptionColor,
|
// descriptionColor,
|
||||||
}) => (
|
}) => (
|
||||||
<Card
|
<Card
|
||||||
key={title}
|
key={title}
|
||||||
// variant={cardVariant}
|
variant={cardVariant}
|
||||||
className="flex flex-col justify-between"
|
className="flex flex-col justify-between"
|
||||||
>
|
>
|
||||||
<CardHeader className="items-end-safe">
|
<CardHeader className="items-end-safe">
|
||||||
@@ -211,79 +200,7 @@ export default function Dashboard({
|
|||||||
),
|
),
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<Card>
|
{IS_SHOWN_RECOMMENDATIONS && <DashboardRecommendations />}
|
||||||
<CardHeader className="items-start">
|
|
||||||
<h4>
|
|
||||||
<Trans i18nKey="dashboard:recommendedForYou" />
|
|
||||||
</h4>
|
|
||||||
</CardHeader>
|
|
||||||
<CardContent className="space-y-6">
|
|
||||||
{dummyRecommendations.map(
|
|
||||||
(
|
|
||||||
{
|
|
||||||
icon,
|
|
||||||
color,
|
|
||||||
title,
|
|
||||||
description,
|
|
||||||
tooltipContent,
|
|
||||||
price,
|
|
||||||
buttonText,
|
|
||||||
href,
|
|
||||||
},
|
|
||||||
index,
|
|
||||||
) => {
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
className="flex w-full justify-between gap-3 overflow-scroll"
|
|
||||||
key={index}
|
|
||||||
>
|
|
||||||
<div className="mr-4 flex min-w-fit flex-row items-center gap-4">
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'flex size-8 items-center-safe justify-center-safe rounded-full text-white',
|
|
||||||
color,
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{icon}
|
|
||||||
</div>
|
|
||||||
<div className="min-w-fit">
|
|
||||||
<div className="inline-flex items-center gap-1 align-baseline text-sm font-medium">
|
|
||||||
{title}
|
|
||||||
<InfoTooltip content={tooltipContent} />
|
|
||||||
</div>
|
|
||||||
<p className="text-muted-foreground text-sm">
|
|
||||||
{description}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="grid w-36 auto-rows-fr grid-cols-2 items-center gap-4 min-w-fit">
|
|
||||||
<p className="text-sm font-medium"> {price}</p>
|
|
||||||
{href ? (
|
|
||||||
<Link href={href}>
|
|
||||||
<Button
|
|
||||||
size="sm"
|
|
||||||
variant="secondary"
|
|
||||||
className="w-full min-w-fit"
|
|
||||||
>
|
|
||||||
{buttonText}
|
|
||||||
</Button>
|
|
||||||
</Link>
|
|
||||||
) : (
|
|
||||||
<Button
|
|
||||||
size="sm"
|
|
||||||
variant="secondary"
|
|
||||||
className="w-full min-w-fit"
|
|
||||||
>
|
|
||||||
{buttonText}
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
)}
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ export async function HomeMenuNavigation(props: {
|
|||||||
})
|
})
|
||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
const cartQuantityTotal = props.cart?.items?.reduce((acc, item) => acc + item.quantity, 0) ?? 0;
|
const cartQuantityTotal =
|
||||||
|
props.cart?.items?.reduce((acc, item) => acc + item.quantity, 0) ?? 0;
|
||||||
const hasCartItems = cartQuantityTotal > 0;
|
const hasCartItems = cartQuantityTotal > 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -39,15 +40,18 @@ export async function HomeMenuNavigation(props: {
|
|||||||
<div className={`flex items-center ${SIDEBAR_WIDTH_PROPERTY}`}>
|
<div className={`flex items-center ${SIDEBAR_WIDTH_PROPERTY}`}>
|
||||||
<AppLogo href={pathsConfig.app.home} />
|
<AppLogo href={pathsConfig.app.home} />
|
||||||
</div>
|
</div>
|
||||||
<Search
|
{/* TODO: add search functionality */}
|
||||||
|
{/* <Search
|
||||||
className="flex grow"
|
className="flex grow"
|
||||||
startElement={<Trans i18nKey="common:search" values={{ end: '...' }} />}
|
startElement={<Trans i18nKey="common:search" values={{ end: '...' }} />}
|
||||||
/>
|
/> */}
|
||||||
|
|
||||||
<div className="flex items-center justify-end gap-3">
|
<div className="flex items-center justify-end gap-3">
|
||||||
|
{/* TODO: add wallet functionality
|
||||||
<Card className="px-6 py-2">
|
<Card className="px-6 py-2">
|
||||||
<span>€ {Number(0).toFixed(2).replace('.', ',')}</span>
|
<span>€ {Number(0).toFixed(2).replace('.', ',')}</span>
|
||||||
</Card>
|
</Card>
|
||||||
|
*/}
|
||||||
{hasCartItems && (
|
{hasCartItems && (
|
||||||
<Button
|
<Button
|
||||||
className="relative mr-0 h-10 cursor-pointer border-1 px-4 py-2"
|
className="relative mr-0 h-10 cursor-pointer border-1 px-4 py-2"
|
||||||
@@ -56,7 +60,7 @@ export async function HomeMenuNavigation(props: {
|
|||||||
<span className="flex items-center text-nowrap">{totalValue}</span>
|
<span className="flex items-center text-nowrap">{totalValue}</span>
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
<Link href="/home/cart">
|
<Link href={pathsConfig.app.cart}>
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
className="relative mr-0 h-10 cursor-pointer border-1 px-4 py-2"
|
className="relative mr-0 h-10 cursor-pointer border-1 px-4 py-2"
|
||||||
|
|||||||
@@ -4,11 +4,13 @@ import { useMemo } from 'react';
|
|||||||
|
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
|
|
||||||
|
import SignOutDropdownItem from '@kit/shared/components/sign-out-dropdown-item';
|
||||||
import { StoreCart } from '@medusajs/types';
|
import { StoreCart } from '@medusajs/types';
|
||||||
import { Cross, LogOut, Menu, Shield, ShoppingCart } from 'lucide-react';
|
import { Cross, Menu, Shield, ShoppingCart } from 'lucide-react';
|
||||||
|
|
||||||
import { usePersonalAccountData } from '@kit/accounts/hooks/use-personal-account-data';
|
import { usePersonalAccountData } from '@kit/accounts/hooks/use-personal-account-data';
|
||||||
import { ApplicationRoleEnum } from '@kit/accounts/types/accounts';
|
import { ApplicationRoleEnum } from '@kit/accounts/types/accounts';
|
||||||
|
import DropdownLink from '@kit/shared/components/ui/dropdown-link';
|
||||||
import {
|
import {
|
||||||
pathsConfig,
|
pathsConfig,
|
||||||
personalAccountNavigationConfig,
|
personalAccountNavigationConfig,
|
||||||
@@ -91,7 +93,7 @@ export function HomeMobileNavigation(props: {
|
|||||||
<If condition={props.cart && hasCartItems}>
|
<If condition={props.cart && hasCartItems}>
|
||||||
<DropdownMenuGroup>
|
<DropdownMenuGroup>
|
||||||
<DropdownLink
|
<DropdownLink
|
||||||
path="/home/cart"
|
path={pathsConfig.app.cart}
|
||||||
label="common:shoppingCartCount"
|
label="common:shoppingCartCount"
|
||||||
Icon={<ShoppingCart className="stroke-[1.5px]" />}
|
Icon={<ShoppingCart className="stroke-[1.5px]" />}
|
||||||
labelOptions={{ count: cartQuantityTotal }}
|
labelOptions={{ count: cartQuantityTotal }}
|
||||||
@@ -145,49 +147,4 @@ export function HomeMobileNavigation(props: {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function DropdownLink(
|
|
||||||
props: React.PropsWithChildren<{
|
|
||||||
path: string;
|
|
||||||
label: string;
|
|
||||||
labelOptions?: Record<string, any>;
|
|
||||||
Icon: React.ReactNode;
|
|
||||||
}>,
|
|
||||||
) {
|
|
||||||
return (
|
|
||||||
<DropdownMenuItem asChild key={props.path}>
|
|
||||||
<Link
|
|
||||||
href={props.path}
|
|
||||||
className={'flex h-12 w-full items-center space-x-4'}
|
|
||||||
>
|
|
||||||
{props.Icon}
|
|
||||||
|
|
||||||
<span>
|
|
||||||
<Trans
|
|
||||||
i18nKey={props.label}
|
|
||||||
defaults={props.label}
|
|
||||||
values={props.labelOptions}
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
</Link>
|
|
||||||
</DropdownMenuItem>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function SignOutDropdownItem(
|
|
||||||
props: React.PropsWithChildren<{
|
|
||||||
onSignOut: () => unknown;
|
|
||||||
}>,
|
|
||||||
) {
|
|
||||||
return (
|
|
||||||
<DropdownMenuItem
|
|
||||||
className={'flex h-12 w-full items-center space-x-4'}
|
|
||||||
onClick={props.onSignOut}
|
|
||||||
>
|
|
||||||
<LogOut className={'h-6'} />
|
|
||||||
|
|
||||||
<span>
|
|
||||||
<Trans i18nKey={'common:signOut'} defaults={'Sign out'} />
|
|
||||||
</span>
|
|
||||||
</DropdownMenuItem>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { HeartPulse, Loader2, ShoppingCart } from 'lucide-react';
|
import { HeartPulse, Loader2, ShoppingCart } from 'lucide-react';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import { Button } from '@kit/ui/button';
|
import { Button } from '@kit/ui/button';
|
||||||
import {
|
import {
|
||||||
@@ -15,12 +16,14 @@ 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 { Trans } from '@kit/ui/trans';
|
||||||
import { toast } from '@kit/ui/sonner';
|
import { toast } from '@kit/ui/sonner';
|
||||||
|
import { formatCurrency } from '@/packages/shared/src/utils';
|
||||||
|
|
||||||
export type OrderAnalysisCard = Pick<
|
export type OrderAnalysisCard = Pick<
|
||||||
StoreProduct, 'title' | 'description' | 'subtitle'
|
StoreProduct, 'title' | 'description' | 'subtitle'
|
||||||
> & {
|
> & {
|
||||||
isAvailable: boolean;
|
isAvailable: boolean;
|
||||||
variant: { id: string };
|
variant: { id: string };
|
||||||
|
price: number | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function OrderAnalysesCards({
|
export default function OrderAnalysesCards({
|
||||||
@@ -30,23 +33,26 @@ export default function OrderAnalysesCards({
|
|||||||
analyses: OrderAnalysisCard[];
|
analyses: OrderAnalysisCard[];
|
||||||
countryCode: string;
|
countryCode: string;
|
||||||
}) {
|
}) {
|
||||||
const [isAddingToCart, setIsAddingToCart] = useState(false);
|
|
||||||
|
const { i18n: { language } } = useTranslation()
|
||||||
|
|
||||||
|
const [variantAddingToCart, setVariantAddingToCart] = useState<string | null>(null);
|
||||||
const handleSelect = async (variantId: string) => {
|
const handleSelect = async (variantId: string) => {
|
||||||
if (isAddingToCart) {
|
if (variantAddingToCart) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
setIsAddingToCart(true);
|
setVariantAddingToCart(variantId);
|
||||||
try {
|
try {
|
||||||
await handleAddToCart({
|
await handleAddToCart({
|
||||||
selectedVariant: { id: variantId },
|
selectedVariant: { id: variantId },
|
||||||
countryCode,
|
countryCode,
|
||||||
});
|
});
|
||||||
toast.success(<Trans i18nKey={'order-analysis:analysisAddedToCart'} />);
|
toast.success(<Trans i18nKey={'order-analysis:analysisAddedToCart'} />);
|
||||||
setIsAddingToCart(false);
|
setVariantAddingToCart(null);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
toast.error(<Trans i18nKey={'order-analysis:analysisAddToCartError'} />);
|
toast.error(<Trans i18nKey={'order-analysis:analysisAddToCartError'} />);
|
||||||
setIsAddingToCart(false);
|
setVariantAddingToCart(null);
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -59,7 +65,15 @@ export default function OrderAnalysesCards({
|
|||||||
description,
|
description,
|
||||||
subtitle,
|
subtitle,
|
||||||
isAvailable,
|
isAvailable,
|
||||||
|
price,
|
||||||
}) => {
|
}) => {
|
||||||
|
const formattedPrice = typeof price === 'number'
|
||||||
|
? formatCurrency({
|
||||||
|
currencyCode: 'eur',
|
||||||
|
locale: language,
|
||||||
|
value: price,
|
||||||
|
})
|
||||||
|
: null;
|
||||||
return (
|
return (
|
||||||
<Card
|
<Card
|
||||||
key={title}
|
key={title}
|
||||||
@@ -80,7 +94,7 @@ export default function OrderAnalysesCards({
|
|||||||
className="px-2 text-black"
|
className="px-2 text-black"
|
||||||
onClick={() => handleSelect(variant.id)}
|
onClick={() => handleSelect(variant.id)}
|
||||||
>
|
>
|
||||||
{isAddingToCart ? <Loader2 className="size-4 stroke-2 animate-spin" /> : <ShoppingCart className="size-4 stroke-2" />}
|
{variantAddingToCart === variant.id ? <Loader2 className="size-4 stroke-2 animate-spin" /> : <ShoppingCart className="size-4 stroke-2" />}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -91,7 +105,14 @@ export default function OrderAnalysesCards({
|
|||||||
{description && (
|
{description && (
|
||||||
<>
|
<>
|
||||||
{' '}
|
{' '}
|
||||||
<InfoTooltip content={`${description}`} />
|
<InfoTooltip
|
||||||
|
content={
|
||||||
|
<div className='flex flex-col gap-2'>
|
||||||
|
<span>{formattedPrice}</span>
|
||||||
|
<span>{description}</span>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</h5>
|
</h5>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { cache } from 'react';
|
import { cache } from 'react';
|
||||||
|
|
||||||
import { requireUserInServerComponent } from '@/lib/server/require-user-in-server-component';
|
|
||||||
|
|
||||||
import { createAccountsApi } from '@kit/accounts/api';
|
import { createAccountsApi } from '@kit/accounts/api';
|
||||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import { cache } from 'react';
|
import { cache } from 'react';
|
||||||
|
|
||||||
import { getProductCategories } from '@lib/data/categories';
|
import { getProductCategories } from '@lib/data/categories';
|
||||||
import { listProductTypes } from '@lib/data/products';
|
import { listProducts, listProductTypes } from '@lib/data/products';
|
||||||
import { listRegions } from '@lib/data/regions';
|
import { listRegions } from '@lib/data/regions';
|
||||||
|
|
||||||
import { OrderAnalysisCard } from '../../_components/order-analyses-cards';
|
import { OrderAnalysisCard } from '../../_components/order-analyses-cards';
|
||||||
import { ServiceCategory } from '../../_components/service-categories';
|
|
||||||
|
|
||||||
async function countryCodesLoader() {
|
async function countryCodesLoader() {
|
||||||
const countryCodes = await listRegions().then((regions) =>
|
const countryCodes = await listRegions().then((regions) =>
|
||||||
@@ -39,13 +38,20 @@ async function analysesLoader() {
|
|||||||
const category = productCategories.find(
|
const category = productCategories.find(
|
||||||
({ metadata }) => metadata?.page === 'order-analysis',
|
({ metadata }) => metadata?.page === 'order-analysis',
|
||||||
);
|
);
|
||||||
|
const categoryProducts = category
|
||||||
|
? await listProducts({
|
||||||
|
countryCode,
|
||||||
|
queryParams: { limit: 100, category_id: category.id },
|
||||||
|
})
|
||||||
|
: null;
|
||||||
|
|
||||||
const serviceCategories = productCategories.filter(
|
const serviceCategories = productCategories.filter(
|
||||||
({ parent_category }) => parent_category?.handle === 'tto-categories',
|
({ parent_category }) => parent_category?.handle === 'tto-categories',
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
analyses:
|
analyses:
|
||||||
category?.products?.map<OrderAnalysisCard>(
|
categoryProducts?.response.products.map<OrderAnalysisCard>(
|
||||||
({ title, description, subtitle, variants, status, metadata }) => {
|
({ title, description, subtitle, variants, status, metadata }) => {
|
||||||
const variant = variants![0]!;
|
const variant = variants![0]!;
|
||||||
return {
|
return {
|
||||||
@@ -57,6 +63,7 @@ async function analysesLoader() {
|
|||||||
},
|
},
|
||||||
isAvailable:
|
isAvailable:
|
||||||
status === 'published' && !!metadata?.analysisIdOriginal,
|
status === 'published' && !!metadata?.analysisIdOriginal,
|
||||||
|
price: variant.calculated_price?.calculated_amount ?? null,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
) ?? [],
|
) ?? [],
|
||||||
|
|||||||
@@ -16,14 +16,14 @@ export const loadUserAccount = cache(accountLoader);
|
|||||||
|
|
||||||
export async function loadCurrentUserAccount() {
|
export async function loadCurrentUserAccount() {
|
||||||
const user = await requireUserInServerComponent();
|
const user = await requireUserInServerComponent();
|
||||||
return user?.identities?.[0]?.id
|
return user?.id
|
||||||
? await loadUserAccount(user?.identities?.[0]?.id)
|
? await loadUserAccount(user.id)
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function accountLoader(accountId: string) {
|
async function accountLoader(userId: string) {
|
||||||
const client = getSupabaseServerClient();
|
const client = getSupabaseServerClient();
|
||||||
const api = createAccountsApi(client);
|
const api = createAccountsApi(client);
|
||||||
|
|
||||||
return api.getAccount(accountId);
|
return api.getPersonalAccountByUserId(userId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,111 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
|
import { useForm } from 'react-hook-form';
|
||||||
|
import { Trans } from 'react-i18next';
|
||||||
|
|
||||||
|
import { AccountWithParams } from '@kit/accounts/api';
|
||||||
|
import { useRevalidatePersonalAccountDataQuery } from '@kit/accounts/hooks/use-personal-account-data';
|
||||||
|
import { Button } from '@kit/ui/button';
|
||||||
|
import { Card, CardDescription, CardTitle } from '@kit/ui/card';
|
||||||
|
import { Form } from '@kit/ui/form';
|
||||||
|
import { toast } from '@kit/ui/sonner';
|
||||||
|
import { Switch } from '@kit/ui/switch';
|
||||||
|
|
||||||
|
import {
|
||||||
|
AccountPreferences,
|
||||||
|
accountPreferencesSchema,
|
||||||
|
} from '../_lib/account-preferences.schema';
|
||||||
|
import { updatePersonalAccountPreferencesAction } from '../_lib/server/actions';
|
||||||
|
import { LanguageSelector } from '@kit/ui/language-selector';
|
||||||
|
|
||||||
|
export default function AccountPreferencesForm({
|
||||||
|
account,
|
||||||
|
}: {
|
||||||
|
account: AccountWithParams | null;
|
||||||
|
}) {
|
||||||
|
const revalidateUserDataQuery = useRevalidatePersonalAccountDataQuery();
|
||||||
|
|
||||||
|
const form = useForm({
|
||||||
|
resolver: zodResolver(accountPreferencesSchema),
|
||||||
|
defaultValues: {
|
||||||
|
preferredLanguage: account?.preferred_locale,
|
||||||
|
isConsentToAnonymizedCompanyStatistics:
|
||||||
|
!!account?.has_consent_anonymized_company_statistics,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const { register, handleSubmit, watch, setValue } = form;
|
||||||
|
|
||||||
|
const onSubmit = async (data: AccountPreferences) => {
|
||||||
|
if (!account?.id) {
|
||||||
|
return toast.error(<Trans i18nKey="account:updateAccountError" />);
|
||||||
|
}
|
||||||
|
const result = await updatePersonalAccountPreferencesAction({
|
||||||
|
accountId: account.id,
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
|
revalidateUserDataQuery(account.primary_owner_user_id);
|
||||||
|
return toast.success(
|
||||||
|
<Trans i18nKey="account:updateAccountPreferencesSuccess" />,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return toast.error(
|
||||||
|
<Trans i18nKey="account:updateAccountPreferencesError" />,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const watchedConsent = watch('isConsentToAnonymizedCompanyStatistics');
|
||||||
|
|
||||||
|
if (!account) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="space-y-2">
|
||||||
|
<CardTitle className="text-base">
|
||||||
|
<Trans i18nKey={'account:language'} />
|
||||||
|
</CardTitle>
|
||||||
|
<LanguageSelector />
|
||||||
|
</div>
|
||||||
|
<Form {...form}>
|
||||||
|
<form
|
||||||
|
className="flex flex-col gap-6 text-left"
|
||||||
|
onSubmit={handleSubmit(onSubmit)}
|
||||||
|
>
|
||||||
|
<div className="space-y-4">
|
||||||
|
<h2 className="text-xl font-semibold text-gray-900">
|
||||||
|
<Trans i18nKey="account:consents" />
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<Card>
|
||||||
|
<div className="flex items-center justify-between p-3">
|
||||||
|
<div>
|
||||||
|
<CardTitle className="text-base">
|
||||||
|
<Trans i18nKey="account:consentToAnonymizedCompanyData.label" />
|
||||||
|
</CardTitle>
|
||||||
|
<CardDescription>
|
||||||
|
<Trans i18nKey="account:consentToAnonymizedCompanyData.description" />
|
||||||
|
</CardDescription>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Switch
|
||||||
|
checked={!!watchedConsent}
|
||||||
|
onCheckedChange={(checked) =>
|
||||||
|
setValue('isConsentToAnonymizedCompanyStatistics', checked)
|
||||||
|
}
|
||||||
|
{...register('isConsentToAnonymizedCompanyStatistics')}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Button type="submit" className="w-36">
|
||||||
|
<Trans i18nKey="account:updateProfileSubmitLabel" />
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
259
app/home/(user)/settings/_components/account-settings-form.tsx
Normal file
259
app/home/(user)/settings/_components/account-settings-form.tsx
Normal file
@@ -0,0 +1,259 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
|
import { useForm } from 'react-hook-form';
|
||||||
|
import { Trans } from 'react-i18next';
|
||||||
|
|
||||||
|
import { AccountWithParams } from '@kit/accounts/api';
|
||||||
|
import { useRevalidatePersonalAccountDataQuery } from '@kit/accounts/hooks/use-personal-account-data';
|
||||||
|
import { Button } from '@kit/ui/button';
|
||||||
|
import { Card, CardTitle } from '@kit/ui/card';
|
||||||
|
import {
|
||||||
|
Form,
|
||||||
|
FormControl,
|
||||||
|
FormField,
|
||||||
|
FormItem,
|
||||||
|
FormLabel,
|
||||||
|
FormMessage,
|
||||||
|
} from '@kit/ui/form';
|
||||||
|
import { Input } from '@kit/ui/input';
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from '@kit/ui/select';
|
||||||
|
import { toast } from '@kit/ui/sonner';
|
||||||
|
import { Switch } from '@kit/ui/switch';
|
||||||
|
|
||||||
|
import {
|
||||||
|
AccountSettings,
|
||||||
|
accountSettingsSchema,
|
||||||
|
} from '../_lib/account-settings.schema';
|
||||||
|
import { updatePersonalAccountAction } from '../_lib/server/actions';
|
||||||
|
|
||||||
|
export default function AccountSettingsForm({
|
||||||
|
account,
|
||||||
|
}: {
|
||||||
|
account: AccountWithParams | null;
|
||||||
|
}) {
|
||||||
|
const revalidateUserDataQuery = useRevalidatePersonalAccountDataQuery();
|
||||||
|
|
||||||
|
const form = useForm({
|
||||||
|
resolver: zodResolver(accountSettingsSchema),
|
||||||
|
defaultValues: {
|
||||||
|
firstName: account?.name,
|
||||||
|
lastName: account?.last_name ?? '',
|
||||||
|
email: account?.email,
|
||||||
|
phone: account?.phone ?? '',
|
||||||
|
accountParams: {
|
||||||
|
height: account?.accountParams?.height,
|
||||||
|
weight: account?.accountParams?.weight,
|
||||||
|
isSmoker: account?.accountParams?.isSmoker,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const { handleSubmit } = form;
|
||||||
|
|
||||||
|
const onSubmit = async (data: AccountSettings) => {
|
||||||
|
if (!account?.id) {
|
||||||
|
return toast.error(<Trans i18nKey="account:updateAccountError" />);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await updatePersonalAccountAction({
|
||||||
|
accountId: account.id,
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
|
revalidateUserDataQuery(account.primary_owner_user_id);
|
||||||
|
return toast.success(<Trans i18nKey="account:updateAccountSuccess" />);
|
||||||
|
}
|
||||||
|
return toast.error(<Trans i18nKey="account:updateAccountError" />);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!account) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Form {...form}>
|
||||||
|
<form
|
||||||
|
className="flex flex-col gap-6 text-left"
|
||||||
|
onSubmit={handleSubmit(onSubmit)}
|
||||||
|
>
|
||||||
|
<FormField
|
||||||
|
name={'firstName'}
|
||||||
|
render={({ field }) => {
|
||||||
|
return (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>
|
||||||
|
<Trans i18nKey={'common:formField.firstName'} />
|
||||||
|
</FormLabel>
|
||||||
|
|
||||||
|
<FormControl>
|
||||||
|
<Input {...field} />
|
||||||
|
</FormControl>
|
||||||
|
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
name={'lastName'}
|
||||||
|
render={({ field }) => {
|
||||||
|
return (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>
|
||||||
|
<Trans i18nKey={'common:formField.lastName'} />
|
||||||
|
</FormLabel>
|
||||||
|
|
||||||
|
<FormControl>
|
||||||
|
<Input {...field} />
|
||||||
|
</FormControl>
|
||||||
|
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<FormField
|
||||||
|
name={'accountParams.height'}
|
||||||
|
render={({ field }) => {
|
||||||
|
return (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>
|
||||||
|
<Trans i18nKey={'common:formField.height'} />
|
||||||
|
</FormLabel>
|
||||||
|
|
||||||
|
<FormControl>
|
||||||
|
<Input {...field} />
|
||||||
|
</FormControl>
|
||||||
|
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
name={'accountParams.weight'}
|
||||||
|
render={({ field }) => {
|
||||||
|
return (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>
|
||||||
|
<Trans i18nKey={'common:formField.weight'} />
|
||||||
|
</FormLabel>
|
||||||
|
|
||||||
|
<FormControl>
|
||||||
|
<Input {...field} />
|
||||||
|
</FormControl>
|
||||||
|
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
name={'phone'}
|
||||||
|
render={({ field }) => {
|
||||||
|
return (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>
|
||||||
|
<Trans i18nKey={'common:formField.phone'} />
|
||||||
|
</FormLabel>
|
||||||
|
|
||||||
|
<FormControl>
|
||||||
|
<Input {...field} />
|
||||||
|
</FormControl>
|
||||||
|
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
name={'email'}
|
||||||
|
render={({ field }) => {
|
||||||
|
return (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>
|
||||||
|
<Trans i18nKey={'common:formField.email'} />
|
||||||
|
</FormLabel>
|
||||||
|
|
||||||
|
<FormControl>
|
||||||
|
<Input {...field} />
|
||||||
|
</FormControl>
|
||||||
|
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="space-y-4">
|
||||||
|
<h2 className="text-xl font-semibold text-gray-900">
|
||||||
|
<Trans i18nKey="account:myHabits" />
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
name="accountParams.isSmoker"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>
|
||||||
|
<Trans i18nKey={'common:formField.smoking'} />
|
||||||
|
</FormLabel>
|
||||||
|
|
||||||
|
<FormControl>
|
||||||
|
<Select
|
||||||
|
value={
|
||||||
|
field.value === true
|
||||||
|
? 'yes'
|
||||||
|
: field.value === false
|
||||||
|
? 'no'
|
||||||
|
: 'preferNotToAnswer'
|
||||||
|
}
|
||||||
|
onValueChange={(value) => {
|
||||||
|
if (value === 'yes') {
|
||||||
|
field.onChange(true);
|
||||||
|
} else if (value === 'no') {
|
||||||
|
field.onChange(false);
|
||||||
|
} else {
|
||||||
|
field.onChange(null);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="yes">
|
||||||
|
<Trans i18nKey="common:yes" />
|
||||||
|
</SelectItem>
|
||||||
|
<SelectItem value="no">
|
||||||
|
<Trans i18nKey="common:no" />
|
||||||
|
</SelectItem>
|
||||||
|
<SelectItem value="preferNotToAnswer">
|
||||||
|
<Trans i18nKey="common:preferNotToAnswer" />
|
||||||
|
</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</FormControl>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Button type="submit" className="w-36">
|
||||||
|
<Trans i18nKey="account:updateProfileSubmitLabel" />
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
);
|
||||||
|
}
|
||||||
152
app/home/(user)/settings/_components/settings-navigation.tsx
Normal file
152
app/home/(user)/settings/_components/settings-navigation.tsx
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useMemo } from 'react';
|
||||||
|
|
||||||
|
import Link from 'next/link';
|
||||||
|
|
||||||
|
import { StoreCart } from '@medusajs/types';
|
||||||
|
import { Cross, Menu, Shield, ShoppingCart } from 'lucide-react';
|
||||||
|
|
||||||
|
import { usePersonalAccountData } from '@kit/accounts/hooks/use-personal-account-data';
|
||||||
|
import { ApplicationRoleEnum } from '@kit/accounts/types/accounts';
|
||||||
|
import { pathsConfig } from '@kit/shared/config';
|
||||||
|
import { useSignOut } from '@kit/supabase/hooks/use-sign-out';
|
||||||
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuGroup,
|
||||||
|
DropdownMenuItem,
|
||||||
|
DropdownMenuSeparator,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
} from '@kit/ui/dropdown-menu';
|
||||||
|
import { If } from '@kit/ui/if';
|
||||||
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
|
import SignOutDropdownItem from '@kit/shared/components/sign-out-dropdown-item';
|
||||||
|
import DropdownLink from '@kit/shared/components/ui/dropdown-link';
|
||||||
|
import { UserWorkspace } from '../../_lib/server/load-user-workspace';
|
||||||
|
import { routes } from './settings-sidebar';
|
||||||
|
|
||||||
|
export function SettingsMobileNavigation(props: {
|
||||||
|
workspace: UserWorkspace;
|
||||||
|
cart: StoreCart | null;
|
||||||
|
}) {
|
||||||
|
const user = props.workspace.user;
|
||||||
|
|
||||||
|
const signOut = useSignOut();
|
||||||
|
const { data: personalAccountData } = usePersonalAccountData(user.id);
|
||||||
|
|
||||||
|
const Links = [
|
||||||
|
{
|
||||||
|
children: [{ path: pathsConfig.app.home, label: 'common:routes.home' }],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
.concat(routes)
|
||||||
|
.map((item, index) => {
|
||||||
|
if ('children' in item) {
|
||||||
|
return item.children.map((child) => {
|
||||||
|
return (
|
||||||
|
<DropdownLink
|
||||||
|
key={child.path}
|
||||||
|
path={child.path}
|
||||||
|
label={child.label}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('divider' in item) {
|
||||||
|
return <DropdownMenuSeparator key={index} />;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const hasTotpFactor = useMemo(() => {
|
||||||
|
const factors = user?.factors ?? [];
|
||||||
|
return factors.some(
|
||||||
|
(factor) => factor.factor_type === 'totp' && factor.status === 'verified',
|
||||||
|
);
|
||||||
|
}, [user?.factors]);
|
||||||
|
|
||||||
|
const isSuperAdmin = useMemo(() => {
|
||||||
|
const hasAdminRole =
|
||||||
|
personalAccountData?.application_role === ApplicationRoleEnum.SuperAdmin;
|
||||||
|
|
||||||
|
return hasAdminRole && hasTotpFactor;
|
||||||
|
}, [user, personalAccountData, hasTotpFactor]);
|
||||||
|
|
||||||
|
const isDoctor = useMemo(() => {
|
||||||
|
const hasDoctorRole =
|
||||||
|
personalAccountData?.application_role === ApplicationRoleEnum.Doctor;
|
||||||
|
|
||||||
|
return hasDoctorRole && hasTotpFactor;
|
||||||
|
}, [user, personalAccountData, hasTotpFactor]);
|
||||||
|
|
||||||
|
const cartQuantityTotal =
|
||||||
|
props.cart?.items?.reduce((acc, item) => acc + item.quantity, 0) ?? 0;
|
||||||
|
const hasCartItems = cartQuantityTotal > 0;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger>
|
||||||
|
<Menu className={'h-9'} />
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
|
||||||
|
<DropdownMenuContent sideOffset={10} className={'w-screen rounded-none'}>
|
||||||
|
<If condition={props.cart && hasCartItems}>
|
||||||
|
<DropdownMenuGroup>
|
||||||
|
<DropdownLink
|
||||||
|
path={pathsConfig.app.cart}
|
||||||
|
label="common:shoppingCartCount"
|
||||||
|
Icon={<ShoppingCart className="stroke-[1.5px]" />}
|
||||||
|
labelOptions={{ count: cartQuantityTotal }}
|
||||||
|
/>
|
||||||
|
</DropdownMenuGroup>
|
||||||
|
<DropdownMenuSeparator />
|
||||||
|
</If>
|
||||||
|
|
||||||
|
<DropdownMenuGroup>{Links}</DropdownMenuGroup>
|
||||||
|
|
||||||
|
<If condition={isSuperAdmin}>
|
||||||
|
<DropdownMenuSeparator />
|
||||||
|
|
||||||
|
<DropdownMenuItem asChild>
|
||||||
|
<Link
|
||||||
|
className={
|
||||||
|
's-full flex cursor-pointer items-center space-x-2 text-yellow-700 dark:text-yellow-500'
|
||||||
|
}
|
||||||
|
href={pathsConfig.app.admin}
|
||||||
|
>
|
||||||
|
<Shield className={'h-5'} />
|
||||||
|
|
||||||
|
<span>Super Admin</span>
|
||||||
|
</Link>
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</If>
|
||||||
|
|
||||||
|
<If condition={isDoctor}>
|
||||||
|
<DropdownMenuSeparator />
|
||||||
|
|
||||||
|
<DropdownMenuItem asChild>
|
||||||
|
<Link
|
||||||
|
className={
|
||||||
|
'flex h-full cursor-pointer items-center space-x-2 text-yellow-700 dark:text-yellow-500'
|
||||||
|
}
|
||||||
|
href={pathsConfig.app.doctor}
|
||||||
|
>
|
||||||
|
<Cross className={'h-5'} />
|
||||||
|
|
||||||
|
<span>
|
||||||
|
<Trans i18nKey="common:doctor" />
|
||||||
|
</span>
|
||||||
|
</Link>
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</If>
|
||||||
|
<DropdownMenuSeparator />
|
||||||
|
|
||||||
|
<SignOutDropdownItem onSignOut={() => signOut.mutateAsync()} />
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import { Separator } from "@kit/ui/separator";
|
||||||
|
import { Trans } from "@kit/ui/trans";
|
||||||
|
|
||||||
|
export default function SettingsSectionHeader({
|
||||||
|
titleKey,
|
||||||
|
descriptionKey,
|
||||||
|
}: {
|
||||||
|
titleKey: string;
|
||||||
|
descriptionKey: string;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className="space-y-2">
|
||||||
|
<h1 className="text-2xl font-semibold text-gray-900">
|
||||||
|
<Trans i18nKey={titleKey} />
|
||||||
|
</h1>
|
||||||
|
<p className="text-gray-600">
|
||||||
|
<Trans i18nKey={descriptionKey} />
|
||||||
|
</p>
|
||||||
|
<Separator />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
55
app/home/(user)/settings/_components/settings-sidebar.tsx
Normal file
55
app/home/(user)/settings/_components/settings-sidebar.tsx
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
import z from 'zod';
|
||||||
|
|
||||||
|
import { pathsConfig } from '@kit/shared/config';
|
||||||
|
import { NavigationConfigSchema } from '@kit/ui/navigation-schema';
|
||||||
|
import { PageHeader } from '@kit/ui/page';
|
||||||
|
import {
|
||||||
|
Sidebar,
|
||||||
|
SidebarContent,
|
||||||
|
SidebarHeader,
|
||||||
|
SidebarNavigation,
|
||||||
|
} from '@kit/ui/shadcn-sidebar';
|
||||||
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
|
export const routes = [
|
||||||
|
{
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
label: 'common:routes.profile',
|
||||||
|
path: pathsConfig.app.personalAccountSettings,
|
||||||
|
end: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
label: 'common:routes.preferences',
|
||||||
|
path: pathsConfig.app.personalAccountPreferences,
|
||||||
|
end: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
label: 'common:routes.security',
|
||||||
|
path: pathsConfig.app.personalAccountSecurity,
|
||||||
|
end: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
] satisfies z.infer<typeof NavigationConfigSchema>['routes'];
|
||||||
|
|
||||||
|
export function SettingsSidebar() {
|
||||||
|
return (
|
||||||
|
<Sidebar>
|
||||||
|
<SidebarHeader className="mt-16 h-24 w-[95vw] max-w-screen justify-center border-b bg-white pt-2">
|
||||||
|
<PageHeader
|
||||||
|
title={<Trans i18nKey="account:accountTabLabel" />}
|
||||||
|
description={<Trans i18nKey={'account:accountTabDescription'} />}
|
||||||
|
/>
|
||||||
|
</SidebarHeader>
|
||||||
|
|
||||||
|
<SidebarContent className="w-auto">
|
||||||
|
<SidebarNavigation
|
||||||
|
config={{ style: 'custom', sidebarCollapsedStyle: 'none', routes }}
|
||||||
|
/>
|
||||||
|
</SidebarContent>
|
||||||
|
</Sidebar>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
export const accountPreferencesSchema = z.object({
|
||||||
|
preferredLanguage: z.enum(['et', 'en', 'ru']).optional().nullable(),
|
||||||
|
isConsentToAnonymizedCompanyStatistics: z.boolean().optional(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type AccountPreferences = z.infer<typeof accountPreferencesSchema>;
|
||||||
21
app/home/(user)/settings/_lib/account-settings.schema.ts
Normal file
21
app/home/(user)/settings/_lib/account-settings.schema.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
export const accountSettingsSchema = z.object({
|
||||||
|
firstName: z
|
||||||
|
.string()
|
||||||
|
.min(1, { error: 'error:tooShort' })
|
||||||
|
.max(200, { error: 'error:tooLong' }),
|
||||||
|
lastName: z
|
||||||
|
.string()
|
||||||
|
.min(1, { error: 'error:tooShort' })
|
||||||
|
.max(200, { error: 'error:tooLong' }),
|
||||||
|
email: z.email({ error: 'error:invalidEmail' }).nullable(),
|
||||||
|
phone: z.e164({ error: 'error:invalidPhone' }),
|
||||||
|
accountParams: z.object({
|
||||||
|
height: z.coerce.number({ error: 'error:invalidNumber' }),
|
||||||
|
weight: z.coerce.number({ error: 'error:invalidNumber' }),
|
||||||
|
isSmoker: z.boolean().optional().nullable(),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type AccountSettings = z.infer<typeof accountSettingsSchema>;
|
||||||
66
app/home/(user)/settings/_lib/server/actions.ts
Normal file
66
app/home/(user)/settings/_lib/server/actions.ts
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
'use server';
|
||||||
|
|
||||||
|
import z from 'zod';
|
||||||
|
|
||||||
|
import { enhanceAction } from '@kit/next/actions';
|
||||||
|
import { getLogger } from '@kit/shared/logger';
|
||||||
|
|
||||||
|
import {
|
||||||
|
updatePersonalAccount,
|
||||||
|
updatePersonalAccountPreferences,
|
||||||
|
} from '~/lib/services/account.service';
|
||||||
|
|
||||||
|
import {
|
||||||
|
AccountPreferences,
|
||||||
|
accountPreferencesSchema,
|
||||||
|
} from '../account-preferences.schema';
|
||||||
|
import {
|
||||||
|
AccountSettings,
|
||||||
|
accountSettingsSchema,
|
||||||
|
} from '../account-settings.schema';
|
||||||
|
|
||||||
|
export const updatePersonalAccountAction = enhanceAction(
|
||||||
|
async ({ accountId, data }: { accountId: string; data: AccountSettings }) => {
|
||||||
|
const logger = await getLogger();
|
||||||
|
|
||||||
|
try {
|
||||||
|
logger.info({ accountId }, 'Updating account');
|
||||||
|
await updatePersonalAccount(accountId, data);
|
||||||
|
logger.info({ accountId }, 'Successfully updated account');
|
||||||
|
return { success: true };
|
||||||
|
} catch (e) {
|
||||||
|
logger.error('Failed to update account', JSON.stringify(e));
|
||||||
|
|
||||||
|
return { success: false };
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
schema: z.object({ accountId: z.uuid(), data: accountSettingsSchema }),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
export const updatePersonalAccountPreferencesAction = enhanceAction(
|
||||||
|
async ({
|
||||||
|
accountId,
|
||||||
|
data,
|
||||||
|
}: {
|
||||||
|
accountId: string;
|
||||||
|
data: AccountPreferences;
|
||||||
|
}) => {
|
||||||
|
const logger = await getLogger();
|
||||||
|
|
||||||
|
try {
|
||||||
|
logger.info({ accountId }, 'Updating account preferences');
|
||||||
|
await updatePersonalAccountPreferences(accountId, data);
|
||||||
|
logger.info({ accountId }, 'Successfully updated account preferences');
|
||||||
|
return { success: true };
|
||||||
|
} catch (e) {
|
||||||
|
logger.error('Failed to update account preferences', JSON.stringify(e));
|
||||||
|
|
||||||
|
return { success: false };
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
schema: z.object({ accountId: z.uuid(), data: accountPreferencesSchema }),
|
||||||
|
},
|
||||||
|
);
|
||||||
@@ -1,23 +1,69 @@
|
|||||||
import { AppBreadcrumbs } from '@kit/ui/app-breadcrumbs';
|
import { use } from 'react';
|
||||||
import { Trans } from '@kit/ui/trans';
|
|
||||||
|
import { retrieveCart } from '@lib/data/cart';
|
||||||
|
import { StoreCart } from '@medusajs/types';
|
||||||
|
|
||||||
|
import { UserWorkspaceContextProvider } from '@kit/accounts/components';
|
||||||
|
import { AppLogo } from '@kit/shared/components/app-logo';
|
||||||
|
import { pathsConfig } from '@kit/shared/config';
|
||||||
|
import { Page, PageMobileNavigation, PageNavigation } from '@kit/ui/page';
|
||||||
|
import { SidebarProvider } from '@kit/ui/shadcn-sidebar';
|
||||||
|
|
||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
|
|
||||||
|
import { SettingsSidebar } from './_components/settings-sidebar';
|
||||||
|
// home imports
|
||||||
|
import { HomeMenuNavigation } from '../_components/home-menu-navigation';
|
||||||
|
import { loadUserWorkspace } from '../_lib/server/load-user-workspace';
|
||||||
|
import { SettingsMobileNavigation } from './_components/settings-navigation';
|
||||||
|
|
||||||
// local imports
|
function UserSettingsLayout({ children }: React.PropsWithChildren) {
|
||||||
import { HomeLayoutPageHeader } from '../_components/home-page-header';
|
return <HeaderLayout>{children}</HeaderLayout>;
|
||||||
|
|
||||||
function UserSettingsLayout(props: React.PropsWithChildren) {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<HomeLayoutPageHeader
|
|
||||||
title={<Trans i18nKey={'account:routes.settings'} />}
|
|
||||||
description={<AppBreadcrumbs />}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{props.children}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default withI18n(UserSettingsLayout);
|
export default withI18n(UserSettingsLayout);
|
||||||
|
|
||||||
|
function HeaderLayout({ children }: React.PropsWithChildren) {
|
||||||
|
const workspace = use(loadUserWorkspace());
|
||||||
|
const cart = use(retrieveCart());
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<UserWorkspaceContextProvider value={workspace}>
|
||||||
|
<Page style={'header'}>
|
||||||
|
<PageNavigation>
|
||||||
|
<HomeMenuNavigation workspace={workspace} cart={cart} />
|
||||||
|
</PageNavigation>
|
||||||
|
|
||||||
|
<PageMobileNavigation className={'flex items-center justify-between'}>
|
||||||
|
<MobileNavigation workspace={workspace} cart={cart} />
|
||||||
|
</PageMobileNavigation>
|
||||||
|
|
||||||
|
<SidebarProvider defaultOpen>
|
||||||
|
<Page style={'sidebar'}>
|
||||||
|
<PageNavigation>
|
||||||
|
<SettingsSidebar />
|
||||||
|
</PageNavigation>
|
||||||
|
<div className="md:mt-28 min-w-full min-h-full">{children}</div>
|
||||||
|
</Page>
|
||||||
|
</SidebarProvider>
|
||||||
|
</Page>
|
||||||
|
</UserWorkspaceContextProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function MobileNavigation({
|
||||||
|
workspace,
|
||||||
|
cart,
|
||||||
|
}: {
|
||||||
|
workspace: Awaited<ReturnType<typeof loadUserWorkspace>>;
|
||||||
|
cart: StoreCart | null;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<AppLogo href={pathsConfig.app.home} />
|
||||||
|
|
||||||
|
<SettingsMobileNavigation workspace={workspace} cart={cart} />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,28 +1,11 @@
|
|||||||
import { use } from 'react';
|
|
||||||
|
|
||||||
import { PersonalAccountSettingsContainer } from '@kit/accounts/personal-account-settings';
|
|
||||||
import {
|
|
||||||
authConfig,
|
|
||||||
featureFlagsConfig,
|
|
||||||
pathsConfig,
|
|
||||||
} from '@kit/shared/config';
|
|
||||||
import { PageBody } from '@kit/ui/page';
|
import { PageBody } from '@kit/ui/page';
|
||||||
|
|
||||||
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
||||||
import { requireUserInServerComponent } from '~/lib/server/require-user-in-server-component';
|
|
||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
|
|
||||||
const features = {
|
import { loadCurrentUserAccount } from '../_lib/server/load-user-account';
|
||||||
enableAccountDeletion: featureFlagsConfig.enableAccountDeletion,
|
import AccountSettingsForm from './_components/account-settings-form';
|
||||||
enablePasswordUpdate: authConfig.providers.password,
|
import SettingsSectionHeader from './_components/settings-section-header';
|
||||||
};
|
|
||||||
|
|
||||||
const callbackPath = pathsConfig.auth.callback;
|
|
||||||
const accountHomePath = pathsConfig.app.accountHome;
|
|
||||||
|
|
||||||
const paths = {
|
|
||||||
callback: callbackPath + `?next=${accountHomePath}`,
|
|
||||||
};
|
|
||||||
|
|
||||||
export const generateMetadata = async () => {
|
export const generateMetadata = async () => {
|
||||||
const i18n = await createI18nServerInstance();
|
const i18n = await createI18nServerInstance();
|
||||||
@@ -33,17 +16,18 @@ export const generateMetadata = async () => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
function PersonalAccountSettingsPage() {
|
async function PersonalAccountSettingsPage() {
|
||||||
const user = use(requireUserInServerComponent());
|
const account = await loadCurrentUserAccount();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageBody>
|
<PageBody>
|
||||||
<div className={'flex w-full flex-1 flex-col lg:max-w-2xl'}>
|
<div className="mx-auto w-full bg-white p-6">
|
||||||
<PersonalAccountSettingsContainer
|
<div className="space-y-6">
|
||||||
userId={user.id}
|
<SettingsSectionHeader
|
||||||
features={features}
|
titleKey="account:accountTabLabel"
|
||||||
paths={paths}
|
descriptionKey="account:accountTabDescription"
|
||||||
/>
|
/>
|
||||||
|
<AccountSettingsForm account={account} />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</PageBody>
|
</PageBody>
|
||||||
);
|
);
|
||||||
|
|||||||
24
app/home/(user)/settings/preferences/page.tsx
Normal file
24
app/home/(user)/settings/preferences/page.tsx
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { CardTitle } from '@kit/ui/card';
|
||||||
|
import { LanguageSelector } from '@kit/ui/language-selector';
|
||||||
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
|
import { loadCurrentUserAccount } from '../../_lib/server/load-user-account';
|
||||||
|
import AccountPreferencesForm from '../_components/account-preferences-form';
|
||||||
|
import SettingsSectionHeader from '../_components/settings-section-header';
|
||||||
|
|
||||||
|
export default async function PreferencesPage() {
|
||||||
|
const account = await loadCurrentUserAccount();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="mx-auto w-full bg-white p-6">
|
||||||
|
<div className="space-y-6">
|
||||||
|
<SettingsSectionHeader
|
||||||
|
titleKey="account:preferencesTabLabel"
|
||||||
|
descriptionKey="account:preferencesTabDescription"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<AccountPreferencesForm account={account} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
17
app/home/(user)/settings/security/page.tsx
Normal file
17
app/home/(user)/settings/security/page.tsx
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { MultiFactorAuthFactorsList } from '@kit/accounts/components';
|
||||||
|
|
||||||
|
import SettingsSectionHeader from '../_components/settings-section-header';
|
||||||
|
|
||||||
|
export default function SecuritySettingsPage() {
|
||||||
|
return (
|
||||||
|
<div className="mx-auto w-full bg-white p-6">
|
||||||
|
<div className="space-y-6">
|
||||||
|
<SettingsSectionHeader
|
||||||
|
titleKey="account:securityTabLabel"
|
||||||
|
descriptionKey="account:securityTabDescription"
|
||||||
|
/>
|
||||||
|
<MultiFactorAuthFactorsList />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import Link from 'next/link';
|
import DropdownLink from '@kit/shared/components/ui/dropdown-link';
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
|
|
||||||
import { Home, LogOut, Menu } from 'lucide-react';
|
import SignOutDropdownItem from '@kit/shared/components/sign-out-dropdown-item';
|
||||||
|
import { Home, Menu } from 'lucide-react';
|
||||||
|
|
||||||
import { AccountSelector } from '@kit/accounts/account-selector';
|
import { AccountSelector } from '@kit/accounts/account-selector';
|
||||||
import {
|
import {
|
||||||
@@ -92,47 +93,7 @@ export const TeamAccountLayoutMobileNavigation = (
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
function DropdownLink(
|
|
||||||
props: React.PropsWithChildren<{
|
|
||||||
path: string;
|
|
||||||
label: string;
|
|
||||||
Icon: React.ReactNode;
|
|
||||||
}>,
|
|
||||||
) {
|
|
||||||
return (
|
|
||||||
<DropdownMenuItem asChild>
|
|
||||||
<Link
|
|
||||||
href={props.path}
|
|
||||||
className={'flex h-12 w-full items-center gap-x-3 px-3'}
|
|
||||||
>
|
|
||||||
{props.Icon}
|
|
||||||
|
|
||||||
<span>
|
|
||||||
<Trans i18nKey={props.label} defaults={props.label} />
|
|
||||||
</span>
|
|
||||||
</Link>
|
|
||||||
</DropdownMenuItem>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function SignOutDropdownItem(
|
|
||||||
props: React.PropsWithChildren<{
|
|
||||||
onSignOut: () => unknown;
|
|
||||||
}>,
|
|
||||||
) {
|
|
||||||
return (
|
|
||||||
<DropdownMenuItem
|
|
||||||
className={'flex h-12 w-full items-center space-x-2'}
|
|
||||||
onClick={props.onSignOut}
|
|
||||||
>
|
|
||||||
<LogOut className={'h-4'} />
|
|
||||||
|
|
||||||
<span>
|
|
||||||
<Trans i18nKey={'common:signOut'} />
|
|
||||||
</span>
|
|
||||||
</DropdownMenuItem>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function TeamAccountsModal(props: {
|
function TeamAccountsModal(props: {
|
||||||
accounts: Accounts;
|
accounts: Accounts;
|
||||||
|
|||||||
8362
current-test-data.sql
Normal file
8362
current-test-data.sql
Normal file
File diff suppressed because one or more lines are too long
@@ -3,9 +3,26 @@
|
|||||||
import { redirect } from 'next/navigation';
|
import { redirect } from 'next/navigation';
|
||||||
|
|
||||||
import { createClient } from '@/utils/supabase/server';
|
import { createClient } from '@/utils/supabase/server';
|
||||||
|
import { medusaLogout } from '@lib/data/customer';
|
||||||
|
|
||||||
export const signOutAction = async () => {
|
export const signOutAction = async () => {
|
||||||
const supabase = await createClient();
|
const client = await createClient();
|
||||||
await supabase.auth.signOut();
|
|
||||||
|
try {
|
||||||
|
try {
|
||||||
|
await medusaLogout();
|
||||||
|
} catch (medusaError) {
|
||||||
|
console.warn('Medusa logout failed or not available:', medusaError);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { error } = await client.auth.signOut();
|
||||||
|
if (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Logout error:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
return redirect('/');
|
return redirect('/');
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ export const defaultI18nNamespaces = [
|
|||||||
'orders',
|
'orders',
|
||||||
'analysis-results',
|
'analysis-results',
|
||||||
'doctor',
|
'doctor',
|
||||||
|
'error',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
import type { Tables } from '@/packages/supabase/src/database.types';
|
import type { Tables } from '@/packages/supabase/src/database.types';
|
||||||
|
|
||||||
|
import { AccountWithParams } from '@kit/accounts/api';
|
||||||
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
||||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||||
|
|
||||||
|
import { AccountSettings } from '~/home/(user)/settings/_lib/account-settings.schema';
|
||||||
|
|
||||||
|
import { AccountPreferences } from '../../app/home/(user)/settings/_lib/account-preferences.schema';
|
||||||
|
import { updateCustomer } from '../../packages/features/medusa-storefront/src/lib/data';
|
||||||
|
|
||||||
type Account = Tables<{ schema: 'medreport' }, 'accounts'>;
|
type Account = Tables<{ schema: 'medreport' }, 'accounts'>;
|
||||||
type Membership = Tables<{ schema: 'medreport' }, 'accounts_memberships'>;
|
type Membership = Tables<{ schema: 'medreport' }, 'accounts_memberships'>;
|
||||||
|
|
||||||
@@ -61,7 +67,9 @@ export async function getDoctorAccounts() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getAssignedDoctorAccount(analysisOrderId: number) {
|
export async function getAssignedDoctorAccount(analysisOrderId: number) {
|
||||||
const { data: doctorUser } = await getSupabaseServerAdminClient()
|
const supabase = getSupabaseServerAdminClient();
|
||||||
|
|
||||||
|
const { data: doctorUser } = await supabase
|
||||||
.schema('medreport')
|
.schema('medreport')
|
||||||
.from('doctor_analysis_feedback')
|
.from('doctor_analysis_feedback')
|
||||||
.select('doctor_user_id')
|
.select('doctor_user_id')
|
||||||
@@ -73,7 +81,7 @@ export async function getAssignedDoctorAccount(analysisOrderId: number) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { data } = await getSupabaseServerAdminClient()
|
const { data } = await supabase
|
||||||
.schema('medreport')
|
.schema('medreport')
|
||||||
.from('accounts')
|
.from('accounts')
|
||||||
.select('email')
|
.select('email')
|
||||||
@@ -81,3 +89,58 @@ export async function getAssignedDoctorAccount(analysisOrderId: number) {
|
|||||||
|
|
||||||
return { email: data?.[0]?.email };
|
return { email: data?.[0]?.email };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function updatePersonalAccount(
|
||||||
|
accountId: string,
|
||||||
|
account: AccountSettings,
|
||||||
|
) {
|
||||||
|
const supabase = getSupabaseServerClient();
|
||||||
|
|
||||||
|
return Promise.all([
|
||||||
|
supabase
|
||||||
|
.schema('medreport')
|
||||||
|
.from('accounts')
|
||||||
|
.update({
|
||||||
|
name: account.firstName,
|
||||||
|
last_name: account.lastName,
|
||||||
|
email: account.email,
|
||||||
|
phone: account.phone,
|
||||||
|
})
|
||||||
|
.eq('id', accountId)
|
||||||
|
.throwOnError(),
|
||||||
|
supabase
|
||||||
|
.schema('medreport')
|
||||||
|
.from('account_params')
|
||||||
|
.upsert(
|
||||||
|
{
|
||||||
|
height: account.accountParams.height,
|
||||||
|
weight: account.accountParams.weight,
|
||||||
|
is_smoker: account.accountParams.isSmoker,
|
||||||
|
},
|
||||||
|
{ onConflict: 'account_id' },
|
||||||
|
)
|
||||||
|
.throwOnError(),
|
||||||
|
updateCustomer({
|
||||||
|
first_name: account.firstName,
|
||||||
|
last_name: account.lastName,
|
||||||
|
phone: account.phone,
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
export async function updatePersonalAccountPreferences(
|
||||||
|
accountId: string,
|
||||||
|
preferences: AccountPreferences,
|
||||||
|
) {
|
||||||
|
const supabase = getSupabaseServerClient();
|
||||||
|
|
||||||
|
return supabase
|
||||||
|
.schema('medreport')
|
||||||
|
.from('accounts')
|
||||||
|
.update({
|
||||||
|
preferred_locale: preferences.preferredLanguage,
|
||||||
|
has_consent_anonymized_company_statistics:
|
||||||
|
preferences.isConsentToAnonymizedCompanyStatistics,
|
||||||
|
})
|
||||||
|
.eq('id', accountId)
|
||||||
|
.throwOnError();
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import type { Tables } from '@/packages/supabase/src/database.types';
|
|||||||
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
||||||
import type { IUuringElement } from "./medipost.types";
|
import type { IUuringElement } from "./medipost.types";
|
||||||
|
|
||||||
type AnalysesWithGroupsAndElements = ({
|
export type AnalysesWithGroupsAndElements = ({
|
||||||
analysis_elements: Tables<{ schema: 'medreport' }, 'analysis_elements'> & {
|
analysis_elements: Tables<{ schema: 'medreport' }, 'analysis_elements'> & {
|
||||||
analysis_groups: Tables<{ schema: 'medreport' }, 'analysis_groups'>;
|
analysis_groups: Tables<{ schema: 'medreport' }, 'analysis_groups'>;
|
||||||
};
|
};
|
||||||
@@ -105,12 +105,18 @@ export const createMedusaSyncSuccessEntry = async () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAnalyses({ ids }: { ids: number[] }): Promise<AnalysesWithGroupsAndElements> {
|
export async function getAnalyses({ ids, originalIds }: { ids?: number[], originalIds?: string[] }): Promise<AnalysesWithGroupsAndElements> {
|
||||||
const { data } = await getSupabaseServerAdminClient()
|
const query = getSupabaseServerAdminClient()
|
||||||
.schema('medreport')
|
.schema('medreport')
|
||||||
.from('analyses')
|
.from('analyses')
|
||||||
.select(`*, analysis_elements(*, analysis_groups(*))`)
|
.select(`*, analysis_elements(*, analysis_groups(*))`);
|
||||||
.in('id', ids);
|
if (Array.isArray(ids)) {
|
||||||
|
query.in('id', ids);
|
||||||
|
}
|
||||||
|
if (Array.isArray(originalIds)) {
|
||||||
|
query.in('analysis_id_original', originalIds);
|
||||||
|
}
|
||||||
|
const { data } = await query.throwOnError();
|
||||||
|
|
||||||
return data as unknown as AnalysesWithGroupsAndElements;
|
return data as unknown as AnalysesWithGroupsAndElements;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,10 +37,10 @@ import { Tables } from '@kit/supabase/database';
|
|||||||
import { createAnalysisGroup } from './analysis-group.service';
|
import { createAnalysisGroup } from './analysis-group.service';
|
||||||
import { getSupabaseServerAdminClient } from '@/packages/supabase/src/clients/server-admin-client';
|
import { getSupabaseServerAdminClient } from '@/packages/supabase/src/clients/server-admin-client';
|
||||||
import { getOrder, updateOrderStatus } from './order.service';
|
import { getOrder, updateOrderStatus } from './order.service';
|
||||||
import { getAnalysisElements, getAnalysisElementsAdmin } from './analysis-element.service';
|
import { AnalysisElement, getAnalysisElements, getAnalysisElementsAdmin } from './analysis-element.service';
|
||||||
import { getAnalyses } from './analyses.service';
|
import { AnalysesWithGroupsAndElements, getAnalyses } from './analyses.service';
|
||||||
import { getAccountAdmin } from './account.service';
|
import { getAccountAdmin } from './account.service';
|
||||||
import { StoreOrder } from '@medusajs/types';
|
import { StoreOrder, StoreOrderLineItem } from '@medusajs/types';
|
||||||
import { listProducts } from '@lib/data/products';
|
import { listProducts } from '@lib/data/products';
|
||||||
import { listRegions } from '@lib/data/regions';
|
import { listRegions } from '@lib/data/regions';
|
||||||
import { getAnalysisElementMedusaProductIds } from '@/utils/medusa-product';
|
import { getAnalysisElementMedusaProductIds } from '@/utils/medusa-product';
|
||||||
@@ -480,72 +480,60 @@ export async function composeOrderXML({
|
|||||||
throw new Error(`Got ${analyses.length} analyses, expected ${orderedAnalysesIds.length}`);
|
throw new Error(`Got ${analyses.length} analyses, expected ${orderedAnalysesIds.length}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const uniques = [
|
||||||
|
...analysisElements?.flatMap(({ analysis_groups }) => analysis_groups) ?? [],
|
||||||
|
...analyses?.flatMap(({ analysis_elements }) => analysis_elements.analysis_groups) ?? []
|
||||||
|
];
|
||||||
const analysisGroups: Tables<{ schema: 'medreport' }, 'analysis_groups'>[] =
|
const analysisGroups: Tables<{ schema: 'medreport' }, 'analysis_groups'>[] =
|
||||||
uniqBy(
|
uniqBy(uniques, 'id');
|
||||||
(
|
console.log('analysisGroups', { analysisGroups, uniques });
|
||||||
analysisElements?.flatMap(({ analysis_groups }) => analysis_groups) ??
|
|
||||||
[]
|
|
||||||
).concat(
|
|
||||||
analyses?.flatMap(
|
|
||||||
({ analysis_elements }) => analysis_elements.analysis_groups,
|
|
||||||
) ?? [],
|
|
||||||
),
|
|
||||||
'id',
|
|
||||||
);
|
|
||||||
|
|
||||||
const specimenSection = [];
|
const specimenSection = [];
|
||||||
const analysisSection = [];
|
const analysisSection = [];
|
||||||
let order = 1;
|
let order = 1;
|
||||||
for (const currentGroup of analysisGroups) {
|
for (const currentGroup of analysisGroups) {
|
||||||
let relatedAnalysisElement = analysisElements?.find(
|
const relatedAnalysisElements = await getRelatedAnalysisElements({
|
||||||
(element) => element.analysis_groups.id === currentGroup.id,
|
analysisElements,
|
||||||
);
|
analyses,
|
||||||
const relatedAnalyses = analyses?.filter((analysis) => {
|
currentGroup,
|
||||||
return analysis.analysis_elements.analysis_groups.id === currentGroup.id;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!relatedAnalysisElement) {
|
for (const relatedAnalysisElement of relatedAnalysisElements) {
|
||||||
relatedAnalysisElement = relatedAnalyses?.find(
|
if (!relatedAnalysisElement || !relatedAnalysisElement.material_groups) {
|
||||||
(relatedAnalysis) =>
|
throw new Error(
|
||||||
relatedAnalysis.analysis_elements.analysis_groups.id ===
|
`Failed to find related analysis element for group ${currentGroup.name} (id: ${currentGroup.id})`,
|
||||||
currentGroup.id,
|
);
|
||||||
)?.analysis_elements;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!relatedAnalysisElement || !relatedAnalysisElement.material_groups) {
|
for (const group of relatedAnalysisElement?.material_groups as MaterjalideGrupp[]) {
|
||||||
throw new Error(
|
const materials = toArray(group.Materjal);
|
||||||
`Failed to find related analysis element for group ${currentGroup.name} (id: ${currentGroup.id})`,
|
const specimenXml = materials.flatMap(
|
||||||
|
({ MaterjaliNimi, MaterjaliTyyp, MaterjaliTyypOID, Konteiner }) => {
|
||||||
|
return toArray(Konteiner).map((container) =>
|
||||||
|
getSpecimen(
|
||||||
|
MaterjaliTyypOID,
|
||||||
|
MaterjaliTyyp,
|
||||||
|
MaterjaliNimi,
|
||||||
|
order,
|
||||||
|
container.ProovinouKoodOID,
|
||||||
|
container.ProovinouKood,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
specimenSection.push(...specimenXml);
|
||||||
|
}
|
||||||
|
|
||||||
|
const groupXml = getAnalysisGroup(
|
||||||
|
currentGroup.original_id,
|
||||||
|
currentGroup.name,
|
||||||
|
order,
|
||||||
|
relatedAnalysisElement,
|
||||||
);
|
);
|
||||||
|
order++;
|
||||||
|
analysisSection.push(groupXml);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const group of relatedAnalysisElement?.material_groups as MaterjalideGrupp[]) {
|
|
||||||
const materials = toArray(group.Materjal);
|
|
||||||
const specimenXml = materials.flatMap(
|
|
||||||
({ MaterjaliNimi, MaterjaliTyyp, MaterjaliTyypOID, Konteiner }) => {
|
|
||||||
return toArray(Konteiner).map((container) =>
|
|
||||||
getSpecimen(
|
|
||||||
MaterjaliTyypOID,
|
|
||||||
MaterjaliTyyp,
|
|
||||||
MaterjaliNimi,
|
|
||||||
order,
|
|
||||||
container.ProovinouKoodOID,
|
|
||||||
container.ProovinouKood,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
specimenSection.push(...specimenXml);
|
|
||||||
}
|
|
||||||
|
|
||||||
const groupXml = getAnalysisGroup(
|
|
||||||
currentGroup.original_id,
|
|
||||||
currentGroup.name,
|
|
||||||
order,
|
|
||||||
relatedAnalysisElement,
|
|
||||||
);
|
|
||||||
order++;
|
|
||||||
analysisSection.push(groupXml);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return `<?xml version="1.0" encoding="UTF-8"?>
|
return `<?xml version="1.0" encoding="UTF-8"?>
|
||||||
@@ -666,7 +654,7 @@ async function syncPrivateMessage({
|
|||||||
unit: element.Mootyhik ?? null,
|
unit: element.Mootyhik ?? null,
|
||||||
original_response_element: element,
|
original_response_element: element,
|
||||||
analysis_name: element.UuringNimi || element.KNimetus,
|
analysis_name: element.UuringNimi || element.KNimetus,
|
||||||
comment: element.UuringuKommentaar
|
comment: element.UuringuKommentaar ?? '',
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -695,7 +683,7 @@ async function syncPrivateMessage({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { data: allOrderResponseElements} = await supabase
|
const { data: allOrderResponseElements } = await supabase
|
||||||
.schema('medreport')
|
.schema('medreport')
|
||||||
.from('analysis_response_elements')
|
.from('analysis_response_elements')
|
||||||
.select('*')
|
.select('*')
|
||||||
@@ -715,7 +703,7 @@ export async function sendOrderToMedipost({
|
|||||||
orderedAnalysisElements,
|
orderedAnalysisElements,
|
||||||
}: {
|
}: {
|
||||||
medusaOrderId: string;
|
medusaOrderId: string;
|
||||||
orderedAnalysisElements: { analysisElementId: number }[];
|
orderedAnalysisElements: { analysisElementId?: number; analysisId?: number }[];
|
||||||
}) {
|
}) {
|
||||||
const medreportOrder = await getOrder({ medusaOrderId });
|
const medreportOrder = await getOrder({ medusaOrderId });
|
||||||
const account = await getAccountAdmin({ primaryOwnerUserId: medreportOrder.user_id });
|
const account = await getAccountAdmin({ primaryOwnerUserId: medreportOrder.user_id });
|
||||||
@@ -727,8 +715,8 @@ export async function sendOrderToMedipost({
|
|||||||
lastName: account.last_name ?? '',
|
lastName: account.last_name ?? '',
|
||||||
phone: account.phone ?? '',
|
phone: account.phone ?? '',
|
||||||
},
|
},
|
||||||
orderedAnalysisElementsIds: orderedAnalysisElements.map(({ analysisElementId }) => analysisElementId),
|
orderedAnalysisElementsIds: orderedAnalysisElements.map(({ analysisElementId }) => analysisElementId).filter(Boolean) as number[],
|
||||||
orderedAnalysesIds: [],
|
orderedAnalysesIds: orderedAnalysisElements.map(({ analysisId }) => analysisId).filter(Boolean) as number[],
|
||||||
orderId: medusaOrderId,
|
orderId: medusaOrderId,
|
||||||
orderCreatedAt: new Date(medreportOrder.created_at),
|
orderCreatedAt: new Date(medreportOrder.created_at),
|
||||||
comment: '',
|
comment: '',
|
||||||
@@ -784,17 +772,21 @@ export async function sendOrderToMedipost({
|
|||||||
await updateOrderStatus({ medusaOrderId, orderStatus: 'PROCESSING' });
|
await updateOrderStatus({ medusaOrderId, orderStatus: 'PROCESSING' });
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getOrderedAnalysisElementsIds({
|
type OrderItems = {
|
||||||
|
items: Pick<StoreOrderLineItem, 'product'>[];
|
||||||
|
}
|
||||||
|
export async function getOrderedAnalysisIds({
|
||||||
medusaOrder,
|
medusaOrder,
|
||||||
}: {
|
}: {
|
||||||
medusaOrder: StoreOrder;
|
medusaOrder: OrderItems;
|
||||||
}): Promise<{
|
}): Promise<{
|
||||||
analysisElementId: number;
|
analysisElementId?: number;
|
||||||
|
analysisId?: number;
|
||||||
}[]> {
|
}[]> {
|
||||||
const countryCodes = await listRegions();
|
const countryCodes = await listRegions();
|
||||||
const countryCode = countryCodes[0]!.countries![0]!.iso_2!;
|
const countryCode = countryCodes[0]!.countries![0]!.iso_2!;
|
||||||
|
|
||||||
async function getOrderedAnalysisElements(medusaOrder: StoreOrder) {
|
async function getOrderedAnalysisElements(medusaOrder: OrderItems) {
|
||||||
const originalIds = (medusaOrder?.items ?? [])
|
const originalIds = (medusaOrder?.items ?? [])
|
||||||
.map((a) => a.product?.metadata?.analysisIdOriginal)
|
.map((a) => a.product?.metadata?.analysisIdOriginal)
|
||||||
.filter((a) => typeof a === 'string') as string[];
|
.filter((a) => typeof a === 'string') as string[];
|
||||||
@@ -802,7 +794,15 @@ export async function getOrderedAnalysisElementsIds({
|
|||||||
return analysisElements.map(({ id }) => ({ analysisElementId: id }));
|
return analysisElements.map(({ id }) => ({ analysisElementId: id }));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getOrderedAnalysisPackages(medusaOrder: StoreOrder) {
|
async function getOrderedAnalyses(medusaOrder: OrderItems) {
|
||||||
|
const originalIds = (medusaOrder?.items ?? [])
|
||||||
|
.map((a) => a.product?.metadata?.analysisIdOriginal)
|
||||||
|
.filter((a) => typeof a === 'string') as string[];
|
||||||
|
const analyses = await getAnalyses({ originalIds });
|
||||||
|
return analyses.map(({ id }) => ({ analysisId: id }));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getOrderedAnalysisPackages(medusaOrder: OrderItems) {
|
||||||
const orderedPackages = (medusaOrder?.items ?? []).filter(({ product }) => product?.handle.startsWith(ANALYSIS_PACKAGE_HANDLE_PREFIX));
|
const orderedPackages = (medusaOrder?.items ?? []).filter(({ product }) => product?.handle.startsWith(ANALYSIS_PACKAGE_HANDLE_PREFIX));
|
||||||
const orderedPackageIds = orderedPackages.map(({ product }) => product?.id).filter(Boolean) as string[];
|
const orderedPackageIds = orderedPackages.map(({ product }) => product?.id).filter(Boolean) as string[];
|
||||||
if (orderedPackageIds.length === 0) {
|
if (orderedPackageIds.length === 0) {
|
||||||
@@ -841,12 +841,13 @@ export async function getOrderedAnalysisElementsIds({
|
|||||||
return analysisElements.map(({ id }) => ({ analysisElementId: id }));
|
return analysisElements.map(({ id }) => ({ analysisElementId: id }));
|
||||||
}
|
}
|
||||||
|
|
||||||
const [analysisPackageElements, orderedAnalysisElements] = await Promise.all([
|
const [analysisPackageElements, orderedAnalysisElements, orderedAnalyses] = await Promise.all([
|
||||||
getOrderedAnalysisPackages(medusaOrder),
|
getOrderedAnalysisPackages(medusaOrder),
|
||||||
getOrderedAnalysisElements(medusaOrder),
|
getOrderedAnalysisElements(medusaOrder),
|
||||||
|
getOrderedAnalyses(medusaOrder),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return [...analysisPackageElements, ...orderedAnalysisElements];
|
return [...analysisPackageElements, ...orderedAnalysisElements, ...orderedAnalyses];
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createMedipostActionLog({
|
export async function createMedipostActionLog({
|
||||||
@@ -858,10 +859,10 @@ export async function createMedipostActionLog({
|
|||||||
hasError = false,
|
hasError = false,
|
||||||
}: {
|
}: {
|
||||||
action:
|
action:
|
||||||
| 'send_order_to_medipost'
|
| 'send_order_to_medipost'
|
||||||
| 'sync_analysis_results_from_medipost'
|
| 'sync_analysis_results_from_medipost'
|
||||||
| 'send_fake_analysis_results_to_medipost'
|
| 'send_fake_analysis_results_to_medipost'
|
||||||
| 'send_analysis_results_to_medipost';
|
| 'send_analysis_results_to_medipost';
|
||||||
xml: string;
|
xml: string;
|
||||||
hasAnalysisResults?: boolean;
|
hasAnalysisResults?: boolean;
|
||||||
medusaOrderId?: string | null;
|
medusaOrderId?: string | null;
|
||||||
@@ -882,3 +883,39 @@ export async function createMedipostActionLog({
|
|||||||
.select('id')
|
.select('id')
|
||||||
.throwOnError();
|
.throwOnError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getRelatedAnalysisElements({
|
||||||
|
analysisElements,
|
||||||
|
analyses,
|
||||||
|
currentGroup,
|
||||||
|
}: {
|
||||||
|
analysisElements: AnalysisElement[];
|
||||||
|
analyses: AnalysesWithGroupsAndElements;
|
||||||
|
currentGroup: {
|
||||||
|
created_at: string;
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
order: number;
|
||||||
|
original_id: string;
|
||||||
|
updated_at: string | null;
|
||||||
|
};
|
||||||
|
}) {
|
||||||
|
const relatedAnalysisElements: AnalysisElement[] = [];
|
||||||
|
|
||||||
|
const related1 = analysisElements?.filter(
|
||||||
|
(element) => element.analysis_groups.id === currentGroup.id,
|
||||||
|
);
|
||||||
|
if (related1) {
|
||||||
|
relatedAnalysisElements.push(...related1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const related2 = analyses
|
||||||
|
?.filter(({ analysis_elements }) => analysis_elements.analysis_groups.id === currentGroup.id)
|
||||||
|
?.filter(({ analysis_elements }) => analysis_elements.analysis_groups.id === currentGroup.id)
|
||||||
|
?.flatMap(({ analysis_elements }) => analysis_elements);
|
||||||
|
if (related2) {
|
||||||
|
relatedAnalysisElements.push(...related2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return relatedAnalysisElements;
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,12 +16,12 @@ const env = () =>
|
|||||||
.object({
|
.object({
|
||||||
medusaBackendPublicUrl: z
|
medusaBackendPublicUrl: z
|
||||||
.string({
|
.string({
|
||||||
required_error: 'MEDUSA_BACKEND_PUBLIC_URL is required',
|
error: 'MEDUSA_BACKEND_PUBLIC_URL is required',
|
||||||
})
|
})
|
||||||
.min(1),
|
.min(1),
|
||||||
siteUrl: z
|
siteUrl: z
|
||||||
.string({
|
.string({
|
||||||
required_error: 'NEXT_PUBLIC_SITE_URL is required',
|
error: 'NEXT_PUBLIC_SITE_URL is required',
|
||||||
})
|
})
|
||||||
.min(1),
|
.min(1),
|
||||||
})
|
})
|
||||||
@@ -110,7 +110,7 @@ export async function handleNavigateToPayment({
|
|||||||
const paymentLink =
|
const paymentLink =
|
||||||
await new MontonioOrderHandlerService().getMontonioPaymentLink({
|
await new MontonioOrderHandlerService().getMontonioPaymentLink({
|
||||||
notificationUrl: `${env().medusaBackendPublicUrl}/hooks/payment/montonio_montonio`,
|
notificationUrl: `${env().medusaBackendPublicUrl}/hooks/payment/montonio_montonio`,
|
||||||
returnUrl: `${env().siteUrl}/home/cart/montonio-callback`,
|
returnUrl: `${"https://webhook.site"}/home/cart/montonio-callback`,
|
||||||
amount: cart.total,
|
amount: cart.total,
|
||||||
currency: cart.currency_code.toUpperCase(),
|
currency: cart.currency_code.toUpperCase(),
|
||||||
description: `Order from Medreport`,
|
description: `Order from Medreport`,
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export async function createOrder({
|
|||||||
orderedAnalysisElements,
|
orderedAnalysisElements,
|
||||||
}: {
|
}: {
|
||||||
medusaOrder: StoreOrder;
|
medusaOrder: StoreOrder;
|
||||||
orderedAnalysisElements: { analysisElementId: number }[];
|
orderedAnalysisElements: { analysisElementId?: number; analysisId?: number }[];
|
||||||
}) {
|
}) {
|
||||||
const supabase = getSupabaseServerClient();
|
const supabase = getSupabaseServerClient();
|
||||||
|
|
||||||
@@ -21,8 +21,8 @@ export async function createOrder({
|
|||||||
const orderResult = await supabase.schema('medreport')
|
const orderResult = await supabase.schema('medreport')
|
||||||
.from('analysis_orders')
|
.from('analysis_orders')
|
||||||
.insert({
|
.insert({
|
||||||
analysis_element_ids: orderedAnalysisElements.map(({ analysisElementId }) => analysisElementId),
|
analysis_element_ids: orderedAnalysisElements.map(({ analysisElementId }) => analysisElementId).filter(Boolean) as number[],
|
||||||
analysis_ids: [],
|
analysis_ids: orderedAnalysisElements.map(({ analysisId }) => analysisId).filter(Boolean) as number[],
|
||||||
status: 'QUEUED',
|
status: 'QUEUED',
|
||||||
user_id: user.id,
|
user_id: user.id,
|
||||||
medusa_order_id: medusaOrder.id,
|
medusa_order_id: medusaOrder.id,
|
||||||
|
|||||||
23
lib/utils.ts
23
lib/utils.ts
@@ -15,11 +15,12 @@ export function toArray<T>(input?: T | T[] | null): T[] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function toTitleCase(str?: string) {
|
export function toTitleCase(str?: string) {
|
||||||
if (!str) return '';
|
return (
|
||||||
return str.replace(
|
str
|
||||||
/\w\S*/g,
|
?.toLowerCase()
|
||||||
(text: string) =>
|
.replace(/[^-'’\s]+/g, (match) =>
|
||||||
text.charAt(0).toUpperCase() + text.substring(1).toLowerCase(),
|
match.replace(/^./, (first) => first.toUpperCase()),
|
||||||
|
) ?? ""
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,8 +41,12 @@ export function sortByDate<T>(
|
|||||||
|
|
||||||
export const bmiFromMetric = (kg: number, cm: number) => {
|
export const bmiFromMetric = (kg: number, cm: number) => {
|
||||||
const m = cm / 100;
|
const m = cm / 100;
|
||||||
const bmi = kg / (m * m);
|
const m2 = m * m;
|
||||||
return bmi ? Math.round(bmi) : NaN;
|
if (m2 === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const bmi = kg / m2;
|
||||||
|
return !Number.isNaN(bmi) ? Math.round(bmi) : null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getBmiStatus(
|
export function getBmiStatus(
|
||||||
@@ -58,7 +63,9 @@ export function getBmiStatus(
|
|||||||
) || null;
|
) || null;
|
||||||
const bmi = bmiFromMetric(params.weight, params.height);
|
const bmi = bmiFromMetric(params.weight, params.height);
|
||||||
|
|
||||||
if (!thresholdByAge || Number.isNaN(bmi)) return null;
|
if (!thresholdByAge || bmi === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (bmi > thresholdByAge.obesity_min) return BmiCategory.OBESE;
|
if (bmi > thresholdByAge.obesity_min) return BmiCategory.OBESE;
|
||||||
if (bmi > thresholdByAge.strong_min) return BmiCategory.VERY_OVERWEIGHT;
|
if (bmi > thresholdByAge.strong_min) return BmiCategory.VERY_OVERWEIGHT;
|
||||||
|
|||||||
@@ -2,15 +2,14 @@ import { z } from 'zod';
|
|||||||
|
|
||||||
export const companyOfferSchema = z.object({
|
export const companyOfferSchema = z.object({
|
||||||
companyName: z.string({
|
companyName: z.string({
|
||||||
required_error: 'Company name is required',
|
error: 'Company name is required',
|
||||||
}),
|
}),
|
||||||
contactPerson: z.string({
|
contactPerson: z.string({
|
||||||
required_error: 'Contact person is required',
|
error: 'Contact person is required',
|
||||||
}),
|
}),
|
||||||
email: z
|
email: z
|
||||||
.string({
|
.email({
|
||||||
required_error: 'Email is required',
|
error: 'Invalid email',
|
||||||
})
|
}),
|
||||||
.email('Invalid email'),
|
|
||||||
phone: z.string().optional(),
|
phone: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|||||||
5
local-sync/listofproductids.js
Normal file
5
local-sync/listofproductids.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
const list = ["prod_01K2JQF451ZKVV97FMX10T6DG1","prod_01K2JQFECMKR1CGDYQV81HB2W1","prod_01K2JQCZKZRZWD71CRN84V84NJ","prod_01K2JQD1AWQH7VHGPS4BA4028A","prod_01K2JQD321BMZTP7R4ZXEJNR17","prod_01K2JQD4RCRGERJRY8JQB7VWMT","prod_01K2JQD6F2VDANADSB5HY6WB6M","prod_01K2JQD85JGDRE0EJSQXGB74SE","prod_01K2JQD9VG391PZ02ZS57Y72PC","prod_01K2JQDBHYMESBB332PHF5TNTB", "prod_01K2JQG1EK4VTFH4GR2ZVB1RK6", "prod_01K2JQH0AMN407P1234MJ64BZM"]
|
||||||
|
|
||||||
|
const list2 = ['prod_01K2JQF451ZKVV97FMX10T6DG1', 'prod_01K2JQFECMKR1CGDYQV81HB2W1', 'prod_01K2JQCZKZRZWD71CRN84V84NJ', 'prod_01K2JQD1AWQH7VHGPS4BA4028A', 'prod_01K2JQD321BMZTP7R4ZXEJNR17', 'prod_01K2JQD4RCRGERJRY8JQB7VWMT', 'prod_01K2JQD6F2VDANADSB5HY6WB6M', 'prod_01K2JQD85JGDRE0EJSQXGB74SE', 'prod_01K2JQD9VG391PZ02ZS57Y72PC', 'prod_01K2JQDBHYMESBB332PHF5TNTB', 'prod_01K2JQG1EK4VTFH4GR2ZVB1RK6', 'prod_01K2JQH0AMN407P1234MJ64BZM']
|
||||||
|
|
||||||
|
console.log(list2.map(a => `'${a}'`).join(', '));
|
||||||
8
local-sync/local-order.http
Normal file
8
local-sync/local-order.http
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
function send_medipost_test_response() {
|
||||||
|
curl -X POST "$HOSTNAME/api/order/medipost-test-response" \
|
||||||
|
--header "x-jobs-api-key: $JOBS_API_TOKEN" \
|
||||||
|
--header 'Content-Type: application/json' \
|
||||||
|
--data '{ "medusaOrderId": "'$MEDUSA_ORDER_ID'" }'
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
16
local-sync/syncinbrowser.js
Normal file
16
local-sync/syncinbrowser.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
const SyncHelper = {
|
||||||
|
async send() {
|
||||||
|
await fetch('https://test.medreport.ee/api/order/medipost-test-response', {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "x-jobs-api-key": "fd26ec26-70ed-11f0-9e95-431ac3b15a84", "content-type": "application/json" },
|
||||||
|
body: JSON.stringify({ "medusaOrderId": "order_01K2F3KC87NTMZX04T3KDZAQ69" }),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
async sync() {
|
||||||
|
await fetch('https://test.medreport.ee/api/job/sync-analysis-results', {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "x-jobs-api-key": "fd26ec26-70ed-11f0-9e95-431ac3b15a84" },
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
SyncHelper.sync()
|
||||||
157
local-sync/test-cron-setup.md
Normal file
157
local-sync/test-cron-setup.md
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
# Testing the Supabase Cron Job Setup
|
||||||
|
|
||||||
|
This guide provides step-by-step instructions to test your Supabase cron job configuration.
|
||||||
|
|
||||||
|
## Quick Setup Commands
|
||||||
|
|
||||||
|
### 1. Deploy the Migration (Option A)
|
||||||
|
|
||||||
|
If you want to use the migration approach:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Make sure you're connected to your Supabase project
|
||||||
|
npm run supabase:deploy
|
||||||
|
```
|
||||||
|
|
||||||
|
Then manually update the migration file with your actual values before deploying.
|
||||||
|
|
||||||
|
### 2. Manual Setup (Option B - Recommended)
|
||||||
|
|
||||||
|
Use the SQL Editor in Supabase Dashboard:
|
||||||
|
|
||||||
|
1. Go to your Supabase Dashboard → Database → SQL Editor
|
||||||
|
2. Copy and paste the content from `supabase/sql/setup-cron-job.sql`
|
||||||
|
3. Run the SQL to create the function
|
||||||
|
4. Then execute the schedule function with your actual values:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
select schedule_sync_analysis_results_cron(
|
||||||
|
'https://your-production-domain.com', -- Your actual API URL
|
||||||
|
'your-actual-jobs-api-token' -- Your actual JOBS_API_TOKEN
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Testing Steps
|
||||||
|
|
||||||
|
### 1. Verify Extensions are Enabled
|
||||||
|
|
||||||
|
```sql
|
||||||
|
select * from pg_extension where extname in ('pg_cron', 'pg_net');
|
||||||
|
```
|
||||||
|
|
||||||
|
Expected result: Both `pg_cron` and `pg_net` should be listed.
|
||||||
|
|
||||||
|
### 2. Check Job is Scheduled
|
||||||
|
|
||||||
|
```sql
|
||||||
|
select * from cron.job where jobname = 'sync-analysis-results-every-15-minutes';
|
||||||
|
```
|
||||||
|
|
||||||
|
Expected result: One row with your job details, `active` should be `true`.
|
||||||
|
|
||||||
|
### 3. Test API Endpoint Manually
|
||||||
|
|
||||||
|
Before relying on the cron job, test your API endpoint manually:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X POST https://your-domain.com/api/job/sync-analysis-results \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "x-jobs-api-key: YOUR_JOBS_API_TOKEN" \
|
||||||
|
-v
|
||||||
|
```
|
||||||
|
|
||||||
|
Expected result: Status 200 with success message.
|
||||||
|
|
||||||
|
### 4. Monitor Job Execution
|
||||||
|
|
||||||
|
Wait for the job to run (up to 15 minutes), then check execution history:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
select
|
||||||
|
job_run_details.*,
|
||||||
|
job.jobname
|
||||||
|
from cron.job_run_details
|
||||||
|
join cron.job on job.jobid = job_run_details.jobid
|
||||||
|
where job.jobname = 'sync-analysis-results-every-15-minutes'
|
||||||
|
order by start_time desc
|
||||||
|
limit 5;
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5. Check Application Logs
|
||||||
|
|
||||||
|
Monitor your application logs to see if the API calls are being received and processed successfully.
|
||||||
|
|
||||||
|
## Environment Variables Required
|
||||||
|
|
||||||
|
Make sure these environment variables are set in your production environment:
|
||||||
|
|
||||||
|
- `JOBS_API_TOKEN` - The API key for authenticating job requests
|
||||||
|
- All other environment variables required by your `sync-analysis-results` handler
|
||||||
|
|
||||||
|
## Common Issues and Solutions
|
||||||
|
|
||||||
|
### Issue 1: Job Not Appearing
|
||||||
|
|
||||||
|
**Problem**: Job doesn't appear in `cron.job` table.
|
||||||
|
|
||||||
|
**Solution**:
|
||||||
|
- Check if you have sufficient permissions
|
||||||
|
- Ensure extensions are enabled
|
||||||
|
- Try running the schedule function again
|
||||||
|
|
||||||
|
### Issue 2: Job Scheduled but Not Running
|
||||||
|
|
||||||
|
**Problem**: Job appears in table but no execution history.
|
||||||
|
|
||||||
|
**Solutions**:
|
||||||
|
- Check if `active` is `true` in `cron.job` table
|
||||||
|
- Verify cron schedule format is correct
|
||||||
|
- Check Supabase logs for any cron-related errors
|
||||||
|
|
||||||
|
### Issue 3: HTTP Requests Failing
|
||||||
|
|
||||||
|
**Problem**: Job runs but API calls fail.
|
||||||
|
|
||||||
|
**Solutions**:
|
||||||
|
- Test API endpoint manually with curl
|
||||||
|
- Verify API URL is correct and accessible from Supabase
|
||||||
|
- Check if `JOBS_API_TOKEN` is correct
|
||||||
|
- Ensure your application is deployed and running
|
||||||
|
|
||||||
|
### Issue 4: Authentication Errors
|
||||||
|
|
||||||
|
**Problem**: Getting 401 Unauthorized responses.
|
||||||
|
|
||||||
|
**Solutions**:
|
||||||
|
- Verify `x-jobs-api-key` header is included
|
||||||
|
- Check that `JOBS_API_TOKEN` matches between cron job and application
|
||||||
|
- Ensure the header name is exactly `x-jobs-api-key` (case-sensitive)
|
||||||
|
|
||||||
|
## Cleanup Commands
|
||||||
|
|
||||||
|
If you need to remove the cron job:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
-- Unschedule the job
|
||||||
|
select cron.unschedule('sync-analysis-results-every-15-minutes');
|
||||||
|
|
||||||
|
-- Drop the helper function (optional)
|
||||||
|
drop function if exists schedule_sync_analysis_results_cron(text, text);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Next Steps
|
||||||
|
|
||||||
|
Once the cron job is working:
|
||||||
|
|
||||||
|
1. Remove any old instrumentation.ts cron logic if it exists
|
||||||
|
2. Monitor the job performance and adjust interval if needed
|
||||||
|
3. Set up alerting for failed job executions
|
||||||
|
4. Consider adding more detailed logging to your API endpoint
|
||||||
|
|
||||||
|
## Support
|
||||||
|
|
||||||
|
If you encounter issues:
|
||||||
|
|
||||||
|
1. Check the troubleshooting section in `docs/supabase-cron-setup.md`
|
||||||
|
2. Review Supabase documentation for pg_cron and pg_net
|
||||||
|
3. Contact your team for deployment-specific configuration details
|
||||||
1090
local-sync/xmls/SendPrivateMessageToTervise_cURL.sh
Executable file
1090
local-sync/xmls/SendPrivateMessageToTervise_cURL.sh
Executable file
File diff suppressed because it is too large
Load Diff
138
local-sync/xmls/curl2.sh
Executable file
138
local-sync/xmls/curl2.sh
Executable file
@@ -0,0 +1,138 @@
|
|||||||
|
curl --location 'https://meditest.medisoft.ee:7443/Medipost/MedipostServlet' \
|
||||||
|
--form 'Action="SendPrivateMessage";type=text/plain; charset=UTF-8' \
|
||||||
|
--form 'User="trvurgtst";type=text/plain; charset=UTF-8' \
|
||||||
|
--form 'Password="SRB48HZMV";type=text/plain; charset=UTF-8' \
|
||||||
|
--form 'Receiver="trvurgtst";type=text/plain; charset=UTF-8' \
|
||||||
|
--form 'MessageType="Tellimus";type=text/plain; charset=UTF-8' \
|
||||||
|
--form 'Message="<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
||||||
|
<Saadetis xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"TellimusLOINC.xsd\">
|
||||||
|
<Pais>
|
||||||
|
<Pakett versioon=\"20\">OL</Pakett>
|
||||||
|
<Saatja>trvurgtst</Saatja>
|
||||||
|
<Saaja>trvurgtst</Saaja>
|
||||||
|
<Aeg>2022-07-22 11:31:57</Aeg>
|
||||||
|
<SaadetisId>234254234</SaadetisId>
|
||||||
|
<Email>info@terviseuuringud.ee</Email>
|
||||||
|
</Pais>
|
||||||
|
|
||||||
|
<Tellimus cito=\"EI\">
|
||||||
|
<ValisTellimuseId>1288</ValisTellimuseId>
|
||||||
|
|
||||||
|
<\!--<TellijaAsutus>-->
|
||||||
|
<Asutus tyyp=\"TELLIJA\">
|
||||||
|
<AsutuseId>12702440</AsutuseId>
|
||||||
|
<AsutuseNimi>Health Tests OÜ</AsutuseNimi>
|
||||||
|
<AsutuseKood>TSU</AsutuseKood>
|
||||||
|
<AllyksuseNimi/>
|
||||||
|
<Telefon>+37256257117</Telefon>
|
||||||
|
<Vald>0387</Vald>
|
||||||
|
<Aadress>Valukoja 10, 11415 Tallinn</Aadress>
|
||||||
|
</Asutus>
|
||||||
|
|
||||||
|
<\!--<TeostajaAsutus>-->
|
||||||
|
<Asutus tyyp=\"TEOSTAJA\">
|
||||||
|
<AsutuseId>12702440</AsutuseId>
|
||||||
|
<AsutuseNimi>Health Tests OÜ</AsutuseNimi>
|
||||||
|
<AsutuseKood>TSU</AsutuseKood>
|
||||||
|
<AllyksuseNimi/>
|
||||||
|
<Telefon>+37256257117</Telefon>
|
||||||
|
<Vald>0387</Vald>
|
||||||
|
<Aadress>Valukoja 10, 11415 Tallinn</Aadress>
|
||||||
|
</Asutus>
|
||||||
|
|
||||||
|
<\!--<TellijaIsik>-->
|
||||||
|
<Personal tyyp=\"TELLIJA\">
|
||||||
|
<\!--Tervishoiutöötaja kood (OID: 1.3.6.1.4.1.28284.6.2.4.9)
|
||||||
|
või Eesti isikukood (OID: 1.3.6.1.4.1.28284.6.2.2.1) -->
|
||||||
|
<PersonalOID>1.3.6.1.4.1.28284.6.2.2.1</PersonalOID>
|
||||||
|
<PersonalKood>D07907</PersonalKood>
|
||||||
|
<PersonalPerekonnaNimi>Tsvetkov</PersonalPerekonnaNimi>
|
||||||
|
<PersonalEesNimi>Eduard</PersonalEesNimi>
|
||||||
|
<Telefon>+3725555000</Telefon>
|
||||||
|
</Personal>
|
||||||
|
|
||||||
|
|
||||||
|
<\!--<SisestajaIsik>-->
|
||||||
|
<Personal tyyp=\"SISESTAJA\">
|
||||||
|
<\!--Tervishoiutöötaja kood (OID: 1.3.6.1.4.1.28284.6.2.4.9)
|
||||||
|
või Eesti isikukood (OID: 1.3.6.1.4.1.28284.6.2.2.1) -->
|
||||||
|
<PersonalOID>1.3.6.1.4.1.28284.6.2.2.1</PersonalOID>
|
||||||
|
<PersonalKood>D07907</PersonalKood>
|
||||||
|
<PersonalPerekonnaNimi>Tsvetkov</PersonalPerekonnaNimi>
|
||||||
|
<PersonalEesNimi>Eduard</PersonalEesNimi>
|
||||||
|
</Personal>
|
||||||
|
|
||||||
|
|
||||||
|
<TellijaMarkused>Siia tuleb tellija poolne märkus</TellijaMarkused>
|
||||||
|
|
||||||
|
<Patsient>
|
||||||
|
<IsikukoodiOID>1.3.6.1.4.1.28284.6.2.2.1</IsikukoodiOID>
|
||||||
|
<Isikukood>37907262736</Isikukood>
|
||||||
|
<PerekonnaNimi>KIVIRÜÜT</PerekonnaNimi>
|
||||||
|
<EesNimi>ARGO</EesNimi>
|
||||||
|
<SynniAeg>1979-07-26</SynniAeg>
|
||||||
|
<SuguOID>1.3.6.1.4.1.28284.6.2.3.16.2</SuguOID>
|
||||||
|
<Sugu>M</Sugu>
|
||||||
|
</Patsient>
|
||||||
|
|
||||||
|
<Konfidentsiaalsus>
|
||||||
|
<PatsiendileOID>2.16.840.1.113883.5.25</PatsiendileOID>
|
||||||
|
<Patsiendile>N</Patsiendile>
|
||||||
|
<ArstileOID>1.3.6.1.4.1.28284.6.2.2.39.1</ArstileOID>
|
||||||
|
<Arstile>N</Arstile>
|
||||||
|
<EsindajaleOID>1.3.6.1.4.1.28284.6.2.2.37.1</EsindajaleOID>
|
||||||
|
<Esindajale>N</Esindajale>
|
||||||
|
</Konfidentsiaalsus>
|
||||||
|
<Proov>
|
||||||
|
<ProovinouIdOID>1.3.6.1.4.1.28284.6.2.4.100</ProovinouIdOID>
|
||||||
|
<ProovinouId>ANI7570-16522287</ProovinouId>
|
||||||
|
<MaterjaliTyypOID>1.3.6.1.4.1.28284.6.2.1.244.8</MaterjaliTyypOID>
|
||||||
|
<MaterjaliTyyp>119297000</MaterjaliTyyp>
|
||||||
|
<MaterjaliNimi>Veri</MaterjaliNimi>
|
||||||
|
<Ribakood>16522287</Ribakood>
|
||||||
|
<Jarjenumber>7570</Jarjenumber>
|
||||||
|
<VotmisAeg>2022-06-13 08:53:00</VotmisAeg>
|
||||||
|
</Proov>
|
||||||
|
<Proov>
|
||||||
|
<ProovinouIdOID>1.3.6.1.4.1.28284.6.2.4.100</ProovinouIdOID>
|
||||||
|
<ProovinouId>ANI7571-16522288</ProovinouId>
|
||||||
|
<MaterjaliTyypOID>1.3.6.1.4.1.28284.6.2.1.244.8</MaterjaliTyypOID>
|
||||||
|
<MaterjaliTyyp>119297000</MaterjaliTyyp>
|
||||||
|
<MaterjaliNimi>Veri</MaterjaliNimi>
|
||||||
|
<Ribakood>16522288</Ribakood>
|
||||||
|
<Jarjenumber>7571</Jarjenumber>
|
||||||
|
<VotmisAeg>2022-06-13 08:53:00</VotmisAeg>
|
||||||
|
</Proov>
|
||||||
|
<UuringuGrupp>
|
||||||
|
<UuringuGruppId>TL10</UuringuGruppId>
|
||||||
|
<UuringuGruppNimi>Hematoloogilised uuringud</UuringuGruppNimi>
|
||||||
|
<Uuring>
|
||||||
|
<UuringuElement>
|
||||||
|
<UuringIdOID>2.16.840.1.113883.6.1</UuringIdOID>
|
||||||
|
<UuringId>57021-8</UuringId>
|
||||||
|
<TLyhend>B-CBC-5Diff</TLyhend>
|
||||||
|
<KNimetus>Hemogramm 5-osalise leukogrammiga</KNimetus>
|
||||||
|
<UuringNimi>Hemogramm</UuringNimi>
|
||||||
|
<TellijaUuringId>18327</TellijaUuringId>
|
||||||
|
</UuringuElement>
|
||||||
|
<ProoviJarjenumber>7570</ProoviJarjenumber>
|
||||||
|
</Uuring>
|
||||||
|
</UuringuGrupp>
|
||||||
|
<UuringuGrupp>
|
||||||
|
<UuringuGruppId>TL40</UuringuGruppId>
|
||||||
|
<UuringuGruppNimi>Kliinilise keemia uuringud</UuringuGruppNimi>
|
||||||
|
<Uuring>
|
||||||
|
<UuringuElement>
|
||||||
|
<UuringIdOID>2.16.840.1.113883.6.1</UuringIdOID>
|
||||||
|
<UuringId>L-3757</UuringId>
|
||||||
|
<TLyhend>B-HbA1c panel</TLyhend>
|
||||||
|
<KNimetus>HbA1c paneel</KNimetus>
|
||||||
|
<UuringNimi>HbA1c</UuringNimi>
|
||||||
|
<TellijaUuringId>18349</TellijaUuringId>
|
||||||
|
</UuringuElement>
|
||||||
|
<ProoviJarjenumber>7571</ProoviJarjenumber>
|
||||||
|
</Uuring>
|
||||||
|
</UuringuGrupp>
|
||||||
|
</Tellimus>
|
||||||
|
</Saadetis>
|
||||||
|
";type=text/xml; charset=UTF-8'
|
||||||
98
local-sync/xmls/order6.xml
Normal file
98
local-sync/xmls/order6.xml
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<Saadetis xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:noNamespaceSchemaLocation="TellimusLOINC.xsd">
|
||||||
|
<Pais>
|
||||||
|
<Pakett versioon="20">OL</Pakett>
|
||||||
|
|
||||||
|
<Saatja>trvurgtst</Saatja>
|
||||||
|
<Saaja>trvurgtst</Saaja>
|
||||||
|
<Aeg>2025-08-04 03:30:15</Aeg>
|
||||||
|
<SaadetisId>
|
||||||
|
1</SaadetisId>
|
||||||
|
<Email>argo@medreport.ee</Email>
|
||||||
|
</Pais>
|
||||||
|
<Tellimus cito="EI">
|
||||||
|
<ValisTellimuseId>
|
||||||
|
1</ValisTellimuseId>
|
||||||
|
<!--<TellijaAsutus>-->
|
||||||
|
<Asutus tyyp="TELLIJA">
|
||||||
|
<AsutuseId>16381793</AsutuseId>
|
||||||
|
<AsutuseNimi>MedReport
|
||||||
|
OÜ</AsutuseNimi>
|
||||||
|
<AsutuseKood>TSU</AsutuseKood>
|
||||||
|
<Telefon>+37258871517</Telefon>
|
||||||
|
</Asutus>
|
||||||
|
|
||||||
|
<!--<TeostajaAsutus>-->
|
||||||
|
<Asutus tyyp="TEOSTAJA">
|
||||||
|
<AsutuseId>11107913</AsutuseId>
|
||||||
|
<AsutuseNimi>Synlab HTI
|
||||||
|
Tallinn</AsutuseNimi>
|
||||||
|
<AsutuseKood>SLA</AsutuseKood>
|
||||||
|
<AllyksuseNimi>Synlab HTI Tallinn</AllyksuseNimi>
|
||||||
|
|
||||||
|
<Telefon>+3723417123</Telefon>
|
||||||
|
</Asutus>
|
||||||
|
<!--<TellijaIsik>-->
|
||||||
|
<Personal tyyp="TELLIJA"
|
||||||
|
jarjenumber="1">
|
||||||
|
<PersonalOID>1.3.6.1.4.1.28284.6.2.4.9</PersonalOID>
|
||||||
|
<PersonalKood>
|
||||||
|
39610230904</PersonalKood>
|
||||||
|
<PersonalPerekonnaNimi>test2</PersonalPerekonnaNimi>
|
||||||
|
<PersonalEesNimi>
|
||||||
|
test1</PersonalEesNimi>
|
||||||
|
<Telefon>56232775</Telefon>
|
||||||
|
</Personal>
|
||||||
|
<TellijaMarkused>Test
|
||||||
|
comment</TellijaMarkused>
|
||||||
|
<Patsient>
|
||||||
|
<IsikukoodiOID>1.3.6.1.4.1.28284.6.2.2.1</IsikukoodiOID>
|
||||||
|
|
||||||
|
<Isikukood>39610230904</Isikukood>
|
||||||
|
<PerekonnaNimi>test2</PerekonnaNimi>
|
||||||
|
<EesNimi>
|
||||||
|
test1</EesNimi>
|
||||||
|
<SynniAeg>1996-00-23</SynniAeg>
|
||||||
|
<SuguOID>1.3.6.1.4.1.28284.6.2.3.16.2</SuguOID>
|
||||||
|
|
||||||
|
<Sugu>male</Sugu>
|
||||||
|
</Patsient>
|
||||||
|
<Konfidentsiaalsus>
|
||||||
|
<PatsiendileOID>
|
||||||
|
2.16.840.1.113883.5.25</PatsiendileOID>
|
||||||
|
<Patsiendile>N</Patsiendile>
|
||||||
|
<ArstileOID>
|
||||||
|
1.3.6.1.4.1.28284.6.2.2.39.1</ArstileOID>
|
||||||
|
<Arstile>N</Arstile>
|
||||||
|
<EsindajaleOID>
|
||||||
|
1.3.6.1.4.1.28284.6.2.2.37.1</EsindajaleOID>
|
||||||
|
<Esindajale>N</Esindajale>
|
||||||
|
</Konfidentsiaalsus>
|
||||||
|
|
||||||
|
<Proov>
|
||||||
|
<ProovinouIdOID>1.3.6.1.4.1.28284.6.2.1.243.16</ProovinouIdOID>
|
||||||
|
<ProovinouId>A2</ProovinouId>
|
||||||
|
<MaterjaliTyypOID>1.3.6.1.4.1.28284.6.2.1.244.10</MaterjaliTyypOID>
|
||||||
|
<MaterjaliTyyp>119364003</MaterjaliTyyp>
|
||||||
|
<MaterjaliNimi>Seerum</MaterjaliNimi>
|
||||||
|
<Jarjenumber>1</Jarjenumber>
|
||||||
|
</Proov>
|
||||||
|
<UuringuGrupp>
|
||||||
|
<UuringuGruppId>TL106</UuringuGruppId>
|
||||||
|
<UuringuGruppNimi>Söömishäirete uuringud</UuringuGruppNimi>
|
||||||
|
<Uuring>
|
||||||
|
<UuringuElement>
|
||||||
|
<UuringIdOID>2.16.840.1.113883.6.1</UuringIdOID>
|
||||||
|
<UuringId>2276-4</UuringId>
|
||||||
|
<TLyhend>S,P-Fer</TLyhend>
|
||||||
|
<KNimetus>Ferritiin</KNimetus>
|
||||||
|
<UuringNimi>Ferritiin</UuringNimi>
|
||||||
|
<TellijaUuringId>84</TellijaUuringId>
|
||||||
|
</UuringuElement>
|
||||||
|
<ProoviJarjenumber>1</ProoviJarjenumber>
|
||||||
|
</Uuring>
|
||||||
|
</UuringuGrupp>
|
||||||
|
</Tellimus>
|
||||||
|
</Saadetis>
|
||||||
76
local-sync/xmls/order9.xml
Normal file
76
local-sync/xmls/order9.xml
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
<?xml version= \"1.0\" encoding= \"UTF-8\"?>
|
||||||
|
<Saadetis xmlns:xsi= \"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation= \"TellimusLOINC.xsd\">
|
||||||
|
<Pais>
|
||||||
|
<Pakett versioon= \"20\">OL</Pakett>
|
||||||
|
<Saatja>trvurgtst</Saatja>
|
||||||
|
<Saaja>trvurgtst</Saaja>
|
||||||
|
<Aeg>2025-08-04 06:22:18</Aeg>
|
||||||
|
<SaadetisId>TSU000001200</SaadetisId>
|
||||||
|
<Email>argo@medreport.ee</Email>
|
||||||
|
</Pais>
|
||||||
|
<Vastus>
|
||||||
|
<ValisTellimuseId>TSU000001200</ValisTellimuseId>
|
||||||
|
<Asutus tyyp= \"TELLIJA\" jarjenumber= \"1\">
|
||||||
|
<AsutuseId>16381793</AsutuseId>
|
||||||
|
<AsutuseNimi>MedReport OÜ</AsutuseNimi>
|
||||||
|
<AsutuseKood>TSU</AsutuseKood>
|
||||||
|
<Telefon>+37258871517</Telefon>
|
||||||
|
</Asutus>
|
||||||
|
<Asutus tyyp= \"TEOSTAJA\" jarjenumber= \"1\">
|
||||||
|
<AsutuseId>11107913</AsutuseId>
|
||||||
|
<AsutuseNimi>Synlab HTI Tallinn</AsutuseNimi>
|
||||||
|
<AsutuseKood>SLA</AsutuseKood>
|
||||||
|
<AllyksuseNimi>Synlab HTI Tallinn</AllyksuseNimi>
|
||||||
|
<Telefon>+3723417123</Telefon>
|
||||||
|
</Asutus>
|
||||||
|
<Personal tyyp= \"TELLIJA\" jarjenumber= \"1\">
|
||||||
|
<PersonalOID>1.3.6.1.4.1.28284.6.2.4.9</PersonalOID>
|
||||||
|
<PersonalKood>39610230903</PersonalKood>
|
||||||
|
<PersonalPerekonnaNimi>User</PersonalPerekonnaNimi>
|
||||||
|
<PersonalEesNimi>Test</PersonalEesNimi>
|
||||||
|
<Telefon>+37256232775</Telefon>
|
||||||
|
</Personal>
|
||||||
|
<TellijaMarkused>Siia tuleb tellija poolne märkus</TellijaMarkused>
|
||||||
|
|
||||||
|
<TellimuseNumber>TSU000001200</TellimuseNumber>
|
||||||
|
<TellimuseOlek>4</TellimuseOlek>
|
||||||
|
<Patsient>
|
||||||
|
<IsikukoodiOID>1.3.6.1.4.1.28284.6.2.2.1</IsikukoodiOID>
|
||||||
|
<Isikukood>39610230903</Isikukood>
|
||||||
|
<PerekonnaNimi>User</PerekonnaNimi>
|
||||||
|
<EesNimi>Test</EesNimi>
|
||||||
|
<SynniAeg>1996-00-23</SynniAeg>
|
||||||
|
<SuguOID>1.3.6.1.4.1.28284.6.2.3.16.2</SuguOID>
|
||||||
|
<Sugu>male</Sugu>
|
||||||
|
</Patsient>
|
||||||
|
|
||||||
|
|
||||||
|
<UuringuGrupp>
|
||||||
|
<UuringuGruppId>TL106</UuringuGruppId>
|
||||||
|
<UuringuGruppNimi>Söömishäirete uuringud</UuringuGruppNimi>
|
||||||
|
<Uuring>
|
||||||
|
<UuringuElement>
|
||||||
|
<UuringIdOID>2.16.840.1.113883.6.1</UuringIdOID>
|
||||||
|
<UuringId>2276-4</UuringId>
|
||||||
|
<TLyhend>S,P-Fer</TLyhend>
|
||||||
|
<KNimetus>Ferritiin</KNimetus>
|
||||||
|
<UuringNimi>Ferritiin</UuringNimi>
|
||||||
|
<TellijaUuringId>84</TellijaUuringId>
|
||||||
|
<TeostajaUuringId>84</TeostajaUuringId>
|
||||||
|
<UuringOlek>4</UuringOlek>
|
||||||
|
<Mootyhik>%</Mootyhik>
|
||||||
|
<UuringuVastus>
|
||||||
|
<VastuseVaartus>30000</VastuseVaartus>
|
||||||
|
<VastuseAeg>2025-08-04 07:00:12</VastuseAeg>
|
||||||
|
<NormYlem kaasaarvatud= \"EI\">100000</NormYlem>
|
||||||
|
<NormAlum kaasaarvatud= \"EI\">50</NormAlum>
|
||||||
|
<NormiStaatus>0</NormiStaatus>
|
||||||
|
<ProoviJarjenumber>1</ProoviJarjenumber>
|
||||||
|
</UuringuVastus>
|
||||||
|
</UuringuElement>
|
||||||
|
<UuringuTaitjaAsutuseJnr>2</UuringuTaitjaAsutuseJnr>
|
||||||
|
</Uuring>
|
||||||
|
</UuringuGrupp>
|
||||||
|
|
||||||
|
</Vastus>
|
||||||
|
</Saadetis>
|
||||||
41813
local-sync/xmls/public-message.xml
Normal file
41813
local-sync/xmls/public-message.xml
Normal file
File diff suppressed because it is too large
Load Diff
103
ostukorv-order-xml-ferritiin+kliiniline_vereanalyys.xml
Normal file
103
ostukorv-order-xml-ferritiin+kliiniline_vereanalyys.xml
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Saadetis xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:noNamespaceSchemaLocation="TellimusLOINC.xsd">
|
||||||
|
<Pais>
|
||||||
|
<Pakett versioon="20">OL</Pakett>
|
||||||
|
<Saatja>medreport</Saatja>
|
||||||
|
<Saaja>HTI</Saaja>
|
||||||
|
<Aeg>2025-09-04 14:04:33</Aeg>
|
||||||
|
<SaadetisId>1234567890</SaadetisId>
|
||||||
|
<Email>argo@medreport.ee</Email>
|
||||||
|
</Pais>
|
||||||
|
<Tellimus cito="EI">
|
||||||
|
<ValisTellimuseId>1234567890</ValisTellimuseId>
|
||||||
|
<!--<TellijaAsutus>-->
|
||||||
|
<Asutus tyyp="TELLIJA">
|
||||||
|
<AsutuseId>16381793</AsutuseId>
|
||||||
|
<AsutuseNimi>MedReport OÜ</AsutuseNimi>
|
||||||
|
<AsutuseKood>TSU</AsutuseKood>
|
||||||
|
<Telefon>+37258871517</Telefon>
|
||||||
|
</Asutus>
|
||||||
|
<!--<TeostajaAsutus>-->
|
||||||
|
<Asutus tyyp="TEOSTAJA">
|
||||||
|
<AsutuseId>11107913</AsutuseId>
|
||||||
|
<AsutuseNimi>Synlab HTI Tallinn</AsutuseNimi>
|
||||||
|
<AsutuseKood>SLA</AsutuseKood>
|
||||||
|
<AllyksuseNimi>Synlab HTI Tallinn</AllyksuseNimi>
|
||||||
|
<Telefon>+3723417123</Telefon>
|
||||||
|
</Asutus>
|
||||||
|
<!--<TellijaIsik>-->
|
||||||
|
<Personal tyyp="TELLIJA" jarjenumber="1">
|
||||||
|
<PersonalOID>1.3.6.1.4.1.28284.6.2.4.9</PersonalOID>
|
||||||
|
<PersonalKood>1234567890</PersonalKood>
|
||||||
|
<PersonalPerekonnaNimi>Doe</PersonalPerekonnaNimi>
|
||||||
|
<PersonalEesNimi>John</PersonalEesNimi>
|
||||||
|
<Telefon>+3721234567890</Telefon>
|
||||||
|
</Personal>
|
||||||
|
<TellijaMarkused></TellijaMarkused>
|
||||||
|
<Patsient>
|
||||||
|
<IsikukoodiOID>1.3.6.1.4.1.28284.6.2.2.1</IsikukoodiOID>
|
||||||
|
<Isikukood>1234567890</Isikukood>
|
||||||
|
<PerekonnaNimi>Doe</PerekonnaNimi>
|
||||||
|
<EesNimi>John</EesNimi>
|
||||||
|
<SynniAeg>1826-00-06</SynniAeg>
|
||||||
|
<SuguOID>1.3.6.1.4.1.28284.6.2.3.16.2</SuguOID>
|
||||||
|
<Sugu>M</Sugu>
|
||||||
|
</Patsient>
|
||||||
|
<Konfidentsiaalsus>
|
||||||
|
<PatsiendileOID>2.16.840.1.113883.5.25</PatsiendileOID>
|
||||||
|
<Patsiendile>N</Patsiendile>
|
||||||
|
<ArstileOID>1.3.6.1.4.1.28284.6.2.2.39.1</ArstileOID>
|
||||||
|
<Arstile>N</Arstile>
|
||||||
|
<EsindajaleOID>1.3.6.1.4.1.28284.6.2.2.37.1</EsindajaleOID>
|
||||||
|
<Esindajale>N</Esindajale>
|
||||||
|
</Konfidentsiaalsus>
|
||||||
|
|
||||||
|
<Proov>
|
||||||
|
<ProovinouIdOID>1.3.6.1.4.1.28284.6.2.1.243.22</ProovinouIdOID>
|
||||||
|
<ProovinouId>A7</ProovinouId>
|
||||||
|
<MaterjaliTyypOID>1.3.6.1.4.1.28284.6.2.1.244.15</MaterjaliTyypOID>
|
||||||
|
<MaterjaliTyyp>445295009</MaterjaliTyyp>
|
||||||
|
<MaterjaliNimi>K2E/K3E-veri</MaterjaliNimi>
|
||||||
|
<Jarjenumber>1</Jarjenumber>
|
||||||
|
</Proov>
|
||||||
|
<Proov>
|
||||||
|
<ProovinouIdOID>1.3.6.1.4.1.28284.6.2.1.243.22</ProovinouIdOID>
|
||||||
|
<ProovinouId>A2</ProovinouId>
|
||||||
|
<MaterjaliTyypOID>1.3.6.1.4.1.28284.6.2.1.244.15</MaterjaliTyypOID>
|
||||||
|
<MaterjaliTyyp>119364003</MaterjaliTyyp>
|
||||||
|
<MaterjaliNimi>Seerum</MaterjaliNimi>
|
||||||
|
<Jarjenumber>2</Jarjenumber>
|
||||||
|
</Proov>
|
||||||
|
<UuringuGrupp>
|
||||||
|
<UuringuGruppId>TL10</UuringuGruppId>
|
||||||
|
<UuringuGruppNimi>Hematoloogilised uuringud</UuringuGruppNimi>
|
||||||
|
<Uuring>
|
||||||
|
<UuringuElement>
|
||||||
|
<UuringIdOID>2.16.840.1.113883.6.1</UuringIdOID>
|
||||||
|
<UuringId>57021-8</UuringId>
|
||||||
|
<TLyhend>B-CBC-5Diff</TLyhend>
|
||||||
|
<KNimetus>Hemogramm 5-osalise leukogrammiga</KNimetus>
|
||||||
|
<UuringNimi>Hemogramm</UuringNimi>
|
||||||
|
<TellijaUuringId>4522</TellijaUuringId>
|
||||||
|
</UuringuElement>
|
||||||
|
<ProoviJarjenumber>1</ProoviJarjenumber>
|
||||||
|
</Uuring>
|
||||||
|
</UuringuGrupp>
|
||||||
|
<UuringuGrupp>
|
||||||
|
<UuringuGruppId>TL50</UuringuGruppId>
|
||||||
|
<UuringuGruppNimi>Hormoon- jm. immuunuuringud</UuringuGruppNimi>
|
||||||
|
<Uuring>
|
||||||
|
<UuringuElement>
|
||||||
|
<UuringIdOID>2.16.840.1.113883.6.1</UuringIdOID>
|
||||||
|
<UuringId>2276-4</UuringId>
|
||||||
|
<TLyhend>S,P-Fer</TLyhend>
|
||||||
|
<KNimetus>Ferritiin</KNimetus>
|
||||||
|
<UuringNimi>Ferritiin</UuringNimi>
|
||||||
|
<TellijaUuringId>4605</TellijaUuringId>
|
||||||
|
</UuringuElement>
|
||||||
|
<ProoviJarjenumber>2</ProoviJarjenumber>
|
||||||
|
</Uuring>
|
||||||
|
</UuringuGrupp>
|
||||||
|
</Tellimus>
|
||||||
|
</Saadetis>
|
||||||
126
ostukorv-order-xml-premiumpakett3tootega.xml
Normal file
126
ostukorv-order-xml-premiumpakett3tootega.xml
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Saadetis xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:noNamespaceSchemaLocation="TellimusLOINC.xsd">
|
||||||
|
<Pais>
|
||||||
|
<Pakett versioon="20">OL</Pakett>
|
||||||
|
<Saatja>medreport</Saatja>
|
||||||
|
<Saaja>HTI</Saaja>
|
||||||
|
<Aeg>2025-09-04 14:17:12</Aeg>
|
||||||
|
<SaadetisId>1234567890</SaadetisId>
|
||||||
|
<Email>argo@medreport.ee</Email>
|
||||||
|
</Pais>
|
||||||
|
<Tellimus cito="EI">
|
||||||
|
<ValisTellimuseId>1234567890</ValisTellimuseId>
|
||||||
|
<!--<TellijaAsutus>-->
|
||||||
|
<Asutus tyyp="TELLIJA">
|
||||||
|
<AsutuseId>16381793</AsutuseId>
|
||||||
|
<AsutuseNimi>MedReport OÜ</AsutuseNimi>
|
||||||
|
<AsutuseKood>TSU</AsutuseKood>
|
||||||
|
<Telefon>+37258871517</Telefon>
|
||||||
|
</Asutus>
|
||||||
|
<!--<TeostajaAsutus>-->
|
||||||
|
<Asutus tyyp="TEOSTAJA">
|
||||||
|
<AsutuseId>11107913</AsutuseId>
|
||||||
|
<AsutuseNimi>Synlab HTI Tallinn</AsutuseNimi>
|
||||||
|
<AsutuseKood>SLA</AsutuseKood>
|
||||||
|
<AllyksuseNimi>Synlab HTI Tallinn</AllyksuseNimi>
|
||||||
|
<Telefon>+3723417123</Telefon>
|
||||||
|
</Asutus>
|
||||||
|
<!--<TellijaIsik>-->
|
||||||
|
<Personal tyyp="TELLIJA" jarjenumber="1">
|
||||||
|
<PersonalOID>1.3.6.1.4.1.28284.6.2.4.9</PersonalOID>
|
||||||
|
<PersonalKood>1234567890</PersonalKood>
|
||||||
|
<PersonalPerekonnaNimi>Doe</PersonalPerekonnaNimi>
|
||||||
|
<PersonalEesNimi>John</PersonalEesNimi>
|
||||||
|
<Telefon>+3721234567890</Telefon>
|
||||||
|
</Personal>
|
||||||
|
<TellijaMarkused></TellijaMarkused>
|
||||||
|
<Patsient>
|
||||||
|
<IsikukoodiOID>1.3.6.1.4.1.28284.6.2.2.1</IsikukoodiOID>
|
||||||
|
<Isikukood>1234567890</Isikukood>
|
||||||
|
<PerekonnaNimi>Doe</PerekonnaNimi>
|
||||||
|
<EesNimi>John</EesNimi>
|
||||||
|
<SynniAeg>1826-00-06</SynniAeg>
|
||||||
|
<SuguOID>1.3.6.1.4.1.28284.6.2.3.16.2</SuguOID>
|
||||||
|
<Sugu>M</Sugu>
|
||||||
|
</Patsient>
|
||||||
|
<Konfidentsiaalsus>
|
||||||
|
<PatsiendileOID>2.16.840.1.113883.5.25</PatsiendileOID>
|
||||||
|
<Patsiendile>N</Patsiendile>
|
||||||
|
<ArstileOID>1.3.6.1.4.1.28284.6.2.2.39.1</ArstileOID>
|
||||||
|
<Arstile>N</Arstile>
|
||||||
|
<EsindajaleOID>1.3.6.1.4.1.28284.6.2.2.37.1</EsindajaleOID>
|
||||||
|
<Esindajale>N</Esindajale>
|
||||||
|
</Konfidentsiaalsus>
|
||||||
|
|
||||||
|
<Proov>
|
||||||
|
<ProovinouIdOID>1.3.6.1.4.1.28284.6.2.1.243.22</ProovinouIdOID>
|
||||||
|
<ProovinouId>A9</ProovinouId>
|
||||||
|
<MaterjaliTyypOID>1.3.6.1.4.1.28284.6.2.1.244.15</MaterjaliTyypOID>
|
||||||
|
<MaterjaliTyyp>2491000181101</MaterjaliTyyp>
|
||||||
|
<MaterjaliNimi>Glükolüüsi inhibiitoriga plasma</MaterjaliNimi>
|
||||||
|
<Jarjenumber>1</Jarjenumber>
|
||||||
|
</Proov>
|
||||||
|
<Proov>
|
||||||
|
<ProovinouIdOID>1.3.6.1.4.1.28284.6.2.1.243.22</ProovinouIdOID>
|
||||||
|
<ProovinouId>A2</ProovinouId>
|
||||||
|
<MaterjaliTyypOID>1.3.6.1.4.1.28284.6.2.1.244.15</MaterjaliTyypOID>
|
||||||
|
<MaterjaliTyyp>119364003</MaterjaliTyyp>
|
||||||
|
<MaterjaliNimi>Seerum</MaterjaliNimi>
|
||||||
|
<Jarjenumber>2</Jarjenumber>
|
||||||
|
</Proov>
|
||||||
|
<Proov>
|
||||||
|
<ProovinouIdOID>1.3.6.1.4.1.28284.6.2.1.243.22</ProovinouIdOID>
|
||||||
|
<ProovinouId>A2</ProovinouId>
|
||||||
|
<MaterjaliTyypOID>1.3.6.1.4.1.28284.6.2.1.244.15</MaterjaliTyypOID>
|
||||||
|
<MaterjaliTyyp>119364003</MaterjaliTyyp>
|
||||||
|
<MaterjaliNimi>Seerum</MaterjaliNimi>
|
||||||
|
<Jarjenumber>3</Jarjenumber>
|
||||||
|
</Proov>
|
||||||
|
<UuringuGrupp>
|
||||||
|
<UuringuGruppId>TL40</UuringuGruppId>
|
||||||
|
<UuringuGruppNimi>Kliinilise keemia uuringud</UuringuGruppNimi>
|
||||||
|
<Uuring>
|
||||||
|
<UuringuElement>
|
||||||
|
<UuringIdOID>2.16.840.1.113883.6.1</UuringIdOID>
|
||||||
|
<UuringId>14771-0</UuringId>
|
||||||
|
<TLyhend>fS,fP-Gluc</TLyhend>
|
||||||
|
<KNimetus>Glükoos paastuseerumis/-plasmas</KNimetus>
|
||||||
|
<UuringNimi>Glükoos</UuringNimi>
|
||||||
|
<TellijaUuringId>4530</TellijaUuringId>
|
||||||
|
</UuringuElement>
|
||||||
|
<ProoviJarjenumber>1</ProoviJarjenumber>
|
||||||
|
</Uuring>
|
||||||
|
</UuringuGrupp>
|
||||||
|
<UuringuGrupp>
|
||||||
|
<UuringuGruppId>TL40</UuringuGruppId>
|
||||||
|
<UuringuGruppNimi>Kliinilise keemia uuringud</UuringuGruppNimi>
|
||||||
|
<Uuring>
|
||||||
|
<UuringuElement>
|
||||||
|
<UuringIdOID>2.16.840.1.113883.6.1</UuringIdOID>
|
||||||
|
<UuringId>14927-8</UuringId>
|
||||||
|
<TLyhend>S,P-Trigl</TLyhend>
|
||||||
|
<KNimetus>Triglütseriidid</KNimetus>
|
||||||
|
<UuringNimi>Triglütseriidid</UuringNimi>
|
||||||
|
<TellijaUuringId>4535</TellijaUuringId>
|
||||||
|
</UuringuElement>
|
||||||
|
<ProoviJarjenumber>2</ProoviJarjenumber>
|
||||||
|
</Uuring>
|
||||||
|
</UuringuGrupp>
|
||||||
|
<UuringuGrupp>
|
||||||
|
<UuringuGruppId>TL40</UuringuGruppId>
|
||||||
|
<UuringuGruppNimi>Kliinilise keemia uuringud</UuringuGruppNimi>
|
||||||
|
<Uuring>
|
||||||
|
<UuringuElement>
|
||||||
|
<UuringIdOID>2.16.840.1.113883.6.1</UuringIdOID>
|
||||||
|
<UuringId>14798-3</UuringId>
|
||||||
|
<TLyhend>S,P-Fe</TLyhend>
|
||||||
|
<KNimetus>Raud</KNimetus>
|
||||||
|
<UuringNimi>Raud</UuringNimi>
|
||||||
|
<TellijaUuringId>4570</TellijaUuringId>
|
||||||
|
</UuringuElement>
|
||||||
|
<ProoviJarjenumber>3</ProoviJarjenumber>
|
||||||
|
</Uuring>
|
||||||
|
</UuringuGrupp>
|
||||||
|
</Tellimus>
|
||||||
|
</Saadetis>
|
||||||
@@ -33,13 +33,13 @@
|
|||||||
"@hookform/resolvers": "^5.1.1",
|
"@hookform/resolvers": "^5.1.1",
|
||||||
"@kit/accounts": "workspace:*",
|
"@kit/accounts": "workspace:*",
|
||||||
"@kit/admin": "workspace:*",
|
"@kit/admin": "workspace:*",
|
||||||
"@kit/doctor": "workspace:*",
|
|
||||||
"@kit/analytics": "workspace:*",
|
"@kit/analytics": "workspace:*",
|
||||||
"@kit/auth": "workspace:*",
|
"@kit/auth": "workspace:*",
|
||||||
"@kit/billing": "workspace:*",
|
"@kit/billing": "workspace:*",
|
||||||
"@kit/billing-gateway": "workspace:*",
|
"@kit/billing-gateway": "workspace:*",
|
||||||
"@kit/cms": "workspace:*",
|
"@kit/cms": "workspace:*",
|
||||||
"@kit/database-webhooks": "workspace:*",
|
"@kit/database-webhooks": "workspace:*",
|
||||||
|
"@kit/doctor": "workspace:*",
|
||||||
"@kit/email-templates": "workspace:*",
|
"@kit/email-templates": "workspace:*",
|
||||||
"@kit/i18n": "workspace:*",
|
"@kit/i18n": "workspace:*",
|
||||||
"@kit/mailers": "workspace:*",
|
"@kit/mailers": "workspace:*",
|
||||||
@@ -69,6 +69,7 @@
|
|||||||
"fast-xml-parser": "^5.2.5",
|
"fast-xml-parser": "^5.2.5",
|
||||||
"isikukood": "3.1.7",
|
"isikukood": "3.1.7",
|
||||||
"jsonwebtoken": "9.0.2",
|
"jsonwebtoken": "9.0.2",
|
||||||
|
"libphonenumber-js": "^1.12.15",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"lucide-react": "^0.510.0",
|
"lucide-react": "^0.510.0",
|
||||||
"next": "15.3.2",
|
"next": "15.3.2",
|
||||||
@@ -82,7 +83,7 @@
|
|||||||
"sonner": "^2.0.5",
|
"sonner": "^2.0.5",
|
||||||
"tailwind-merge": "^3.3.1",
|
"tailwind-merge": "^3.3.1",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.9.2",
|
||||||
"zod": "^3.25.67"
|
"zod": "^4.1.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@hookform/resolvers": "^5.0.1",
|
"@hookform/resolvers": "^5.0.1",
|
||||||
|
|||||||
@@ -21,39 +21,25 @@ export const PaymentTypeSchema = z.enum(['one-time', 'recurring']);
|
|||||||
export const LineItemSchema = z
|
export const LineItemSchema = z
|
||||||
.object({
|
.object({
|
||||||
id: z
|
id: z
|
||||||
.string({
|
.string()
|
||||||
description:
|
.describe('Unique identifier for the line item. Defined by the Provider.')
|
||||||
'Unique identifier for the line item. Defined by the Provider.',
|
|
||||||
})
|
|
||||||
.min(1),
|
.min(1),
|
||||||
name: z
|
name: z
|
||||||
.string({
|
.string().describe('Name of the line item. Displayed to the user.')
|
||||||
description: 'Name of the line item. Displayed to the user.',
|
|
||||||
})
|
|
||||||
.min(1),
|
.min(1),
|
||||||
description: z
|
description: z
|
||||||
.string({
|
.string().describe('Description of the line item. Displayed to the user and will replace the auto-generated description inferred' +
|
||||||
description:
|
' from the line item. This is useful if you want to provide a more detailed description to the user.')
|
||||||
'Description of the line item. Displayed to the user and will replace the auto-generated description inferred' +
|
|
||||||
' from the line item. This is useful if you want to provide a more detailed description to the user.',
|
|
||||||
})
|
|
||||||
.optional(),
|
.optional(),
|
||||||
cost: z
|
cost: z
|
||||||
.number({
|
.number().describe('Cost of the line item. Displayed to the user.')
|
||||||
description: 'Cost of the line item. Displayed to the user.',
|
|
||||||
})
|
|
||||||
.min(0),
|
.min(0),
|
||||||
type: LineItemTypeSchema,
|
type: LineItemTypeSchema,
|
||||||
unit: z
|
unit: z
|
||||||
.string({
|
.string().describe('Unit of the line item. Displayed to the user. Example "seat" or "GB"')
|
||||||
description:
|
|
||||||
'Unit of the line item. Displayed to the user. Example "seat" or "GB"',
|
|
||||||
})
|
|
||||||
.optional(),
|
.optional(),
|
||||||
setupFee: z
|
setupFee: z
|
||||||
.number({
|
.number().describe(`Lemon Squeezy only: If true, in addition to the cost, a setup fee will be charged.`)
|
||||||
description: `Lemon Squeezy only: If true, in addition to the cost, a setup fee will be charged.`,
|
|
||||||
})
|
|
||||||
.positive()
|
.positive()
|
||||||
.optional(),
|
.optional(),
|
||||||
tiers: z
|
tiers: z
|
||||||
@@ -92,14 +78,10 @@ export const LineItemSchema = z
|
|||||||
export const PlanSchema = z
|
export const PlanSchema = z
|
||||||
.object({
|
.object({
|
||||||
id: z
|
id: z
|
||||||
.string({
|
.string().describe('Unique identifier for the plan. Defined by yourself.')
|
||||||
description: 'Unique identifier for the plan. Defined by yourself.',
|
|
||||||
})
|
|
||||||
.min(1),
|
.min(1),
|
||||||
name: z
|
name: z
|
||||||
.string({
|
.string().describe('Name of the plan. Displayed to the user.')
|
||||||
description: 'Name of the plan. Displayed to the user.',
|
|
||||||
})
|
|
||||||
.min(1),
|
.min(1),
|
||||||
interval: BillingIntervalSchema.optional(),
|
interval: BillingIntervalSchema.optional(),
|
||||||
custom: z.boolean().default(false).optional(),
|
custom: z.boolean().default(false).optional(),
|
||||||
@@ -124,10 +106,7 @@ export const PlanSchema = z
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
trialDays: z
|
trialDays: z
|
||||||
.number({
|
.number().describe('Number of days for the trial period. Leave empty for no trial.')
|
||||||
description:
|
|
||||||
'Number of days for the trial period. Leave empty for no trial.',
|
|
||||||
})
|
|
||||||
.positive()
|
.positive()
|
||||||
.optional(),
|
.optional(),
|
||||||
paymentType: PaymentTypeSchema,
|
paymentType: PaymentTypeSchema,
|
||||||
@@ -209,54 +188,34 @@ export const PlanSchema = z
|
|||||||
const ProductSchema = z
|
const ProductSchema = z
|
||||||
.object({
|
.object({
|
||||||
id: z
|
id: z
|
||||||
.string({
|
.string().describe('Unique identifier for the product. Defined by th Provider.')
|
||||||
description:
|
|
||||||
'Unique identifier for the product. Defined by th Provider.',
|
|
||||||
})
|
|
||||||
.min(1),
|
.min(1),
|
||||||
name: z
|
name: z
|
||||||
.string({
|
.string().describe('Name of the product. Displayed to the user.')
|
||||||
description: 'Name of the product. Displayed to the user.',
|
|
||||||
})
|
|
||||||
.min(1),
|
.min(1),
|
||||||
description: z
|
description: z
|
||||||
.string({
|
.string().describe('Description of the product. Displayed to the user.')
|
||||||
description: 'Description of the product. Displayed to the user.',
|
|
||||||
})
|
|
||||||
.min(1),
|
.min(1),
|
||||||
currency: z
|
currency: z
|
||||||
.string({
|
.string().describe('Currency code for the product. Displayed to the user.')
|
||||||
description: 'Currency code for the product. Displayed to the user.',
|
|
||||||
})
|
|
||||||
.min(3)
|
.min(3)
|
||||||
.max(3),
|
.max(3),
|
||||||
badge: z
|
badge: z
|
||||||
.string({
|
.string().describe('Badge for the product. Displayed to the user. Example: "Popular"')
|
||||||
description:
|
|
||||||
'Badge for the product. Displayed to the user. Example: "Popular"',
|
|
||||||
})
|
|
||||||
.optional(),
|
.optional(),
|
||||||
features: z
|
features: z
|
||||||
.array(
|
.array(
|
||||||
z.string({
|
z.string(),
|
||||||
description: 'Features of the product. Displayed to the user.',
|
).describe('Features of the product. Displayed to the user.')
|
||||||
}),
|
|
||||||
)
|
|
||||||
.nonempty(),
|
.nonempty(),
|
||||||
enableDiscountField: z
|
enableDiscountField: z
|
||||||
.boolean({
|
.boolean().describe('Enable discount field for the product in the checkout.')
|
||||||
description: 'Enable discount field for the product in the checkout.',
|
|
||||||
})
|
|
||||||
.optional(),
|
.optional(),
|
||||||
highlighted: z
|
highlighted: z
|
||||||
.boolean({
|
.boolean().describe('Highlight this product. Displayed to the user.')
|
||||||
description: 'Highlight this product. Displayed to the user.',
|
|
||||||
})
|
|
||||||
.optional(),
|
.optional(),
|
||||||
hidden: z
|
hidden: z
|
||||||
.boolean({
|
.boolean().describe('Hide this product from being displayed to users.')
|
||||||
description: 'Hide this product from being displayed to users.',
|
|
||||||
})
|
|
||||||
.optional(),
|
.optional(),
|
||||||
plans: z.array(PlanSchema),
|
plans: z.array(PlanSchema),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
export const ReportBillingUsageSchema = z.object({
|
export const ReportBillingUsageSchema = z.object({
|
||||||
id: z.string({
|
id: z.string().describe('The id of the usage record. For Stripe a customer ID, for LS a subscription item ID.'),
|
||||||
description:
|
|
||||||
'The id of the usage record. For Stripe a customer ID, for LS a subscription item ID.',
|
|
||||||
}),
|
|
||||||
eventName: z
|
eventName: z
|
||||||
.string({
|
.string()
|
||||||
description: 'The name of the event that triggered the usage',
|
.describe('The name of the event that triggered the usage')
|
||||||
})
|
|
||||||
.optional(),
|
.optional(),
|
||||||
usage: z.object({
|
usage: z.object({
|
||||||
quantity: z.number(),
|
quantity: z.number(),
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ import { z } from 'zod';
|
|||||||
export const UpdateHealthBenefitSchema = z.object({
|
export const UpdateHealthBenefitSchema = z.object({
|
||||||
occurance: z
|
occurance: z
|
||||||
.string({
|
.string({
|
||||||
required_error: 'Occurance is required',
|
error: 'Occurance is required',
|
||||||
})
|
})
|
||||||
.nonempty(),
|
.nonempty(),
|
||||||
amount: z.number({ required_error: 'Amount is required' }),
|
amount: z.number({ error: 'Amount is required' }),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ export const MontonioServerEnvSchema = z
|
|||||||
.object({
|
.object({
|
||||||
secretKey: z
|
secretKey: z
|
||||||
.string({
|
.string({
|
||||||
required_error: `Please provide the variable MONTONIO_SECRET_KEY`,
|
error: `Please provide the variable MONTONIO_SECRET_KEY`,
|
||||||
})
|
})
|
||||||
.min(1),
|
.min(1),
|
||||||
apiUrl: z
|
apiUrl: z
|
||||||
.string({
|
.string({
|
||||||
required_error: `Please provide the variable MONTONIO_API_URL`,
|
error: `Please provide the variable MONTONIO_API_URL`,
|
||||||
})
|
})
|
||||||
.min(1),
|
.min(1),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ export const StripeServerEnvSchema = z
|
|||||||
.object({
|
.object({
|
||||||
secretKey: z
|
secretKey: z
|
||||||
.string({
|
.string({
|
||||||
required_error: `Please provide the variable STRIPE_SECRET_KEY`,
|
error: `Please provide the variable STRIPE_SECRET_KEY`,
|
||||||
})
|
})
|
||||||
.min(1),
|
.min(1),
|
||||||
webhooksSecret: z
|
webhooksSecret: z
|
||||||
.string({
|
.string({
|
||||||
required_error: `Please provide the variable STRIPE_WEBHOOK_SECRET`,
|
error: `Please provide the variable STRIPE_WEBHOOK_SECRET`,
|
||||||
})
|
})
|
||||||
.min(1),
|
.min(1),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import { DatabaseWebhookVerifierService } from './database-webhook-verifier.serv
|
|||||||
|
|
||||||
const webhooksSecret = z
|
const webhooksSecret = z
|
||||||
.string({
|
.string({
|
||||||
description: `The secret used to verify the webhook signature`,
|
error: `Provide the variable SUPABASE_DB_WEBHOOK_SECRET. This is used to authenticate the webhook event from Supabase.`,
|
||||||
required_error: `Provide the variable SUPABASE_DB_WEBHOOK_SECRET. This is used to authenticate the webhook event from Supabase.`,
|
|
||||||
})
|
})
|
||||||
|
.describe(`The secret used to verify the webhook signature`,)
|
||||||
.min(1)
|
.min(1)
|
||||||
.parse(process.env.SUPABASE_DB_WEBHOOK_SECRET);
|
.parse(process.env.SUPABASE_DB_WEBHOOK_SECRET);
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
export * from './user-workspace-context';
|
export * from './user-workspace-context';
|
||||||
|
export * from './personal-account-settings/mfa/multi-factor-auth-list'
|
||||||
|
export * from './personal-account-settings/mfa/multi-factor-auth-setup-dialog'
|
||||||
|
|||||||
@@ -79,15 +79,9 @@ export function PersonalAccountDropdown({
|
|||||||
}) {
|
}) {
|
||||||
const { data: personalAccountData } = usePersonalAccountData(user.id);
|
const { data: personalAccountData } = usePersonalAccountData(user.id);
|
||||||
|
|
||||||
const signedInAsLabel = useMemo(() => {
|
const { name, last_name } = personalAccountData ?? {};
|
||||||
const email = user?.email ?? undefined;
|
const firstNameLabel = toTitleCase(name) ?? '-';
|
||||||
const phone = user?.phone ?? undefined;
|
const fullNameLabel = name && last_name ? toTitleCase(`${name} ${last_name}`) : '-';
|
||||||
|
|
||||||
return email ?? phone;
|
|
||||||
}, [user]);
|
|
||||||
|
|
||||||
const displayName =
|
|
||||||
personalAccountData?.name ?? account?.name ?? user?.email ?? '';
|
|
||||||
|
|
||||||
const hasTotpFactor = useMemo(() => {
|
const hasTotpFactor = useMemo(() => {
|
||||||
const factors = user?.factors ?? [];
|
const factors = user?.factors ?? [];
|
||||||
@@ -101,14 +95,14 @@ export function PersonalAccountDropdown({
|
|||||||
personalAccountData?.application_role === ApplicationRoleEnum.SuperAdmin;
|
personalAccountData?.application_role === ApplicationRoleEnum.SuperAdmin;
|
||||||
|
|
||||||
return hasAdminRole && hasTotpFactor;
|
return hasAdminRole && hasTotpFactor;
|
||||||
}, [user, personalAccountData, hasTotpFactor]);
|
}, [personalAccountData, hasTotpFactor]);
|
||||||
|
|
||||||
const isDoctor = useMemo(() => {
|
const isDoctor = useMemo(() => {
|
||||||
const hasDoctorRole =
|
const hasDoctorRole =
|
||||||
personalAccountData?.application_role === ApplicationRoleEnum.Doctor;
|
personalAccountData?.application_role === ApplicationRoleEnum.Doctor;
|
||||||
|
|
||||||
return hasDoctorRole && hasTotpFactor;
|
return hasDoctorRole && hasTotpFactor;
|
||||||
}, [user, personalAccountData, hasTotpFactor]);
|
}, [personalAccountData, hasTotpFactor]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
@@ -128,7 +122,7 @@ export function PersonalAccountDropdown({
|
|||||||
<ProfileAvatar
|
<ProfileAvatar
|
||||||
className={'rounded-md'}
|
className={'rounded-md'}
|
||||||
fallbackClassName={'rounded-md border'}
|
fallbackClassName={'rounded-md border'}
|
||||||
displayName={displayName ?? user?.email ?? ''}
|
displayName={firstNameLabel}
|
||||||
pictureUrl={personalAccountData?.picture_url}
|
pictureUrl={personalAccountData?.picture_url}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@@ -142,7 +136,7 @@ export function PersonalAccountDropdown({
|
|||||||
data-test={'account-dropdown-display-name'}
|
data-test={'account-dropdown-display-name'}
|
||||||
className={'truncate text-sm'}
|
className={'truncate text-sm'}
|
||||||
>
|
>
|
||||||
{toTitleCase(displayName)}
|
{firstNameLabel}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -164,7 +158,7 @@ export function PersonalAccountDropdown({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<span className={'block truncate'}>{signedInAsLabel}</span>
|
<span className={'block truncate'}>{fullNameLabel}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
|
|||||||
@@ -1,208 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { useTranslation } from 'react-i18next';
|
|
||||||
|
|
||||||
import {
|
|
||||||
Card,
|
|
||||||
CardContent,
|
|
||||||
CardDescription,
|
|
||||||
CardHeader,
|
|
||||||
CardTitle,
|
|
||||||
} from '@kit/ui/card';
|
|
||||||
import { If } from '@kit/ui/if';
|
|
||||||
import { LanguageSelector } from '@kit/ui/language-selector';
|
|
||||||
import { LoadingOverlay } from '@kit/ui/loading-overlay';
|
|
||||||
import { Trans } from '@kit/ui/trans';
|
|
||||||
|
|
||||||
import { usePersonalAccountData } from '../../hooks/use-personal-account-data';
|
|
||||||
import { AccountDangerZone } from './account-danger-zone';
|
|
||||||
import ConsentToggle from './consent/consent-toggle';
|
|
||||||
import { UpdateEmailFormContainer } from './email/update-email-form-container';
|
|
||||||
import { MultiFactorAuthFactorsList } from './mfa/multi-factor-auth-list';
|
|
||||||
import { UpdatePasswordFormContainer } from './password/update-password-container';
|
|
||||||
import { UpdateAccountDetailsFormContainer } from './update-account-details-form-container';
|
|
||||||
import { UpdateAccountImageContainer } from './update-account-image-container';
|
|
||||||
|
|
||||||
export function PersonalAccountSettingsContainer(
|
|
||||||
props: React.PropsWithChildren<{
|
|
||||||
userId: string;
|
|
||||||
|
|
||||||
features: {
|
|
||||||
enableAccountDeletion: boolean;
|
|
||||||
enablePasswordUpdate: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
paths: {
|
|
||||||
callback: string;
|
|
||||||
};
|
|
||||||
}>,
|
|
||||||
) {
|
|
||||||
const supportsLanguageSelection = useSupportMultiLanguage();
|
|
||||||
const user = usePersonalAccountData(props.userId);
|
|
||||||
|
|
||||||
if (!user.data || user.isPending) {
|
|
||||||
return <LoadingOverlay fullPage />;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className={'flex w-full flex-col space-y-4 pb-32'}>
|
|
||||||
<Card>
|
|
||||||
<CardHeader>
|
|
||||||
<CardTitle>
|
|
||||||
<Trans i18nKey={'account:accountImage'} />
|
|
||||||
</CardTitle>
|
|
||||||
|
|
||||||
<CardDescription>
|
|
||||||
<Trans i18nKey={'account:accountImageDescription'} />
|
|
||||||
</CardDescription>
|
|
||||||
</CardHeader>
|
|
||||||
|
|
||||||
<CardContent>
|
|
||||||
<UpdateAccountImageContainer
|
|
||||||
user={{
|
|
||||||
pictureUrl: user.data.picture_url,
|
|
||||||
id: user.data.id,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
<Card>
|
|
||||||
<CardHeader>
|
|
||||||
<CardTitle>
|
|
||||||
<Trans i18nKey={'account:name'} />
|
|
||||||
</CardTitle>
|
|
||||||
|
|
||||||
<CardDescription>
|
|
||||||
<Trans i18nKey={'account:nameDescription'} />
|
|
||||||
</CardDescription>
|
|
||||||
</CardHeader>
|
|
||||||
|
|
||||||
<CardContent>
|
|
||||||
<UpdateAccountDetailsFormContainer user={user.data} />
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
<If condition={supportsLanguageSelection}>
|
|
||||||
<Card>
|
|
||||||
<CardHeader>
|
|
||||||
<CardTitle>
|
|
||||||
<Trans i18nKey={'account:language'} />
|
|
||||||
</CardTitle>
|
|
||||||
|
|
||||||
<CardDescription>
|
|
||||||
<Trans i18nKey={'account:languageDescription'} />
|
|
||||||
</CardDescription>
|
|
||||||
</CardHeader>
|
|
||||||
|
|
||||||
<CardContent>
|
|
||||||
<LanguageSelector />
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</If>
|
|
||||||
|
|
||||||
<Card>
|
|
||||||
<CardHeader>
|
|
||||||
<CardTitle>
|
|
||||||
<Trans i18nKey={'account:updateEmailCardTitle'} />
|
|
||||||
</CardTitle>
|
|
||||||
|
|
||||||
<CardDescription>
|
|
||||||
<Trans i18nKey={'account:updateEmailCardDescription'} />
|
|
||||||
</CardDescription>
|
|
||||||
</CardHeader>
|
|
||||||
|
|
||||||
<CardContent>
|
|
||||||
<UpdateEmailFormContainer callbackPath={props.paths.callback} />
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
<If condition={props.features.enablePasswordUpdate}>
|
|
||||||
<Card>
|
|
||||||
<CardHeader>
|
|
||||||
<CardTitle>
|
|
||||||
<Trans i18nKey={'account:updatePasswordCardTitle'} />
|
|
||||||
</CardTitle>
|
|
||||||
|
|
||||||
<CardDescription>
|
|
||||||
<Trans i18nKey={'account:updatePasswordCardDescription'} />
|
|
||||||
</CardDescription>
|
|
||||||
</CardHeader>
|
|
||||||
|
|
||||||
<CardContent>
|
|
||||||
<UpdatePasswordFormContainer callbackPath={props.paths.callback} />
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</If>
|
|
||||||
|
|
||||||
<Card>
|
|
||||||
<CardHeader>
|
|
||||||
<CardTitle>
|
|
||||||
<Trans i18nKey={'account:multiFactorAuth'} />
|
|
||||||
</CardTitle>
|
|
||||||
|
|
||||||
<CardDescription>
|
|
||||||
<Trans i18nKey={'account:multiFactorAuthDescription'} />
|
|
||||||
</CardDescription>
|
|
||||||
</CardHeader>
|
|
||||||
|
|
||||||
<CardContent>
|
|
||||||
<MultiFactorAuthFactorsList userId={props.userId} />
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
<Card>
|
|
||||||
<CardHeader>
|
|
||||||
<div className="flex justify-between">
|
|
||||||
<div>
|
|
||||||
<p className="font-medium">
|
|
||||||
<Trans
|
|
||||||
i18nKey={'account:consentToAnonymizedCompanyData.label'}
|
|
||||||
/>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<CardDescription>
|
|
||||||
<Trans
|
|
||||||
i18nKey={'account:consentToAnonymizedCompanyData.description'}
|
|
||||||
/>
|
|
||||||
</CardDescription>
|
|
||||||
</div>
|
|
||||||
<ConsentToggle
|
|
||||||
userId={props.userId}
|
|
||||||
initialState={
|
|
||||||
!!user.data.has_consent_anonymized_company_statistics
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</CardHeader>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
<If condition={props.features.enableAccountDeletion}>
|
|
||||||
<Card className={'border-destructive'}>
|
|
||||||
<CardHeader>
|
|
||||||
<CardTitle>
|
|
||||||
<Trans i18nKey={'account:dangerZone'} />
|
|
||||||
</CardTitle>
|
|
||||||
|
|
||||||
<CardDescription>
|
|
||||||
<Trans i18nKey={'account:dangerZoneDescription'} />
|
|
||||||
</CardDescription>
|
|
||||||
</CardHeader>
|
|
||||||
|
|
||||||
<CardContent>
|
|
||||||
<AccountDangerZone />
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</If>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function useSupportMultiLanguage() {
|
|
||||||
const { i18n } = useTranslation();
|
|
||||||
const langs = (i18n?.options?.supportedLngs as string[]) ?? [];
|
|
||||||
|
|
||||||
const supportedLangs = langs.filter((lang) => lang !== 'cimode');
|
|
||||||
|
|
||||||
return supportedLangs.length > 1;
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
import { useState } from 'react';
|
|
||||||
|
|
||||||
import { toast } from 'sonner';
|
|
||||||
|
|
||||||
import { Switch } from '@kit/ui/switch';
|
|
||||||
import { Trans } from '@kit/ui/trans';
|
|
||||||
|
|
||||||
import { useRevalidatePersonalAccountDataQuery } from '../../../hooks/use-personal-account-data';
|
|
||||||
import { useUpdateAccountData } from '../../../hooks/use-update-account';
|
|
||||||
|
|
||||||
// This is temporary. When the profile views are ready, all account values included in the form will be updated together on form submit.
|
|
||||||
export default function ConsentToggle({
|
|
||||||
userId,
|
|
||||||
initialState,
|
|
||||||
}: {
|
|
||||||
userId: string;
|
|
||||||
initialState: boolean;
|
|
||||||
}) {
|
|
||||||
const [isConsent, setIsConsent] = useState(initialState);
|
|
||||||
const updateAccountMutation = useUpdateAccountData(userId);
|
|
||||||
const revalidateUserDataQuery = useRevalidatePersonalAccountDataQuery();
|
|
||||||
|
|
||||||
const updateConsent = (consent: boolean) => {
|
|
||||||
const promise = updateAccountMutation
|
|
||||||
.mutateAsync({
|
|
||||||
has_consent_anonymized_company_statistics: consent,
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
revalidateUserDataQuery(userId);
|
|
||||||
});
|
|
||||||
|
|
||||||
return toast.promise(() => promise, {
|
|
||||||
success: <Trans i18nKey={'account:updateConsentSuccess'} />,
|
|
||||||
error: <Trans i18nKey={'account:updateConsentError'} />,
|
|
||||||
loading: <Trans i18nKey={'account:updateConsentLoading'} />,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
return (
|
|
||||||
<Switch
|
|
||||||
checked={isConsent}
|
|
||||||
onCheckedChange={setIsConsent}
|
|
||||||
onClick={() => updateConsent(!isConsent)}
|
|
||||||
disabled={updateAccountMutation.isPending}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -12,6 +12,7 @@ import { toast } from 'sonner';
|
|||||||
|
|
||||||
import { useFetchAuthFactors } from '@kit/supabase/hooks/use-fetch-mfa-factors';
|
import { useFetchAuthFactors } from '@kit/supabase/hooks/use-fetch-mfa-factors';
|
||||||
import { useSupabase } from '@kit/supabase/hooks/use-supabase';
|
import { useSupabase } from '@kit/supabase/hooks/use-supabase';
|
||||||
|
import { useUser } from '@kit/supabase/hooks/use-user';
|
||||||
import { useFactorsMutationKey } from '@kit/supabase/hooks/use-user-factors-mutation-key';
|
import { useFactorsMutationKey } from '@kit/supabase/hooks/use-user-factors-mutation-key';
|
||||||
import { Alert, AlertDescription, AlertTitle } from '@kit/ui/alert';
|
import { Alert, AlertDescription, AlertTitle } from '@kit/ui/alert';
|
||||||
import {
|
import {
|
||||||
@@ -46,13 +47,18 @@ import { Trans } from '@kit/ui/trans';
|
|||||||
|
|
||||||
import { MultiFactorAuthSetupDialog } from './multi-factor-auth-setup-dialog';
|
import { MultiFactorAuthSetupDialog } from './multi-factor-auth-setup-dialog';
|
||||||
|
|
||||||
export function MultiFactorAuthFactorsList(props: { userId: string }) {
|
export function MultiFactorAuthFactorsList() {
|
||||||
|
const { data: user } = useUser();
|
||||||
|
if (!user?.id) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={'flex flex-col space-y-4'}>
|
<div className={'flex flex-col space-y-4'}>
|
||||||
<FactorsTableContainer userId={props.userId} />
|
<FactorsTableContainer userId={user?.id} />
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<MultiFactorAuthSetupDialog userId={props.userId} />
|
<MultiFactorAuthSetupDialog userId={user?.id} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { useUser } from '@kit/supabase/hooks/use-user';
|
|
||||||
import { Alert } from '@kit/ui/alert';
|
|
||||||
import { LoadingOverlay } from '@kit/ui/loading-overlay';
|
|
||||||
import { Trans } from '@kit/ui/trans';
|
|
||||||
|
|
||||||
import { UpdatePasswordForm } from './update-password-form';
|
|
||||||
|
|
||||||
export function UpdatePasswordFormContainer(
|
|
||||||
props: React.PropsWithChildren<{
|
|
||||||
callbackPath: string;
|
|
||||||
}>,
|
|
||||||
) {
|
|
||||||
const { data: user, isPending } = useUser();
|
|
||||||
|
|
||||||
if (isPending) {
|
|
||||||
return <LoadingOverlay fullPage={false} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!user) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const canUpdatePassword = user.identities?.some(
|
|
||||||
(item) => item.provider === `email`,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!canUpdatePassword) {
|
|
||||||
return <WarnCannotUpdatePasswordAlert />;
|
|
||||||
}
|
|
||||||
|
|
||||||
return <UpdatePasswordForm callbackPath={props.callbackPath} user={user} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
function WarnCannotUpdatePasswordAlert() {
|
|
||||||
return (
|
|
||||||
<Alert variant={'warning'}>
|
|
||||||
<Trans i18nKey={'account:cannotUpdatePassword'} />
|
|
||||||
</Alert>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,206 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { useState } from 'react';
|
|
||||||
|
|
||||||
import type { User } from '@supabase/supabase-js';
|
|
||||||
|
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
|
||||||
import { ExclamationTriangleIcon } from '@radix-ui/react-icons';
|
|
||||||
import { Check } from 'lucide-react';
|
|
||||||
import { useForm } from 'react-hook-form';
|
|
||||||
import { useTranslation } from 'react-i18next';
|
|
||||||
import { toast } from 'sonner';
|
|
||||||
|
|
||||||
import { useUpdateUser } from '@kit/supabase/hooks/use-update-user-mutation';
|
|
||||||
import { Alert, AlertDescription, AlertTitle } from '@kit/ui/alert';
|
|
||||||
import { Button } from '@kit/ui/button';
|
|
||||||
import {
|
|
||||||
Form,
|
|
||||||
FormControl,
|
|
||||||
FormDescription,
|
|
||||||
FormField,
|
|
||||||
FormItem,
|
|
||||||
FormLabel,
|
|
||||||
FormMessage,
|
|
||||||
} from '@kit/ui/form';
|
|
||||||
import { If } from '@kit/ui/if';
|
|
||||||
import { Input } from '@kit/ui/input';
|
|
||||||
import { Label } from '@kit/ui/label';
|
|
||||||
import { Trans } from '@kit/ui/trans';
|
|
||||||
|
|
||||||
import { PasswordUpdateSchema } from '../../../schema/update-password.schema';
|
|
||||||
|
|
||||||
export const UpdatePasswordForm = ({
|
|
||||||
user,
|
|
||||||
callbackPath,
|
|
||||||
}: {
|
|
||||||
user: User;
|
|
||||||
callbackPath: string;
|
|
||||||
}) => {
|
|
||||||
const { t } = useTranslation('account');
|
|
||||||
const updateUserMutation = useUpdateUser();
|
|
||||||
const [needsReauthentication, setNeedsReauthentication] = useState(false);
|
|
||||||
|
|
||||||
const updatePasswordFromCredential = (password: string) => {
|
|
||||||
const redirectTo = [window.location.origin, callbackPath].join('');
|
|
||||||
|
|
||||||
const promise = updateUserMutation
|
|
||||||
.mutateAsync({ password, redirectTo })
|
|
||||||
.catch((error) => {
|
|
||||||
if (
|
|
||||||
typeof error === 'string' &&
|
|
||||||
error?.includes('Password update requires reauthentication')
|
|
||||||
) {
|
|
||||||
setNeedsReauthentication(true);
|
|
||||||
} else {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
toast.promise(() => promise, {
|
|
||||||
success: t(`updatePasswordSuccess`),
|
|
||||||
error: t(`updatePasswordError`),
|
|
||||||
loading: t(`updatePasswordLoading`),
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const updatePasswordCallback = async ({
|
|
||||||
newPassword,
|
|
||||||
}: {
|
|
||||||
newPassword: string;
|
|
||||||
}) => {
|
|
||||||
const email = user.email;
|
|
||||||
|
|
||||||
// if the user does not have an email assigned, it's possible they
|
|
||||||
// don't have an email/password factor linked, and the UI is out of sync
|
|
||||||
if (!email) {
|
|
||||||
return Promise.reject(t(`cannotUpdatePassword`));
|
|
||||||
}
|
|
||||||
|
|
||||||
updatePasswordFromCredential(newPassword);
|
|
||||||
};
|
|
||||||
|
|
||||||
const form = useForm({
|
|
||||||
resolver: zodResolver(
|
|
||||||
PasswordUpdateSchema.withTranslation(t('passwordNotMatching')),
|
|
||||||
),
|
|
||||||
defaultValues: {
|
|
||||||
newPassword: '',
|
|
||||||
repeatPassword: '',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Form {...form}>
|
|
||||||
<form
|
|
||||||
data-test={'account-password-form'}
|
|
||||||
onSubmit={form.handleSubmit(updatePasswordCallback)}
|
|
||||||
>
|
|
||||||
<div className={'flex flex-col space-y-4'}>
|
|
||||||
<If condition={updateUserMutation.data}>
|
|
||||||
<SuccessAlert />
|
|
||||||
</If>
|
|
||||||
|
|
||||||
<If condition={needsReauthentication}>
|
|
||||||
<NeedsReauthenticationAlert />
|
|
||||||
</If>
|
|
||||||
|
|
||||||
<FormField
|
|
||||||
name={'newPassword'}
|
|
||||||
render={({ field }) => {
|
|
||||||
return (
|
|
||||||
<FormItem>
|
|
||||||
<FormLabel>
|
|
||||||
<Label>
|
|
||||||
<Trans i18nKey={'account:newPassword'} />
|
|
||||||
</Label>
|
|
||||||
</FormLabel>
|
|
||||||
|
|
||||||
<FormControl>
|
|
||||||
<Input
|
|
||||||
data-test={'account-password-form-password-input'}
|
|
||||||
autoComplete={'new-password'}
|
|
||||||
required
|
|
||||||
type={'password'}
|
|
||||||
{...field}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<FormField
|
|
||||||
name={'repeatPassword'}
|
|
||||||
render={({ field }) => {
|
|
||||||
return (
|
|
||||||
<FormItem>
|
|
||||||
<FormLabel>
|
|
||||||
<Label>
|
|
||||||
<Trans i18nKey={'account:repeatPassword'} />
|
|
||||||
</Label>
|
|
||||||
</FormLabel>
|
|
||||||
|
|
||||||
<FormControl>
|
|
||||||
<Input
|
|
||||||
data-test={'account-password-form-repeat-password-input'}
|
|
||||||
required
|
|
||||||
type={'password'}
|
|
||||||
{...field}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
|
|
||||||
<FormDescription>
|
|
||||||
<Trans i18nKey={'account:repeatPasswordDescription'} />
|
|
||||||
</FormDescription>
|
|
||||||
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<Button disabled={updateUserMutation.isPending}>
|
|
||||||
<Trans i18nKey={'account:updatePasswordSubmitLabel'} />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</Form>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
function SuccessAlert() {
|
|
||||||
return (
|
|
||||||
<Alert variant={'success'}>
|
|
||||||
<Check className={'h-4'} />
|
|
||||||
|
|
||||||
<AlertTitle>
|
|
||||||
<Trans i18nKey={'account:updatePasswordSuccess'} />
|
|
||||||
</AlertTitle>
|
|
||||||
|
|
||||||
<AlertDescription>
|
|
||||||
<Trans i18nKey={'account:updatePasswordSuccessMessage'} />
|
|
||||||
</AlertDescription>
|
|
||||||
</Alert>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function NeedsReauthenticationAlert() {
|
|
||||||
return (
|
|
||||||
<Alert variant={'warning'}>
|
|
||||||
<ExclamationTriangleIcon className={'h-4'} />
|
|
||||||
|
|
||||||
<AlertTitle>
|
|
||||||
<Trans i18nKey={'account:needsReauthentication'} />
|
|
||||||
</AlertTitle>
|
|
||||||
|
|
||||||
<AlertDescription>
|
|
||||||
<Trans i18nKey={'account:needsReauthenticationDescription'} />
|
|
||||||
</AlertDescription>
|
|
||||||
</Alert>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { useRevalidatePersonalAccountDataQuery } from '../../hooks/use-personal-account-data';
|
|
||||||
import { UpdateAccountDetailsForm } from './update-account-details-form';
|
|
||||||
|
|
||||||
export function UpdateAccountDetailsFormContainer({
|
|
||||||
user,
|
|
||||||
}: {
|
|
||||||
user: {
|
|
||||||
name: string | null;
|
|
||||||
id: string;
|
|
||||||
};
|
|
||||||
}) {
|
|
||||||
const revalidateUserDataQuery = useRevalidatePersonalAccountDataQuery();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<UpdateAccountDetailsForm
|
|
||||||
displayName={user.name ?? ''}
|
|
||||||
userId={user.id}
|
|
||||||
onUpdate={() => revalidateUserDataQuery(user.id)}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
|
||||||
import { useForm } from 'react-hook-form';
|
|
||||||
import { useTranslation } from 'react-i18next';
|
|
||||||
import { toast } from 'sonner';
|
|
||||||
|
|
||||||
import { Database } from '@kit/supabase/database';
|
|
||||||
import { Button } from '@kit/ui/button';
|
|
||||||
import {
|
|
||||||
Form,
|
|
||||||
FormControl,
|
|
||||||
FormField,
|
|
||||||
FormItem,
|
|
||||||
FormLabel,
|
|
||||||
FormMessage,
|
|
||||||
} from '@kit/ui/form';
|
|
||||||
import { Input } from '@kit/ui/input';
|
|
||||||
import { Trans } from '@kit/ui/trans';
|
|
||||||
|
|
||||||
import { useUpdateAccountData } from '../../hooks/use-update-account';
|
|
||||||
import { AccountDetailsSchema } from '../../schema/account-details.schema';
|
|
||||||
|
|
||||||
type UpdateUserDataParams =
|
|
||||||
Database['medreport']['Tables']['accounts']['Update'];
|
|
||||||
|
|
||||||
export function UpdateAccountDetailsForm({
|
|
||||||
displayName,
|
|
||||||
onUpdate,
|
|
||||||
userId,
|
|
||||||
}: {
|
|
||||||
displayName: string;
|
|
||||||
userId: string;
|
|
||||||
onUpdate: (user: Partial<UpdateUserDataParams>) => void;
|
|
||||||
}) {
|
|
||||||
const updateAccountMutation = useUpdateAccountData(userId);
|
|
||||||
const { t } = useTranslation('account');
|
|
||||||
|
|
||||||
const form = useForm({
|
|
||||||
resolver: zodResolver(AccountDetailsSchema),
|
|
||||||
defaultValues: {
|
|
||||||
displayName,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const onSubmit = ({ displayName }: { displayName: string }) => {
|
|
||||||
const data = { name: displayName };
|
|
||||||
|
|
||||||
const promise = updateAccountMutation.mutateAsync(data).then(() => {
|
|
||||||
onUpdate(data);
|
|
||||||
});
|
|
||||||
|
|
||||||
return toast.promise(() => promise, {
|
|
||||||
success: t(`updateProfileSuccess`),
|
|
||||||
error: t(`updateProfileError`),
|
|
||||||
loading: t(`updateProfileLoading`),
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className={'flex flex-col space-y-8'}>
|
|
||||||
<Form {...form}>
|
|
||||||
<form
|
|
||||||
data-test={'update-account-name-form'}
|
|
||||||
className={'flex flex-col space-y-4'}
|
|
||||||
onSubmit={form.handleSubmit(onSubmit)}
|
|
||||||
>
|
|
||||||
<FormField
|
|
||||||
name={'displayName'}
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem>
|
|
||||||
<FormLabel>
|
|
||||||
<Trans i18nKey={'account:name'} />
|
|
||||||
</FormLabel>
|
|
||||||
|
|
||||||
<FormControl>
|
|
||||||
<Input
|
|
||||||
data-test={'account-display-name'}
|
|
||||||
minLength={2}
|
|
||||||
placeholder={''}
|
|
||||||
maxLength={100}
|
|
||||||
{...field}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<Button disabled={updateAccountMutation.isPending}>
|
|
||||||
<Trans i18nKey={'account:updateProfileSubmitLabel'} />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</Form>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,168 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { useCallback } from 'react';
|
|
||||||
|
|
||||||
import type { SupabaseClient } from '@supabase/supabase-js';
|
|
||||||
|
|
||||||
import { useTranslation } from 'react-i18next';
|
|
||||||
import { toast } from 'sonner';
|
|
||||||
|
|
||||||
import { Database } from '@kit/supabase/database';
|
|
||||||
import { useSupabase } from '@kit/supabase/hooks/use-supabase';
|
|
||||||
import { ImageUploader } from '@kit/ui/image-uploader';
|
|
||||||
import { Trans } from '@kit/ui/trans';
|
|
||||||
|
|
||||||
import { useRevalidatePersonalAccountDataQuery } from '../../hooks/use-personal-account-data';
|
|
||||||
|
|
||||||
const AVATARS_BUCKET = 'account_image';
|
|
||||||
|
|
||||||
export function UpdateAccountImageContainer({
|
|
||||||
user,
|
|
||||||
}: {
|
|
||||||
user: {
|
|
||||||
pictureUrl: string | null;
|
|
||||||
id: string;
|
|
||||||
};
|
|
||||||
}) {
|
|
||||||
const revalidateUserDataQuery = useRevalidatePersonalAccountDataQuery();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<UploadProfileAvatarForm
|
|
||||||
pictureUrl={user.pictureUrl ?? null}
|
|
||||||
userId={user.id}
|
|
||||||
onAvatarUpdated={() => revalidateUserDataQuery(user.id)}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function UploadProfileAvatarForm(props: {
|
|
||||||
pictureUrl: string | null;
|
|
||||||
userId: string;
|
|
||||||
onAvatarUpdated: () => void;
|
|
||||||
}) {
|
|
||||||
const client = useSupabase();
|
|
||||||
const { t } = useTranslation('account');
|
|
||||||
|
|
||||||
const createToaster = useCallback(
|
|
||||||
(promise: () => Promise<unknown>) => {
|
|
||||||
return toast.promise(promise, {
|
|
||||||
success: t(`updateProfileSuccess`),
|
|
||||||
error: t(`updateProfileError`),
|
|
||||||
loading: t(`updateProfileLoading`),
|
|
||||||
});
|
|
||||||
},
|
|
||||||
[t],
|
|
||||||
);
|
|
||||||
|
|
||||||
const onValueChange = useCallback(
|
|
||||||
(file: File | null) => {
|
|
||||||
const removeExistingStorageFile = () => {
|
|
||||||
if (props.pictureUrl) {
|
|
||||||
return (
|
|
||||||
deleteProfilePhoto(client, props.pictureUrl) ?? Promise.resolve()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Promise.resolve();
|
|
||||||
};
|
|
||||||
|
|
||||||
if (file) {
|
|
||||||
const promise = () =>
|
|
||||||
removeExistingStorageFile().then(() =>
|
|
||||||
uploadUserProfilePhoto(client, file, props.userId)
|
|
||||||
.then((pictureUrl) => {
|
|
||||||
return client
|
|
||||||
.schema('medreport')
|
|
||||||
.from('accounts')
|
|
||||||
.update({
|
|
||||||
picture_url: pictureUrl,
|
|
||||||
})
|
|
||||||
.eq('id', props.userId)
|
|
||||||
.throwOnError();
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
props.onAvatarUpdated();
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
createToaster(promise);
|
|
||||||
} else {
|
|
||||||
const promise = () =>
|
|
||||||
removeExistingStorageFile()
|
|
||||||
.then(() => {
|
|
||||||
return client
|
|
||||||
.schema('medreport')
|
|
||||||
.from('accounts')
|
|
||||||
.update({
|
|
||||||
picture_url: null,
|
|
||||||
})
|
|
||||||
.eq('id', props.userId)
|
|
||||||
.throwOnError();
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
props.onAvatarUpdated();
|
|
||||||
});
|
|
||||||
|
|
||||||
createToaster(promise);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[client, createToaster, props],
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ImageUploader value={props.pictureUrl} onValueChange={onValueChange}>
|
|
||||||
<div className={'flex flex-col space-y-1'}>
|
|
||||||
<span className={'text-sm'}>
|
|
||||||
<Trans i18nKey={'account:profilePictureHeading'} />
|
|
||||||
</span>
|
|
||||||
|
|
||||||
<span className={'text-xs'}>
|
|
||||||
<Trans i18nKey={'account:profilePictureSubheading'} />
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</ImageUploader>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function deleteProfilePhoto(client: SupabaseClient<Database>, url: string) {
|
|
||||||
const bucket = client.storage.from(AVATARS_BUCKET);
|
|
||||||
const fileName = url.split('/').pop()?.split('?')[0];
|
|
||||||
|
|
||||||
if (!fileName) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return bucket.remove([fileName]);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function uploadUserProfilePhoto(
|
|
||||||
client: SupabaseClient<Database>,
|
|
||||||
photoFile: File,
|
|
||||||
userId: string,
|
|
||||||
) {
|
|
||||||
const bytes = await photoFile.arrayBuffer();
|
|
||||||
const bucket = client.storage.from(AVATARS_BUCKET);
|
|
||||||
const extension = photoFile.name.split('.').pop();
|
|
||||||
const fileName = await getAvatarFileName(userId, extension);
|
|
||||||
|
|
||||||
const result = await bucket.upload(fileName, bytes);
|
|
||||||
|
|
||||||
if (!result.error) {
|
|
||||||
return bucket.getPublicUrl(fileName).data.publicUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw result.error;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getAvatarFileName(
|
|
||||||
userId: string,
|
|
||||||
extension: string | undefined,
|
|
||||||
) {
|
|
||||||
const { nanoid } = await import('nanoid');
|
|
||||||
|
|
||||||
// we add a version to the URL to ensure
|
|
||||||
// the browser always fetches the latest image
|
|
||||||
const uniqueId = nanoid(16);
|
|
||||||
|
|
||||||
return `${userId}.${extension}?v=${uniqueId}`;
|
|
||||||
}
|
|
||||||
@@ -2,19 +2,19 @@ import { SupabaseClient } from '@supabase/supabase-js';
|
|||||||
|
|
||||||
import { Database } from '@kit/supabase/database';
|
import { Database } from '@kit/supabase/database';
|
||||||
|
|
||||||
import {
|
import { AnalysisResultDetails, UserAnalysis } from '../types/accounts';
|
||||||
AnalysisResultDetails,
|
|
||||||
UserAnalysis,
|
|
||||||
UserAnalysisResponse,
|
|
||||||
} from '../types/accounts';
|
|
||||||
|
|
||||||
export type AccountWithParams =
|
export type AccountWithParams =
|
||||||
Database['medreport']['Tables']['accounts']['Row'] & {
|
Database['medreport']['Tables']['accounts']['Row'] & {
|
||||||
account_params:
|
accountParams:
|
||||||
| Pick<
|
| (Pick<
|
||||||
Database['medreport']['Tables']['account_params']['Row'],
|
Database['medreport']['Tables']['account_params']['Row'],
|
||||||
'weight' | 'height'
|
'weight' | 'height'
|
||||||
>[]
|
> & {
|
||||||
|
isSmoker:
|
||||||
|
| Database['medreport']['Tables']['account_params']['Row']['is_smoker']
|
||||||
|
| null;
|
||||||
|
})
|
||||||
| null;
|
| null;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -35,7 +35,9 @@ class AccountsApi {
|
|||||||
const { data, error } = await this.client
|
const { data, error } = await this.client
|
||||||
.schema('medreport')
|
.schema('medreport')
|
||||||
.from('accounts')
|
.from('accounts')
|
||||||
.select('*, account_params: account_params (weight, height)')
|
.select(
|
||||||
|
'*, accountParams: account_params (weight, height, isSmoker:is_smoker)',
|
||||||
|
)
|
||||||
.eq('id', id)
|
.eq('id', id)
|
||||||
.single();
|
.single();
|
||||||
|
|
||||||
@@ -46,6 +48,41 @@ class AccountsApi {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name getPersonalAccountByUserId
|
||||||
|
* @description Get the personal account data for the given user ID.
|
||||||
|
* @param userId
|
||||||
|
*/
|
||||||
|
async getPersonalAccountByUserId(userId: string): Promise<AccountWithParams> {
|
||||||
|
const { data, error } = await this.client
|
||||||
|
.schema('medreport')
|
||||||
|
.from('accounts')
|
||||||
|
.select(
|
||||||
|
'*, accountParams: account_params (weight, height, isSmoker:is_smoker)',
|
||||||
|
)
|
||||||
|
.eq('primary_owner_user_id', userId)
|
||||||
|
.eq('is_personal_account', true)
|
||||||
|
.single();
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { personal_code, ...rest } = data;
|
||||||
|
return {
|
||||||
|
...rest,
|
||||||
|
personal_code: (() => {
|
||||||
|
if (!personal_code) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (personal_code.toLowerCase().startsWith('ee')) {
|
||||||
|
return personal_code.substring(2);
|
||||||
|
}
|
||||||
|
return personal_code;
|
||||||
|
})(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name getAccountWorkspace
|
* @name getAccountWorkspace
|
||||||
* @description Get the account workspace data.
|
* @description Get the account workspace data.
|
||||||
|
|||||||
@@ -32,9 +32,8 @@ const SPECIAL_CHARACTERS_REGEX = /[!@#$%^&*()+=[\]{};':"\\|,.<>/?]/;
|
|||||||
* @name CompanyNameSchema
|
* @name CompanyNameSchema
|
||||||
*/
|
*/
|
||||||
export const CompanyNameSchema = z
|
export const CompanyNameSchema = z
|
||||||
.string({
|
.string()
|
||||||
description: 'The name of the company account',
|
.describe('The name of the company account')
|
||||||
})
|
|
||||||
.min(2)
|
.min(2)
|
||||||
.max(50)
|
.max(50)
|
||||||
.refine(
|
.refine(
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ import { AuthProviderButton } from './auth-provider-button';
|
|||||||
* @see https://supabase.com/docs/guides/auth/social-login
|
* @see https://supabase.com/docs/guides/auth/social-login
|
||||||
*/
|
*/
|
||||||
const OAUTH_SCOPES: Partial<Record<Provider, string>> = {
|
const OAUTH_SCOPES: Partial<Record<Provider, string>> = {
|
||||||
azure: 'email',
|
// azure: 'email',
|
||||||
keycloak: 'openid',
|
// keycloak: 'openid',
|
||||||
// add your OAuth providers here
|
// add your OAuth providers here
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -88,10 +88,12 @@ export const OauthProviders: React.FC<{
|
|||||||
queryParams.set('invite_token', props.inviteToken);
|
queryParams.set('invite_token', props.inviteToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
const redirectPath = [
|
// signicat/keycloak will not allow redirect-uri with changing query params
|
||||||
props.paths.callback,
|
const INCLUDE_QUERY_PARAMS = false as boolean;
|
||||||
queryParams.toString(),
|
|
||||||
].join('?');
|
const redirectPath = INCLUDE_QUERY_PARAMS
|
||||||
|
? [props.paths.callback, queryParams.toString()].join('?')
|
||||||
|
: props.paths.callback;
|
||||||
|
|
||||||
const redirectTo = [origin, redirectPath].join('');
|
const redirectTo = [origin, redirectPath].join('');
|
||||||
const scopes = OAUTH_SCOPES[provider] ?? undefined;
|
const scopes = OAUTH_SCOPES[provider] ?? undefined;
|
||||||
@@ -102,6 +104,7 @@ export const OauthProviders: React.FC<{
|
|||||||
redirectTo,
|
redirectTo,
|
||||||
queryParams: props.queryParams,
|
queryParams: props.queryParams,
|
||||||
scopes,
|
scopes,
|
||||||
|
// skipBrowserRedirect: false,
|
||||||
},
|
},
|
||||||
} satisfies SignInWithOAuthCredentials;
|
} satisfies SignInWithOAuthCredentials;
|
||||||
|
|
||||||
|
|||||||
@@ -108,6 +108,9 @@ export function SignInMethodsContainer(props: {
|
|||||||
callback: props.paths.callback,
|
callback: props.paths.callback,
|
||||||
returnPath: props.paths.returnPath,
|
returnPath: props.paths.returnPath,
|
||||||
}}
|
}}
|
||||||
|
queryParams={{
|
||||||
|
prompt: 'login',
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</If>
|
</If>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ export function SignUpMethodsContainer(props: {
|
|||||||
emailRedirectTo={props.paths.callback}
|
emailRedirectTo={props.paths.callback}
|
||||||
defaultValues={defaultValues}
|
defaultValues={defaultValues}
|
||||||
displayTermsCheckbox={props.displayTermsCheckbox}
|
displayTermsCheckbox={props.displayTermsCheckbox}
|
||||||
onSignUp={() => redirect(redirectUrl)}
|
//onSignUp={() => redirect(redirectUrl)}
|
||||||
/>
|
/>
|
||||||
</If>
|
</If>
|
||||||
|
|
||||||
@@ -79,6 +79,9 @@ export function SignUpMethodsContainer(props: {
|
|||||||
callback: props.paths.callback,
|
callback: props.paths.callback,
|
||||||
returnPath: props.paths.appHome,
|
returnPath: props.paths.appHome,
|
||||||
}}
|
}}
|
||||||
|
queryParams={{
|
||||||
|
prompt: 'login',
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</If>
|
</If>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -28,6 +28,10 @@ export const OrderSchema = z.object({
|
|||||||
title: z.string(),
|
title: z.string(),
|
||||||
isPackage: z.boolean(),
|
isPackage: z.boolean(),
|
||||||
analysisOrderId: z.number(),
|
analysisOrderId: z.number(),
|
||||||
|
productMetadata: z.object({
|
||||||
|
analysisIdOriginal: z.string().nullable(),
|
||||||
|
analysisResultUnit: z.string().nullable(),
|
||||||
|
}).nullable(),
|
||||||
});
|
});
|
||||||
export type Order = z.infer<typeof OrderSchema>;
|
export type Order = z.infer<typeof OrderSchema>;
|
||||||
|
|
||||||
|
|||||||
@@ -410,7 +410,7 @@ export async function getAnalysisResultsForDoctor(
|
|||||||
.from('accounts')
|
.from('accounts')
|
||||||
.select(
|
.select(
|
||||||
`primary_owner_user_id, id, name, last_name, personal_code, phone, email, preferred_locale,
|
`primary_owner_user_id, id, name, last_name, personal_code, phone, email, preferred_locale,
|
||||||
account_params(height,weight)`,
|
accountParams:account_params(height,weight)`,
|
||||||
)
|
)
|
||||||
.eq('is_personal_account', true)
|
.eq('is_personal_account', true)
|
||||||
.eq('primary_owner_user_id', userId)
|
.eq('primary_owner_user_id', userId)
|
||||||
@@ -472,7 +472,7 @@ export async function getAnalysisResultsForDoctor(
|
|||||||
last_name,
|
last_name,
|
||||||
personal_code,
|
personal_code,
|
||||||
phone,
|
phone,
|
||||||
account_params,
|
accountParams,
|
||||||
preferred_locale,
|
preferred_locale,
|
||||||
} = accountWithParams[0];
|
} = accountWithParams[0];
|
||||||
|
|
||||||
@@ -513,8 +513,8 @@ export async function getAnalysisResultsForDoctor(
|
|||||||
personalCode: personal_code,
|
personalCode: personal_code,
|
||||||
phone,
|
phone,
|
||||||
email,
|
email,
|
||||||
height: account_params?.[0]?.height,
|
height: accountParams?.height,
|
||||||
weight: account_params?.[0]?.weight,
|
weight: accountParams?.weight,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import { sdk } from "@lib/config"
|
|||||||
import medusaError from "@lib/util/medusa-error"
|
import medusaError from "@lib/util/medusa-error"
|
||||||
import { HttpTypes } from "@medusajs/types"
|
import { HttpTypes } from "@medusajs/types"
|
||||||
import { revalidateTag } from "next/cache"
|
import { revalidateTag } from "next/cache"
|
||||||
import { redirect } from "next/navigation"
|
|
||||||
import {
|
import {
|
||||||
getAuthHeaders,
|
getAuthHeaders,
|
||||||
getCacheOptions,
|
getCacheOptions,
|
||||||
@@ -127,7 +126,7 @@ export async function login(_currentState: unknown, formData: FormData) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function signout(countryCode: string) {
|
export async function medusaLogout(countryCode = 'ee') {
|
||||||
await sdk.auth.logout()
|
await sdk.auth.logout()
|
||||||
|
|
||||||
await removeAuthToken()
|
await removeAuthToken()
|
||||||
@@ -139,8 +138,6 @@ export async function signout(countryCode: string) {
|
|||||||
|
|
||||||
const cartCacheTag = await getCacheTag("carts")
|
const cartCacheTag = await getCacheTag("carts")
|
||||||
revalidateTag(cartCacheTag)
|
revalidateTag(cartCacheTag)
|
||||||
|
|
||||||
redirect(`/${countryCode}/account`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function transferCart() {
|
export async function transferCart() {
|
||||||
@@ -260,62 +257,110 @@ export const updateCustomerAddress = async (
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function medusaLoginOrRegister(credentials: {
|
async function medusaLogin(email: string, password: string) {
|
||||||
email: string
|
const token = await sdk.auth.login("customer", "emailpass", { email, password });
|
||||||
password?: string
|
await setAuthToken(token as string);
|
||||||
}) {
|
|
||||||
const { email, password } = credentials;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const token = await sdk.auth.login("customer", "emailpass", {
|
|
||||||
email,
|
|
||||||
password,
|
|
||||||
});
|
|
||||||
await setAuthToken(token as string);
|
|
||||||
await transferCart();
|
await transferCart();
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Failed to transfer cart", e);
|
||||||
|
}
|
||||||
|
|
||||||
const customerCacheTag = await getCacheTag("customers");
|
const customer = await retrieveCustomer();
|
||||||
revalidateTag(customerCacheTag);
|
if (!customer) {
|
||||||
|
throw new Error("Customer not found for active session");
|
||||||
|
}
|
||||||
|
|
||||||
const customer = await retrieveCustomer();
|
return customer.id;
|
||||||
if (!customer) {
|
}
|
||||||
throw new Error("Customer not found");
|
|
||||||
|
async function medusaRegister({
|
||||||
|
email,
|
||||||
|
password,
|
||||||
|
name,
|
||||||
|
lastName,
|
||||||
|
}: {
|
||||||
|
email: string;
|
||||||
|
password: string;
|
||||||
|
name: string | undefined;
|
||||||
|
lastName: string | undefined;
|
||||||
|
}) {
|
||||||
|
console.info(`Creating new Medusa account for Keycloak user with email=${email}`);
|
||||||
|
|
||||||
|
const registerToken = await sdk.auth.register("customer", "emailpass", { email, password });
|
||||||
|
await setAuthToken(registerToken);
|
||||||
|
|
||||||
|
console.info(`Creating new Medusa customer profile for Keycloak user with email=${email} and name=${name} and lastName=${lastName}`);
|
||||||
|
await sdk.store.customer.create(
|
||||||
|
{ email, first_name: name, last_name: lastName },
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
...(await getAuthHeaders()),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function medusaLoginOrRegister(credentials: {
|
||||||
|
email: string
|
||||||
|
supabaseUserId?: string
|
||||||
|
name?: string,
|
||||||
|
lastName?: string,
|
||||||
|
} & ({ isDevPasswordLogin: true; password: string } | { isDevPasswordLogin?: false; password?: undefined })) {
|
||||||
|
const { email, supabaseUserId, name, lastName } = credentials;
|
||||||
|
|
||||||
|
|
||||||
|
const password = await (async () => {
|
||||||
|
if (credentials.isDevPasswordLogin) {
|
||||||
|
return credentials.password;
|
||||||
}
|
}
|
||||||
return customer.id;
|
|
||||||
} catch (error) {
|
return generateDeterministicPassword(email, supabaseUserId);
|
||||||
console.error("Failed to login customer, attempting to register", error);
|
})();
|
||||||
|
|
||||||
|
try {
|
||||||
|
return await medusaLogin(email, password);
|
||||||
|
} catch (loginError) {
|
||||||
|
console.error("Failed to login customer, attempting to register", loginError);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const registerToken = await sdk.auth.register("customer", "emailpass", {
|
await medusaRegister({ email, password, name, lastName });
|
||||||
email: email,
|
return await medusaLogin(email, password);
|
||||||
password: password,
|
|
||||||
})
|
|
||||||
|
|
||||||
await setAuthToken(registerToken as string);
|
|
||||||
|
|
||||||
const headers = {
|
|
||||||
...(await getAuthHeaders()),
|
|
||||||
};
|
|
||||||
|
|
||||||
await sdk.store.customer.create({ email }, {}, headers);
|
|
||||||
|
|
||||||
const loginToken = await sdk.auth.login("customer", "emailpass", {
|
|
||||||
email,
|
|
||||||
password,
|
|
||||||
});
|
|
||||||
|
|
||||||
await setAuthToken(loginToken as string);
|
|
||||||
|
|
||||||
const customerCacheTag = await getCacheTag("customers");
|
|
||||||
revalidateTag(customerCacheTag);
|
|
||||||
await transferCart();
|
|
||||||
|
|
||||||
const customer = await retrieveCustomer();
|
|
||||||
if (!customer) {
|
|
||||||
throw new Error("Customer not found");
|
|
||||||
}
|
|
||||||
return customer.id;
|
|
||||||
} catch (registerError) {
|
} catch (registerError) {
|
||||||
|
console.error("Failed to create Medusa account for user with email=${email}", registerError);
|
||||||
throw medusaError(registerError);
|
throw medusaError(registerError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a deterministic password based on user identifier
|
||||||
|
* This ensures the same user always gets the same password for Medusa
|
||||||
|
*/
|
||||||
|
async function generateDeterministicPassword(email: string, userId?: string): Promise<string> {
|
||||||
|
// Use the user ID or email as the base for deterministic generation
|
||||||
|
const baseString = userId || email;
|
||||||
|
const secret = process.env.MEDUSA_PASSWORD_SECRET!;
|
||||||
|
|
||||||
|
// Create a deterministic password using HMAC
|
||||||
|
const encoder = new TextEncoder();
|
||||||
|
const keyData = encoder.encode(secret);
|
||||||
|
const messageData = encoder.encode(baseString);
|
||||||
|
|
||||||
|
// Import key for HMAC
|
||||||
|
const key = await crypto.subtle.importKey(
|
||||||
|
'raw',
|
||||||
|
keyData,
|
||||||
|
{ name: 'HMAC', hash: 'SHA-256' },
|
||||||
|
false,
|
||||||
|
['sign']
|
||||||
|
);
|
||||||
|
// Generate HMAC
|
||||||
|
const signature = await crypto.subtle.sign('HMAC', key, messageData);
|
||||||
|
// Convert to base64 and make it a valid password
|
||||||
|
const hashArray = Array.from(new Uint8Array(signature));
|
||||||
|
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
|
||||||
|
// Take first 24 characters and add some complexity
|
||||||
|
const basePassword = hashHex.substring(0, 24);
|
||||||
|
// Add some required complexity for Medusa (uppercase, lowercase, numbers, symbols)
|
||||||
|
return `Mk${basePassword}9!`;
|
||||||
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export const listProducts = async ({
|
|||||||
regionId,
|
regionId,
|
||||||
}: {
|
}: {
|
||||||
pageParam?: number
|
pageParam?: number
|
||||||
queryParams?: HttpTypes.FindParams & HttpTypes.StoreProductParams & { "type_id[0]"?: string; id?: string[] }
|
queryParams?: HttpTypes.FindParams & HttpTypes.StoreProductParams & { "type_id[0]"?: string; id?: string[], category_id?: string }
|
||||||
countryCode?: string
|
countryCode?: string
|
||||||
regionId?: string
|
regionId?: string
|
||||||
}): Promise<{
|
}): Promise<{
|
||||||
@@ -63,12 +63,12 @@ export const listProducts = async ({
|
|||||||
offset,
|
offset,
|
||||||
region_id: region?.id,
|
region_id: region?.id,
|
||||||
fields:
|
fields:
|
||||||
"*variants.calculated_price,+variants.inventory_quantity,+metadata,+tags",
|
"*variants.calculated_price,+variants.inventory_quantity,+metadata,+tags,+status",
|
||||||
...queryParams,
|
...queryParams,
|
||||||
},
|
},
|
||||||
headers,
|
headers,
|
||||||
next,
|
next,
|
||||||
cache: "force-cache",
|
//cache: "force-cache",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.then(({ products, count }) => {
|
.then(({ products, count }) => {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import MapPin from "@modules/common/icons/map-pin"
|
|||||||
import Package from "@modules/common/icons/package"
|
import Package from "@modules/common/icons/package"
|
||||||
import LocalizedClientLink from "@modules/common/components/localized-client-link"
|
import LocalizedClientLink from "@modules/common/components/localized-client-link"
|
||||||
import { HttpTypes } from "@medusajs/types"
|
import { HttpTypes } from "@medusajs/types"
|
||||||
import { signout } from "@lib/data/customer"
|
import { medusaLogout } from "@lib/data/customer"
|
||||||
|
|
||||||
const AccountNav = ({
|
const AccountNav = ({
|
||||||
customer,
|
customer,
|
||||||
@@ -21,7 +21,7 @@ const AccountNav = ({
|
|||||||
const { countryCode } = useParams() as { countryCode: string }
|
const { countryCode } = useParams() as { countryCode: string }
|
||||||
|
|
||||||
const handleLogout = async () => {
|
const handleLogout = async () => {
|
||||||
await signout(countryCode)
|
await medusaLogout(countryCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -17,22 +17,22 @@ const env = z
|
|||||||
.object({
|
.object({
|
||||||
invitePath: z
|
invitePath: z
|
||||||
.string({
|
.string({
|
||||||
required_error: 'The property invitePath is required',
|
error: 'The property invitePath is required',
|
||||||
})
|
})
|
||||||
.min(1),
|
.min(1),
|
||||||
siteURL: z
|
siteURL: z
|
||||||
.string({
|
.string({
|
||||||
required_error: 'NEXT_PUBLIC_SITE_URL is required',
|
error: 'NEXT_PUBLIC_SITE_URL is required',
|
||||||
})
|
})
|
||||||
.min(1),
|
.min(1),
|
||||||
productName: z
|
productName: z
|
||||||
.string({
|
.string({
|
||||||
required_error: 'NEXT_PUBLIC_PRODUCT_NAME is required',
|
error: 'NEXT_PUBLIC_PRODUCT_NAME is required',
|
||||||
})
|
})
|
||||||
.min(1),
|
.min(1),
|
||||||
emailSender: z
|
emailSender: z
|
||||||
.string({
|
.string({
|
||||||
required_error: 'EMAIL_SENDER is required',
|
error: 'EMAIL_SENDER is required',
|
||||||
})
|
})
|
||||||
.min(1),
|
.min(1),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ class AccountWebhooksService {
|
|||||||
productName: z.string(),
|
productName: z.string(),
|
||||||
fromEmail: z
|
fromEmail: z
|
||||||
.string({
|
.string({
|
||||||
required_error: 'EMAIL_SENDER is required',
|
error: 'EMAIL_SENDER is required',
|
||||||
})
|
})
|
||||||
.min(1),
|
.min(1),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ type Config = z.infer<typeof MailerSchema>;
|
|||||||
|
|
||||||
const RESEND_API_KEY = z
|
const RESEND_API_KEY = z
|
||||||
.string({
|
.string({
|
||||||
description: 'The API key for the Resend API',
|
error: 'Please provide the API key for the Resend API',
|
||||||
required_error: 'Please provide the API key for the Resend API',
|
|
||||||
})
|
})
|
||||||
|
.describe('The API key for the Resend API')
|
||||||
.parse(process.env.RESEND_API_KEY);
|
.parse(process.env.RESEND_API_KEY);
|
||||||
|
|
||||||
export function createResendMailer() {
|
export function createResendMailer() {
|
||||||
|
|||||||
@@ -4,25 +4,19 @@ import { z } from 'zod';
|
|||||||
|
|
||||||
export const SmtpConfigSchema = z.object({
|
export const SmtpConfigSchema = z.object({
|
||||||
user: z.string({
|
user: z.string({
|
||||||
description:
|
error: `Please provide the variable EMAIL_USER`,
|
||||||
'This is the email account to send emails from. This is specific to the email provider.',
|
})
|
||||||
required_error: `Please provide the variable EMAIL_USER`,
|
.describe('This is the email account to send emails from. This is specific to the email provider.'),
|
||||||
}),
|
|
||||||
pass: z.string({
|
pass: z.string({
|
||||||
description: 'This is the password for the email account',
|
error: `Please provide the variable EMAIL_PASSWORD`,
|
||||||
required_error: `Please provide the variable EMAIL_PASSWORD`,
|
}).describe('This is the password for the email account'),
|
||||||
}),
|
|
||||||
host: z.string({
|
host: z.string({
|
||||||
description: 'This is the SMTP host for the email provider',
|
error: `Please provide the variable EMAIL_HOST`,
|
||||||
required_error: `Please provide the variable EMAIL_HOST`,
|
}).describe('This is the SMTP host for the email provider'),
|
||||||
}),
|
|
||||||
port: z.number({
|
port: z.number({
|
||||||
description:
|
error: `Please provide the variable EMAIL_PORT`,
|
||||||
'This is the port for the email provider. Normally 587 or 465.',
|
}).describe('This is the port for the email provider. Normally 587 or 465.'),
|
||||||
required_error: `Please provide the variable EMAIL_PORT`,
|
|
||||||
}),
|
|
||||||
secure: z.boolean({
|
secure: z.boolean({
|
||||||
description: 'This is whether the connection is secure or not',
|
error: `Please provide the variable EMAIL_TLS`,
|
||||||
required_error: `Please provide the variable EMAIL_TLS`,
|
}).describe('This is whether the connection is secure or not'),
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import { MonitoringService } from '@kit/monitoring-core';
|
|||||||
|
|
||||||
const apiKey = z
|
const apiKey = z
|
||||||
.string({
|
.string({
|
||||||
required_error: 'NEXT_PUBLIC_BASELIME_KEY is required',
|
error: 'NEXT_PUBLIC_BASELIME_KEY is required',
|
||||||
description: 'The Baseline API key',
|
|
||||||
})
|
})
|
||||||
|
.describe('The Baseline API key')
|
||||||
.parse(process.env.NEXT_PUBLIC_BASELIME_KEY);
|
.parse(process.env.NEXT_PUBLIC_BASELIME_KEY);
|
||||||
|
|
||||||
export class BaselimeServerMonitoringService implements MonitoringService {
|
export class BaselimeServerMonitoringService implements MonitoringService {
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user