Compare commits
1 Commits
3e192c71c5
...
MED-97
| Author | SHA1 | Date | |
|---|---|---|---|
| 70d5b78ca8 |
2
.env
2
.env
@@ -33,7 +33,7 @@ NEXT_PUBLIC_LOCALES_PATH=apps/web/public/locales
|
||||
NEXT_PUBLIC_ENABLE_THEME_TOGGLE=true
|
||||
NEXT_PUBLIC_ENABLE_PERSONAL_ACCOUNT_DELETION=true
|
||||
NEXT_PUBLIC_ENABLE_PERSONAL_ACCOUNT_BILLING=false
|
||||
NEXT_PUBLIC_ENABLE_TEAM_ACCOUNTS_DELETION=false
|
||||
NEXT_PUBLIC_ENABLE_TEAM_ACCOUNTS_DELETION=true
|
||||
NEXT_PUBLIC_ENABLE_TEAM_ACCOUNTS_BILLING=true
|
||||
NEXT_PUBLIC_ENABLE_TEAM_ACCOUNTS=true
|
||||
NEXT_PUBLIC_ENABLE_TEAM_ACCOUNTS_CREATION=true
|
||||
|
||||
@@ -10,10 +10,6 @@ NEXT_PUBLIC_AUTH_PASSWORD=true
|
||||
## THIS IS FOR DEVELOPMENT ONLY - DO NOT USE IN PRODUCTION
|
||||
SUPABASE_DB_WEBHOOK_SECRET=WEBHOOKSECRET
|
||||
|
||||
# MEDUSA MONTONIO URLS FOR LOCALHOST
|
||||
# Montonio doesn't allow localhost as notification/callback URL
|
||||
DEV_MONTONIO_CALLBACK_URL=http://webhook.site:3000
|
||||
|
||||
# EMAILS
|
||||
|
||||
# CONTACT FORM
|
||||
@@ -35,14 +31,14 @@ NODE_TLS_REJECT_UNAUTHORIZED=0
|
||||
MEDIPOST_URL=https://meditest.medisoft.ee:7443/Medipost/MedipostServlet
|
||||
MEDIPOST_USER=trvurgtst
|
||||
MEDIPOST_PASSWORD=SRB48HZMV
|
||||
MEDIPOST_RECIPIENT=syndev
|
||||
MEDIPOST_RECIPIENT=trvurgtst
|
||||
MEDIPOST_MESSAGE_SENDER=trvurgtst
|
||||
MEDIPOST_ENABLE_DISPATCH_ON_MONTONIO_CALLBACK=true
|
||||
MEDIPOST_ENABLE_DELETE_RESPONSE_PRIVATE_MESSAGE_ON_READ=false
|
||||
|
||||
#MEDIPOST_URL=https://medipost2.medisoft.ee:8443/Medipost/MedipostServlet
|
||||
#MEDIPOST_USER=medreport
|
||||
#MEDIPOST_PASSWORD=
|
||||
#MEDIPOST_PASSWORD=85MXFFDB7
|
||||
#MEDIPOST_RECIPIENT=HTI
|
||||
#MEDIPOST_MESSAGE_SENDER=medreport
|
||||
#MEDIPOST_ENABLE_DISPATCH_ON_MONTONIO_CALLBACK=false
|
||||
@@ -51,11 +47,48 @@ MEDIPOST_ENABLE_DELETE_RESPONSE_PRIVATE_MESSAGE_ON_READ=false
|
||||
COMPANY_BENEFITS_PAYMENT_SECRET_KEY=NzcwMzE2NmEtOThiMS0xMWYwLWI4NjYtMDMwZDQzMjFhMjExCg==
|
||||
MEDUSA_BACKEND_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_5ac1c1c12c144cd744b6c881050d459e339ddf6a3d14eda271a0cc4f9d3812cb
|
||||
#NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY=pk_e740b9ca22b31c4b44862044f001dbcf8f46d47d40f430733d0c75bef14d2d6a
|
||||
|
||||
#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
|
||||
NEXT_PUBLIC_MONTONIO_ACCESS_KEY=7da5d7fa-3383-4997-9435-46aa818f4ead
|
||||
MONTONIO_SECRET_KEY=rNZkzwxOiH93mzkdV53AvhSsbGidrgO2Kl5lE/IT7cvo
|
||||
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_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=imCTUreSnazWKT3u#
|
||||
|
||||
@@ -10,7 +10,6 @@ MEDIPOST_PASSWORD=your-medipost-password
|
||||
MEDIPOST_RECIPIENT=your-medipost-recipient
|
||||
|
||||
CONNECTED_ONLINE_URL=your-connected-online-url
|
||||
CONNECTED_ONLINE_CONFIRMED_URL=your-connected-confirmed-url
|
||||
|
||||
EMAIL_SENDER=
|
||||
EMAIL_USER= # refer to your email provider's documentation
|
||||
@@ -20,7 +19,6 @@ EMAIL_PORT= # or 465 for SSL
|
||||
EMAIL_TLS= # or false for SSL (see provider documentation)
|
||||
|
||||
NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY=
|
||||
MEDUSA_SECRET_API_KEY=
|
||||
|
||||
NEXT_PUBLIC_MONTONIO_ACCESS_KEY=7da5d7fa-3383-4997-9435-46aa818f4ead
|
||||
MONTONIO_SECRET_KEY=rNZkzwxOiH93mzkdV53AvhSsbGidrgO2Kl5lE/IT7cvo
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
## PUBLIC KEYS OR CONFIGURATION ARE OKAY TO BE PLACED HERE.
|
||||
|
||||
# SUPABASE
|
||||
# NEXT_PUBLIC_SUPABASE_URL=https://oqsdacktkhmbylmzstjq.supabase.co
|
||||
# NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im9xc2RhY2t0a2htYnlsbXpzdGpxIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDY1MjgxMjMsImV4cCI6MjA2MjEwNDEyM30.LdHCTWxijFmhXdnT9KVuLRAVbtSwY7OO-oLtpd8GmO0
|
||||
NEXT_PUBLIC_SUPABASE_URL=https://oqsdacktkhmbylmzstjq.supabase.co
|
||||
NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im9xc2RhY2t0a2htYnlsbXpzdGpxIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDY1MjgxMjMsImV4cCI6MjA2MjEwNDEyM30.LdHCTWxijFmhXdnT9KVuLRAVbtSwY7OO-oLtpd8GmO0
|
||||
|
||||
# NEXT_PUBLIC_SITE_URL=https://test.medreport.ee
|
||||
NEXT_PUBLIC_SITE_URL=https://test.medreport.ee
|
||||
|
||||
# # MONTONIO
|
||||
# NEXT_PUBLIC_MONTONIO_ACCESS_KEY=7da5d7fa-3383-4997-9435-46aa818f4ead
|
||||
NEXT_PUBLIC_MONTONIO_ACCESS_KEY=7da5d7fa-3383-4997-9435-46aa818f4ead
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
database.types.ts
|
||||
playwright-report
|
||||
*.hbs
|
||||
.history
|
||||
node_modules
|
||||
*.hbs
|
||||
@@ -98,13 +98,13 @@ To access admin pages follow these steps:
|
||||
- Register new user
|
||||
- Go to Profile and add Multi-Factor Authentication
|
||||
- Authenticate with mfa (at current time profile page prompts it again)
|
||||
- update your `account.application_role` to `super_admin`.
|
||||
- update your role. look at `supabase/sql/super-admin.sql`
|
||||
- Sign out and Sign in
|
||||
|
||||
## Company User
|
||||
|
||||
- With admin account go to `http://localhost:3000/admin/accounts`
|
||||
- For Create Company Account to work you need to have rows in `medreport.roles` table.
|
||||
- For Create Company Account to work you need to have rows in `medreport.roles` table. For that you can sql in `supabase/sql/super-admin.sql`
|
||||
|
||||
## Start email server
|
||||
|
||||
|
||||
@@ -19,8 +19,6 @@ import { Label } from '@kit/ui/label';
|
||||
import { Spinner } from '@kit/ui/spinner';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
import { sendCompanyOfferEmail } from '../_lib/server/company-offer-actions';
|
||||
|
||||
const CompanyOfferForm = () => {
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const router = useRouter();
|
||||
@@ -36,16 +34,6 @@ const CompanyOfferForm = () => {
|
||||
|
||||
const onSubmit = async (data: CompanySubmitData) => {
|
||||
setIsLoading(true);
|
||||
try {
|
||||
await sendCompanyOfferEmail(data, language);
|
||||
router.push('/company-offer/success');
|
||||
} catch (err) {
|
||||
setIsLoading(false);
|
||||
if (err instanceof Error) {
|
||||
console.warn('Could not send company offer email: ' + err.message);
|
||||
}
|
||||
console.warn('Could not send company offer email: ', err);
|
||||
}
|
||||
const formData = new FormData();
|
||||
Object.entries(data).forEach(([key, value]) => {
|
||||
if (value !== undefined) formData.append(key, value);
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
'use server';
|
||||
|
||||
import { renderCompanyOfferEmail } from '@/packages/email-templates/src';
|
||||
|
||||
import { sendEmailFromTemplate } from '~/lib/services/mailer.service';
|
||||
import { CompanySubmitData } from '~/lib/types/company';
|
||||
|
||||
export const sendCompanyOfferEmail = async (
|
||||
data: CompanySubmitData,
|
||||
language: string,
|
||||
) => {
|
||||
const formData = new FormData();
|
||||
Object.entries(data).forEach(([key, value]) => {
|
||||
if (value !== undefined) formData.append(key, value);
|
||||
});
|
||||
|
||||
sendEmailFromTemplate(
|
||||
renderCompanyOfferEmail,
|
||||
{
|
||||
companyData: data,
|
||||
language,
|
||||
},
|
||||
process.env.CONTACT_EMAIL!,
|
||||
);
|
||||
};
|
||||
@@ -1,27 +0,0 @@
|
||||
import { enhanceRouteHandler } from '@/packages/next/src/routes';
|
||||
import { createAuthCallbackService } from '@/packages/supabase/src/auth-callback.service';
|
||||
import { getSupabaseServerClient } from '@/packages/supabase/src/clients/server-client';
|
||||
|
||||
export const POST = enhanceRouteHandler(
|
||||
async () => {
|
||||
try {
|
||||
const supabaseClient = getSupabaseServerClient();
|
||||
const {
|
||||
data: { user },
|
||||
} = await supabaseClient.auth.getUser();
|
||||
const service = createAuthCallbackService(supabaseClient);
|
||||
|
||||
if (user && service.isKeycloakUser(user)) {
|
||||
await service.setupMedusaUserForKeycloak(user);
|
||||
}
|
||||
|
||||
return new Response(null, { status: 200 });
|
||||
} catch (err) {
|
||||
console.error('Error on verifying:', { err });
|
||||
return new Response(null, { status: 500 });
|
||||
}
|
||||
},
|
||||
{
|
||||
auth: false,
|
||||
},
|
||||
);
|
||||
@@ -7,18 +7,10 @@ import { sendEmailFromTemplate } from '~/lib/services/mailer.service';
|
||||
export default async function sendOpenJobsEmails() {
|
||||
const analysisResponseIds = await getOpenJobAnalysisResponseIds();
|
||||
|
||||
if (analysisResponseIds.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const doctorAccounts = await getDoctorAccounts();
|
||||
const doctorEmails = doctorAccounts
|
||||
const doctorEmails: string[] = doctorAccounts
|
||||
.map(({ email }) => email)
|
||||
.filter((email) => !!email);
|
||||
|
||||
if (doctorEmails !== null) {
|
||||
return [];
|
||||
}
|
||||
.filter((email): email is string => !!email);
|
||||
|
||||
await sendEmailFromTemplate(
|
||||
renderNewJobsAvailableEmail,
|
||||
@@ -28,6 +20,4 @@ export default async function sendOpenJobsEmails() {
|
||||
},
|
||||
doctorEmails,
|
||||
);
|
||||
|
||||
return doctorAccounts.filter((email) => !!email).map(({ id }) => id);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ export default async function syncAnalysisGroups() {
|
||||
|
||||
try {
|
||||
console.info('Getting latest public message id');
|
||||
// const lastCheckedDate = await getLastCheckedDate(); never used?
|
||||
const lastCheckedDate = await getLastCheckedDate();
|
||||
|
||||
const latestMessage = await getLatestPublicMessageListItem();
|
||||
if (!latestMessage) {
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
import { createUserAnalysesApi } from '@/packages/features/user-analyses/src/server/api';
|
||||
import { getSupabaseServerClient } from '@/packages/supabase/src/clients/server-client';
|
||||
|
||||
import { readPrivateMessageResponse } from '~/lib/services/medipost/medipostPrivateMessage.service';
|
||||
|
||||
type ProcessedMessage = {
|
||||
@@ -19,8 +16,6 @@ type GroupedResults = {
|
||||
|
||||
export default async function syncAnalysisResults() {
|
||||
console.info('Syncing analysis results');
|
||||
const supabase = getSupabaseServerClient();
|
||||
const api = createUserAnalysesApi(supabase);
|
||||
|
||||
const processedMessages: ProcessedMessage[] = [];
|
||||
const excludedMessageIds: string[] = [];
|
||||
@@ -30,12 +25,6 @@ export default async function syncAnalysisResults() {
|
||||
processedMessages.push(result as ProcessedMessage);
|
||||
}
|
||||
|
||||
await api.sendAnalysisResultsNotification({
|
||||
hasFullAnalysisResponse: result.hasFullAnalysisResponse,
|
||||
hasPartialAnalysisResponse: result.hasAnalysisResponse,
|
||||
analysisOrderId: result.analysisOrderId,
|
||||
});
|
||||
|
||||
if (!result.messageId) {
|
||||
console.info('No more messages to process');
|
||||
break;
|
||||
|
||||
@@ -81,19 +81,21 @@ export default async function syncConnectedOnline() {
|
||||
});
|
||||
}
|
||||
|
||||
let clinics;
|
||||
let services;
|
||||
let serviceProviders;
|
||||
let jobTitleTranslations;
|
||||
// Filter out "Dentas Demo OÜ" in prod or only sync "Dentas Demo OÜ" in any other environment
|
||||
const isDemoClinic = (clinicId: number) =>
|
||||
isProd ? clinicId !== 2 : clinicId === 2;
|
||||
const clinics = responseData.Data.T_Lic.filter(({ ID }) =>
|
||||
isDemoClinic(ID),
|
||||
);
|
||||
const services = responseData.Data.T_Service.filter(({ ClinicID }) =>
|
||||
clinics = responseData.Data.T_Lic.filter(({ ID }) => isDemoClinic(ID));
|
||||
services = responseData.Data.T_Service.filter(({ ClinicID }) =>
|
||||
isDemoClinic(ClinicID),
|
||||
);
|
||||
const serviceProviders = responseData.Data.T_Doctor.filter(({ ClinicID }) =>
|
||||
serviceProviders = responseData.Data.T_Doctor.filter(({ ClinicID }) =>
|
||||
isDemoClinic(ClinicID),
|
||||
);
|
||||
const jobTitleTranslations = createTranslationMap(
|
||||
jobTitleTranslations = createTranslationMap(
|
||||
responseData.Data.P_JobTitleTranslations.filter(({ ClinicID }) =>
|
||||
isDemoClinic(ClinicID),
|
||||
),
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
import { getLogger } from '@/packages/shared/src/logger';
|
||||
import { retrieveOrder } from '@lib/data/orders';
|
||||
|
||||
import { getMedipostDispatchTries } from '~/lib/services/audit.service';
|
||||
@@ -11,17 +10,13 @@ import loadEnv from '../handler/load-env';
|
||||
import validateApiKey from '../handler/validate-api-key';
|
||||
|
||||
export const POST = async (request: NextRequest) => {
|
||||
const logger = await getLogger();
|
||||
const ctx = {
|
||||
api: '/job/medipost-retry-dispatch',
|
||||
};
|
||||
loadEnv();
|
||||
|
||||
const { medusaOrderId } = await request.json();
|
||||
|
||||
try {
|
||||
validateApiKey(request);
|
||||
} catch {
|
||||
} catch (e) {
|
||||
return NextResponse.json({}, { status: 401, statusText: 'Unauthorized' });
|
||||
}
|
||||
|
||||
@@ -41,15 +36,15 @@ export const POST = async (request: NextRequest) => {
|
||||
medusaOrder,
|
||||
});
|
||||
await sendOrderToMedipost({ medusaOrderId, orderedAnalysisElements });
|
||||
logger.info(ctx, 'Successfully sent order to medipost');
|
||||
console.info('Successfully sent order to medipost');
|
||||
return NextResponse.json(
|
||||
{
|
||||
message: 'Successfully sent order to medipost',
|
||||
},
|
||||
{ status: 200 },
|
||||
);
|
||||
} catch (error) {
|
||||
logger.error({ ...ctx, error }, 'Error sending order to medipost');
|
||||
} catch (e) {
|
||||
console.error('Error sending order to medipost', e);
|
||||
return NextResponse.json(
|
||||
{
|
||||
message: 'Failed to send order to medipost',
|
||||
|
||||
@@ -14,19 +14,18 @@ export const POST = async (request: NextRequest) => {
|
||||
|
||||
try {
|
||||
validateApiKey(request);
|
||||
} catch {
|
||||
} catch (e) {
|
||||
return NextResponse.json({}, { status: 401, statusText: 'Unauthorized' });
|
||||
}
|
||||
|
||||
try {
|
||||
const doctors = await sendOpenJobsEmails();
|
||||
await sendOpenJobsEmails();
|
||||
console.info(
|
||||
'Successfully sent out open job notification emails to doctors',
|
||||
'Successfully sent out open job notification emails to doctors.',
|
||||
);
|
||||
await createNotificationLog({
|
||||
action: NotificationAction.DOCTOR_NEW_JOBS,
|
||||
status: 'SUCCESS',
|
||||
comment: `doctors that received email: ${doctors}`,
|
||||
});
|
||||
return NextResponse.json(
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ export const POST = async (request: NextRequest) => {
|
||||
|
||||
try {
|
||||
validateApiKey(request);
|
||||
} catch {
|
||||
} catch (e) {
|
||||
return NextResponse.json({}, { status: 401, statusText: 'Unauthorized' });
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ export const POST = async (request: NextRequest) => {
|
||||
|
||||
try {
|
||||
validateApiKey(request);
|
||||
} catch {
|
||||
} catch (e) {
|
||||
return NextResponse.json({}, { status: 401, statusText: 'Unauthorized' });
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ export const POST = async (request: NextRequest) => {
|
||||
|
||||
try {
|
||||
validateApiKey(request);
|
||||
} catch {
|
||||
} catch (e) {
|
||||
return NextResponse.json({}, { status: 401, statusText: 'Unauthorized' });
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ export const POST = async (request: NextRequest) => {
|
||||
|
||||
try {
|
||||
validateApiKey(request);
|
||||
} catch {
|
||||
} catch (e) {
|
||||
return NextResponse.json({}, { status: 401, statusText: 'Unauthorized' });
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
try {
|
||||
validateApiKey(request);
|
||||
} catch {
|
||||
} catch (e) {
|
||||
return NextResponse.json({}, { status: 401, statusText: 'Unauthorized' });
|
||||
}
|
||||
|
||||
|
||||
@@ -47,11 +47,6 @@ export async function GET(request: NextRequest) {
|
||||
|
||||
const service = createAuthCallbackService(getSupabaseServerClient());
|
||||
const oauthResult = await service.exchangeCodeForSession(authCode);
|
||||
|
||||
if (oauthResult.requiresMultiFactorAuthentication) {
|
||||
redirect(pathsConfig.auth.verifyMfa);
|
||||
}
|
||||
|
||||
if (!('isSuccess' in oauthResult)) {
|
||||
return redirectOnError(oauthResult.searchParams);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ const MembershipConfirmationNotification: React.FC<{
|
||||
descriptionKey="account:membershipConfirmation:successDescription"
|
||||
buttonProps={{
|
||||
buttonTitleKey: 'account:membershipConfirmation:successButton',
|
||||
href: pathsConfig.app.selectPackage,
|
||||
href: pathsConfig.app.home,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||
|
||||
async function SiteLayout(props: React.PropsWithChildren) {
|
||||
return (
|
||||
<div className={'flex min-h-[100vh] flex-col items-center justify-center'}>
|
||||
|
||||
@@ -181,74 +181,80 @@ export function UpdateAccountForm({
|
||||
)}
|
||||
/>
|
||||
|
||||
<>
|
||||
<FormField
|
||||
name="city"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>
|
||||
<Trans i18nKey={'common:formField:city'} />
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<div className="flex flex-row justify-between gap-4">
|
||||
{!isEmailUser && (
|
||||
<>
|
||||
<FormField
|
||||
name="weight"
|
||||
name="city"
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex-1 basis-0">
|
||||
<FormItem>
|
||||
<FormLabel>
|
||||
<Trans i18nKey={'common:formField:weight'} />
|
||||
<Trans i18nKey={'common:formField:city'} />
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
type="number"
|
||||
placeholder="kg"
|
||||
{...field}
|
||||
value={field.value ?? ''}
|
||||
onChange={(e) =>
|
||||
field.onChange(
|
||||
e.target.value === '' ? null : Number(e.target.value),
|
||||
)
|
||||
}
|
||||
/>
|
||||
<Input {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
name="height"
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex-1 basis-0">
|
||||
<FormLabel>
|
||||
<Trans i18nKey={'common:formField:height'} />
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
placeholder="cm"
|
||||
type="number"
|
||||
{...field}
|
||||
value={field.value ?? ''}
|
||||
onChange={(e) =>
|
||||
field.onChange(
|
||||
e.target.value === '' ? null : Number(e.target.value),
|
||||
)
|
||||
}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
<div className="flex flex-row justify-between gap-4">
|
||||
<FormField
|
||||
name="weight"
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex-1 basis-0">
|
||||
<FormLabel>
|
||||
<Trans i18nKey={'common:formField:weight'} />
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
type="number"
|
||||
placeholder="kg"
|
||||
{...field}
|
||||
value={field.value ?? ''}
|
||||
onChange={(e) =>
|
||||
field.onChange(
|
||||
e.target.value === ''
|
||||
? null
|
||||
: Number(e.target.value),
|
||||
)
|
||||
}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
name="height"
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex-1 basis-0">
|
||||
<FormLabel>
|
||||
<Trans i18nKey={'common:formField:height'} />
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
placeholder="cm"
|
||||
type="number"
|
||||
{...field}
|
||||
value={field.value ?? ''}
|
||||
onChange={(e) =>
|
||||
field.onChange(
|
||||
e.target.value === ''
|
||||
? null
|
||||
: Number(e.target.value),
|
||||
)
|
||||
}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
<FormField
|
||||
name="userConsent"
|
||||
|
||||
@@ -4,6 +4,7 @@ import { updateCustomer } from '@lib/data/customer';
|
||||
|
||||
import { AccountSubmitData, createAuthApi } from '@kit/auth/api';
|
||||
import { enhanceAction } from '@kit/next/actions';
|
||||
import { pathsConfig } from '@kit/shared/config';
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
|
||||
import { UpdateAccountSchemaServer } from '../schemas/update-account.schema';
|
||||
@@ -15,6 +16,7 @@ export const onUpdateAccount = enhanceAction(
|
||||
|
||||
try {
|
||||
await api.updateAccount(params);
|
||||
console.log('SUCCESS', pathsConfig.auth.updateAccountSuccess);
|
||||
} catch (err: unknown) {
|
||||
if (err instanceof Error) {
|
||||
console.warn('On update account error: ' + err.message);
|
||||
|
||||
@@ -44,7 +44,12 @@ async function VerifyPage(props: Props) {
|
||||
!!nextPath && nextPath.length > 0 ? nextPath : pathsConfig.app.home;
|
||||
|
||||
return (
|
||||
<MultiFactorChallengeContainer userId={user.id} paths={{ redirectPath }} />
|
||||
<MultiFactorChallengeContainer
|
||||
userId={user.id}
|
||||
paths={{
|
||||
redirectPath,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
'use server';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import { Spinner } from '@kit/ui/makerkit/spinner';
|
||||
import { Trans } from '@kit/ui/makerkit/trans';
|
||||
import { Progress } from '@kit/ui/shadcn/progress';
|
||||
|
||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||
|
||||
const AnalysisFallback = ({
|
||||
progress,
|
||||
progressTextKey,
|
||||
}: {
|
||||
progress: number;
|
||||
progressTextKey: string;
|
||||
}) => {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center gap-4 py-10">
|
||||
<Trans i18nKey={progressTextKey} />
|
||||
<Spinner />
|
||||
<Progress value={progress} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default withI18n(AnalysisFallback);
|
||||
@@ -1,177 +0,0 @@
|
||||
import React, { useState } from 'react';
|
||||
|
||||
import { giveFeedbackAction } from '@/packages/features/doctor/src/lib/server/actions/doctor-server-actions';
|
||||
import {
|
||||
DoctorFeedback,
|
||||
Order,
|
||||
Patient,
|
||||
} from '@/packages/features/doctor/src/lib/server/schema/doctor-analysis-detail-view.schema';
|
||||
import {
|
||||
DoctorAnalysisFeedbackForm,
|
||||
doctorAnalysisFeedbackFormSchema,
|
||||
} from '@/packages/features/doctor/src/lib/server/schema/doctor-analysis.schema';
|
||||
import ConfirmationModal from '@/packages/shared/src/components/confirmation-modal';
|
||||
import { useUser } from '@/packages/supabase/src/hooks/use-user';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { useForm } from 'react-hook-form';
|
||||
|
||||
import { Spinner } from '@kit/ui/makerkit/spinner';
|
||||
import { Trans } from '@kit/ui/makerkit/trans';
|
||||
import { Button } from '@kit/ui/shadcn/button';
|
||||
import {
|
||||
Form,
|
||||
FormControl,
|
||||
FormField,
|
||||
FormItem,
|
||||
FormMessage,
|
||||
} from '@kit/ui/shadcn/form';
|
||||
import { toast } from '@kit/ui/shadcn/sonner';
|
||||
import { Textarea } from '@kit/ui/shadcn/textarea';
|
||||
|
||||
const AnalysisFeedback = ({
|
||||
feedback,
|
||||
patient,
|
||||
order,
|
||||
aiDoctorFeedback,
|
||||
timestamp,
|
||||
recommendations,
|
||||
isRecommendationsEdited,
|
||||
}: {
|
||||
feedback?: DoctorFeedback;
|
||||
patient: Patient;
|
||||
order: Order;
|
||||
aiDoctorFeedback?: string;
|
||||
timestamp?: string;
|
||||
recommendations: string[];
|
||||
isRecommendationsEdited: boolean;
|
||||
}) => {
|
||||
const [isDraftSubmitting, setIsDraftSubmitting] = useState(false);
|
||||
const [isSubmittingFeedback, setIsSubmittingFeedback] = useState(false);
|
||||
const [isConfirmOpen, setIsConfirmOpen] = useState(false);
|
||||
const { data: user } = useUser();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const form = useForm({
|
||||
resolver: zodResolver(doctorAnalysisFeedbackFormSchema),
|
||||
reValidateMode: 'onChange',
|
||||
defaultValues: {
|
||||
feedbackValue: feedback?.value ?? aiDoctorFeedback ?? '',
|
||||
userId: patient.userId,
|
||||
},
|
||||
});
|
||||
|
||||
const isReadOnly =
|
||||
!!feedback?.doctor_user_id && feedback?.doctor_user_id !== user?.id;
|
||||
|
||||
const handleDraftSubmit = async (e: React.FormEvent) => {
|
||||
setIsDraftSubmitting(true);
|
||||
e.preventDefault();
|
||||
|
||||
form.formState.errors.feedbackValue = undefined;
|
||||
const formData = form.getValues();
|
||||
await onSubmit(formData, 'DRAFT');
|
||||
setIsDraftSubmitting(false);
|
||||
};
|
||||
const handleCompleteSubmit = form.handleSubmit(async () => {
|
||||
setIsConfirmOpen(true);
|
||||
});
|
||||
|
||||
const onSubmit = async (
|
||||
data: DoctorAnalysisFeedbackForm,
|
||||
status: 'DRAFT' | 'COMPLETED',
|
||||
) => {
|
||||
setIsConfirmOpen(false);
|
||||
setIsSubmittingFeedback(true);
|
||||
|
||||
const result = await giveFeedbackAction({
|
||||
...data,
|
||||
analysisOrderId: order.analysisOrderId,
|
||||
status,
|
||||
patientId: patient.userId,
|
||||
timestamp,
|
||||
recommendations,
|
||||
isRecommendationsEdited,
|
||||
});
|
||||
|
||||
if (!result.success) {
|
||||
return toast.error(<Trans i18nKey="common:genericServerError" />);
|
||||
}
|
||||
|
||||
setIsSubmittingFeedback(false);
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
predicate: (query) => query.queryKey.includes('doctor-jobs'),
|
||||
});
|
||||
|
||||
return toast.success(<Trans i18nKey={'doctor:updateFeedbackSuccess'} />);
|
||||
};
|
||||
|
||||
const confirmComplete = form.handleSubmit(async (data) => {
|
||||
await onSubmit(data, 'COMPLETED');
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
{!isReadOnly && (
|
||||
<Form {...form}>
|
||||
<form className="space-y-4 lg:w-1/2">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="feedbackValue"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormControl>
|
||||
<Textarea
|
||||
className="min-h-[200px]"
|
||||
{...field}
|
||||
disabled={isDraftSubmitting || isSubmittingFeedback}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<div className="xs:flex block justify-end gap-2 space-y-2">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={handleDraftSubmit}
|
||||
disabled={
|
||||
isReadOnly || isDraftSubmitting || form.formState.isSubmitting
|
||||
}
|
||||
className="xs:w-auto w-full text-xs"
|
||||
>
|
||||
<Trans i18nKey="common:saveAsDraft" />
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
onClick={handleCompleteSubmit}
|
||||
disabled={
|
||||
isReadOnly || isDraftSubmitting || form.formState.isSubmitting
|
||||
}
|
||||
className="xs:w-1/4 w-full"
|
||||
>
|
||||
{isDraftSubmitting || form.formState.isSubmitting ? (
|
||||
<Spinner />
|
||||
) : (
|
||||
<Trans i18nKey="common:save" />
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</Form>
|
||||
)}
|
||||
<ConfirmationModal
|
||||
isOpen={isConfirmOpen}
|
||||
onClose={() => setIsConfirmOpen(false)}
|
||||
onConfirm={confirmComplete}
|
||||
titleKey="doctor:confirmFeedbackModal.title"
|
||||
descriptionKey="doctor:confirmFeedbackModal.description"
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default AnalysisFeedback;
|
||||
@@ -1,10 +1,13 @@
|
||||
'use client';
|
||||
|
||||
import { useMemo, useState } from 'react';
|
||||
import { useState } from 'react';
|
||||
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { capitalize } from 'lodash';
|
||||
import { useForm } from 'react-hook-form';
|
||||
|
||||
import { giveFeedbackAction } from '@kit/doctor/actions/doctor-server-actions';
|
||||
import {
|
||||
getDOBWithAgeStringFromPersonalCode,
|
||||
getResultSetName,
|
||||
@@ -15,50 +18,46 @@ import {
|
||||
Order,
|
||||
Patient,
|
||||
} from '@kit/doctor/schema/doctor-analysis-detail-view.schema';
|
||||
import {
|
||||
DoctorAnalysisFeedbackForm,
|
||||
doctorAnalysisFeedbackFormSchema,
|
||||
} from '@kit/doctor/schema/doctor-analysis.schema';
|
||||
import ConfirmationModal from '@kit/shared/components/confirmation-modal';
|
||||
import { useCurrentLocaleLanguageNames } from '@kit/shared/hooks';
|
||||
import { getFullName } from '@kit/shared/utils';
|
||||
import { useUser } from '@kit/supabase/hooks/use-user';
|
||||
import { Button } from '@kit/ui/button';
|
||||
import {
|
||||
Form,
|
||||
FormControl,
|
||||
FormField,
|
||||
FormItem,
|
||||
FormMessage,
|
||||
} from '@kit/ui/form';
|
||||
import { toast } from '@kit/ui/sonner';
|
||||
import { Textarea } from '@kit/ui/textarea';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
import { bmiFromMetric } from '~/lib/utils';
|
||||
|
||||
import AnalysisFeedback from './analysis-feedback';
|
||||
import DoctorAnalysisWrapper from './doctor-analysis-wrapper';
|
||||
import DoctorJobSelect from './doctor-job-select';
|
||||
import DoctorRecommendedAnalyses from './doctor-recommended-analyses';
|
||||
|
||||
export default function AnalysisView({
|
||||
patient,
|
||||
order,
|
||||
analyses,
|
||||
feedback,
|
||||
aiDoctorFeedback,
|
||||
recommendations,
|
||||
availableAnalyses,
|
||||
timestamp,
|
||||
}: {
|
||||
patient: Patient;
|
||||
order: Order;
|
||||
analyses: AnalysisResponse[];
|
||||
feedback?: DoctorFeedback;
|
||||
aiDoctorFeedback?: string;
|
||||
recommendations?: string[];
|
||||
availableAnalyses?: string[];
|
||||
timestamp?: string;
|
||||
}) {
|
||||
const [isConfirmOpen, setIsConfirmOpen] = useState(false);
|
||||
const [isDraftSubmitting, setIsDraftSubmitting] = useState(false);
|
||||
|
||||
const { data: user } = useUser();
|
||||
const queryClient = useQueryClient();
|
||||
const [recommendedAnalyses, setRecommendedAnalyses] = useState<string[]>(
|
||||
recommendations ?? [],
|
||||
);
|
||||
const isRecommendationsEdited = useMemo(() => {
|
||||
if (recommendedAnalyses.length !== recommendations?.length) return true;
|
||||
const sa = new Set(recommendedAnalyses),
|
||||
sb = new Set(recommendations);
|
||||
if (sa.size !== sb.size) return true;
|
||||
for (const v of sa) if (!sb.has(v)) return true;
|
||||
return false;
|
||||
}, [recommendations, recommendedAnalyses]);
|
||||
|
||||
const languageNames = useCurrentLocaleLanguageNames();
|
||||
|
||||
@@ -69,11 +68,66 @@ export default function AnalysisView({
|
||||
);
|
||||
const isCurrentDoctorJob =
|
||||
!!feedback?.doctor_user_id && feedback?.doctor_user_id === user?.id;
|
||||
const isReadOnly =
|
||||
!isInProgress ||
|
||||
(!!feedback?.doctor_user_id && feedback?.doctor_user_id !== user?.id);
|
||||
|
||||
const form = useForm({
|
||||
resolver: zodResolver(doctorAnalysisFeedbackFormSchema),
|
||||
reValidateMode: 'onChange',
|
||||
defaultValues: {
|
||||
feedbackValue: feedback?.value ?? '',
|
||||
userId: patient.userId,
|
||||
},
|
||||
});
|
||||
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
if (!patient || !order || !analyses) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const onSubmit = async (
|
||||
data: DoctorAnalysisFeedbackForm,
|
||||
status: 'DRAFT' | 'COMPLETED',
|
||||
) => {
|
||||
const result = await giveFeedbackAction({
|
||||
...data,
|
||||
analysisOrderId: order.analysisOrderId,
|
||||
status,
|
||||
});
|
||||
|
||||
if (!result.success) {
|
||||
return toast.error(<Trans i18nKey="common:genericServerError" />);
|
||||
}
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
predicate: (query) => query.queryKey.includes('doctor-jobs'),
|
||||
});
|
||||
|
||||
toast.success(<Trans i18nKey={'doctor:updateFeedbackSuccess'} />);
|
||||
|
||||
return setIsConfirmOpen(false);
|
||||
};
|
||||
|
||||
const handleDraftSubmit = async (e: React.FormEvent) => {
|
||||
setIsDraftSubmitting(true);
|
||||
e.preventDefault();
|
||||
|
||||
form.formState.errors.feedbackValue = undefined;
|
||||
const formData = form.getValues();
|
||||
await onSubmit(formData, 'DRAFT');
|
||||
setIsDraftSubmitting(false);
|
||||
};
|
||||
|
||||
const handleCompleteSubmit = form.handleSubmit(async () => {
|
||||
setIsConfirmOpen(true);
|
||||
});
|
||||
|
||||
const confirmComplete = form.handleSubmit(async (data) => {
|
||||
await onSubmit(data, 'COMPLETED');
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="xs:flex xs:justify-between">
|
||||
@@ -175,30 +229,59 @@ export default function AnalysisView({
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
{order.isPackage && (
|
||||
<>
|
||||
<h3>
|
||||
<Trans i18nKey="doctor:feedback" />
|
||||
</h3>
|
||||
<p>{feedback?.value ?? '-'}</p>
|
||||
<div className="flex flex-col gap-4 lg:flex-row">
|
||||
<AnalysisFeedback
|
||||
order={order}
|
||||
patient={patient}
|
||||
feedback={feedback}
|
||||
aiDoctorFeedback={aiDoctorFeedback}
|
||||
timestamp={timestamp}
|
||||
recommendations={recommendedAnalyses}
|
||||
isRecommendationsEdited={isRecommendationsEdited}
|
||||
<h3>
|
||||
<Trans i18nKey="doctor:feedback" />
|
||||
</h3>
|
||||
<p>{feedback?.value ?? '-'}</p>
|
||||
{!isReadOnly && (
|
||||
<Form {...form}>
|
||||
<form className="space-y-4 lg:w-1/2">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="feedbackValue"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormControl>
|
||||
<Textarea {...field} disabled={isReadOnly} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<DoctorRecommendedAnalyses
|
||||
recommendedAnalyses={recommendedAnalyses}
|
||||
availableAnalyses={availableAnalyses}
|
||||
setRecommendedAnalyses={setRecommendedAnalyses}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
|
||||
<div className="xs:flex block justify-end gap-2 space-y-2">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={handleDraftSubmit}
|
||||
disabled={
|
||||
isReadOnly || isDraftSubmitting || form.formState.isSubmitting
|
||||
}
|
||||
className="xs:w-1/4 w-full"
|
||||
>
|
||||
<Trans i18nKey="common:saveAsDraft" />
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
onClick={handleCompleteSubmit}
|
||||
disabled={
|
||||
isReadOnly || isDraftSubmitting || form.formState.isSubmitting
|
||||
}
|
||||
className="xs:w-1/4 w-full"
|
||||
>
|
||||
<Trans i18nKey="common:save" />
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</Form>
|
||||
)}
|
||||
<ConfirmationModal
|
||||
isOpen={isConfirmOpen}
|
||||
onClose={() => setIsConfirmOpen(false)}
|
||||
onConfirm={confirmComplete}
|
||||
titleKey="doctor:confirmFeedbackModal.title"
|
||||
descriptionKey="doctor:confirmFeedbackModal.description"
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
|
||||
import ResultsTableWrapper from './results-table-wrapper';
|
||||
|
||||
export default function DoctorDashboard() {
|
||||
export default function Dashboard() {
|
||||
return (
|
||||
<>
|
||||
<ResultsTableWrapper
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import React, { Dispatch, SetStateAction } from 'react';
|
||||
|
||||
import { Trans } from '@kit/ui/makerkit/trans';
|
||||
import { Button } from '@kit/ui/shadcn/button';
|
||||
|
||||
const DoctorRecommendedAnalyses = ({
|
||||
recommendedAnalyses,
|
||||
availableAnalyses,
|
||||
setRecommendedAnalyses,
|
||||
}: {
|
||||
recommendedAnalyses?: string[];
|
||||
availableAnalyses?: string[];
|
||||
setRecommendedAnalyses: Dispatch<SetStateAction<string[]>>;
|
||||
}) => {
|
||||
if (availableAnalyses?.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="w-1/3">
|
||||
<h5>
|
||||
<Trans i18nKey="doctor:recommendedAnalyses" />
|
||||
</h5>
|
||||
<div className="mt-4 flex flex-wrap gap-2">
|
||||
{availableAnalyses?.map((analysis, index) => {
|
||||
return (
|
||||
<Button
|
||||
size="sm"
|
||||
key={`${index}-analysis-feedback-list`}
|
||||
variant={
|
||||
recommendedAnalyses?.includes(analysis) ? 'default' : 'outline'
|
||||
}
|
||||
type="button"
|
||||
onClick={() =>
|
||||
setRecommendedAnalyses((prev: string[]) =>
|
||||
prev.includes(analysis)
|
||||
? prev.filter((x) => x !== analysis)
|
||||
: [...prev, analysis],
|
||||
)
|
||||
}
|
||||
>
|
||||
{analysis}
|
||||
</Button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default DoctorRecommendedAnalyses;
|
||||
@@ -34,7 +34,7 @@ export function DoctorSidebar({
|
||||
<Sidebar collapsible="icon">
|
||||
<SidebarHeader className={'m-2'}>
|
||||
<AppLogo
|
||||
href={pathsConfig.app.home}
|
||||
href={pathsConfig.app.doctor}
|
||||
className="max-w-full"
|
||||
compact={!open}
|
||||
/>
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
'use server';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import { AnalysisResponses } from '@/app/home/(user)/_components/ai/types';
|
||||
import { OrderAnalysisCard } from '@/app/home/(user)/_components/order-analyses-cards';
|
||||
import { loadLifeStyle } from '@/app/home/(user)/_lib/server/load-life-style';
|
||||
import { loadRecommendations } from '@/app/home/(user)/_lib/server/load-recommendations';
|
||||
import { AccountWithParams } from '@/packages/features/accounts/src/types/accounts';
|
||||
import { AnalysisResultDetails } from '@/packages/features/doctor/src/lib/server/schema/doctor-analysis-detail-view.schema';
|
||||
|
||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||
|
||||
import {
|
||||
loadDoctorFeedback,
|
||||
prepareFeedback,
|
||||
} from '../_lib/server/load-doctor-feedback';
|
||||
import AnalysisView from './analysis-view';
|
||||
|
||||
async function NewAnalysisRecommendationsLoader({
|
||||
analysisResultDetails,
|
||||
account,
|
||||
analysisResponses,
|
||||
currentAIResponseTimestamp,
|
||||
analyses,
|
||||
patient,
|
||||
}: {
|
||||
currentAIResponseTimestamp: string;
|
||||
account: AccountWithParams | null;
|
||||
analysisResponses: AnalysisResponses;
|
||||
analysisResultDetails: AnalysisResultDetails;
|
||||
analyses: OrderAnalysisCard[];
|
||||
patient: AccountWithParams | null;
|
||||
}) {
|
||||
if (!analysisResultDetails.order.isPackage) {
|
||||
return (
|
||||
<AnalysisView
|
||||
patient={analysisResultDetails.patient}
|
||||
order={analysisResultDetails.order}
|
||||
analyses={analysisResultDetails.analysisResponse}
|
||||
feedback={analysisResultDetails.doctorFeedback}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const [lifeStyle, recommendations, aiFeedback] = await Promise.all([
|
||||
loadLifeStyle({
|
||||
account: patient,
|
||||
analysisResponses,
|
||||
isDoctorView: true,
|
||||
aiResponseTimestamp: currentAIResponseTimestamp,
|
||||
}),
|
||||
loadRecommendations({
|
||||
account: patient,
|
||||
analysisResponses,
|
||||
aiResponseTimestamp: currentAIResponseTimestamp,
|
||||
isDoctorView: true,
|
||||
analyses,
|
||||
}),
|
||||
loadDoctorFeedback(
|
||||
analysisResultDetails.patient,
|
||||
analysisResultDetails.analysisResponse,
|
||||
currentAIResponseTimestamp,
|
||||
),
|
||||
]);
|
||||
|
||||
const feedback = prepareFeedback({
|
||||
aiResponse: aiFeedback,
|
||||
recommendations,
|
||||
lifeStyleSummary: lifeStyle.response.summary,
|
||||
patientName: analysisResultDetails.patient.firstName,
|
||||
doctorName: `${account?.name} ${account?.last_name}`,
|
||||
aiResponseTimestamp: currentAIResponseTimestamp,
|
||||
});
|
||||
|
||||
return (
|
||||
<AnalysisView
|
||||
patient={analysisResultDetails.patient}
|
||||
order={analysisResultDetails.order}
|
||||
analyses={analysisResultDetails.analysisResponse}
|
||||
feedback={analysisResultDetails.doctorFeedback}
|
||||
aiDoctorFeedback={feedback}
|
||||
availableAnalyses={analyses.map((analysis) => analysis.title)}
|
||||
recommendations={recommendations}
|
||||
timestamp={currentAIResponseTimestamp}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default withI18n(NewAnalysisRecommendationsLoader);
|
||||
@@ -1,55 +0,0 @@
|
||||
'use server';
|
||||
|
||||
import React, { Suspense } from 'react';
|
||||
|
||||
import { loadAnalyses } from '@/app/home/(user)/_lib/server/load-analyses';
|
||||
import {
|
||||
loadCurrentUserAccount,
|
||||
loadUserAccount,
|
||||
} from '@/app/home/(user)/_lib/server/load-user-account';
|
||||
import { AnalysisResultDetails } from '@/packages/features/doctor/src/lib/server/schema/doctor-analysis-detail-view.schema';
|
||||
import { createUserAnalysesApi } from '@/packages/features/user-analyses/src/server/api';
|
||||
import { getSupabaseServerClient } from '@/packages/supabase/src/clients/server-client';
|
||||
|
||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||
import { getLatestResponseTime } from '~/lib/utils';
|
||||
|
||||
import AnalysisFallback from './analysis-fallback';
|
||||
import NewAnalysisRecommendationsLoader from './new-analysis-recommendations-loader';
|
||||
|
||||
async function PrepareAIParameters({
|
||||
analysisResultDetails,
|
||||
}: {
|
||||
analysisResultDetails: AnalysisResultDetails;
|
||||
}) {
|
||||
const { analyses } = await loadAnalyses();
|
||||
const { account: doctorAccount } = await loadCurrentUserAccount();
|
||||
const patientAccount = await loadUserAccount(
|
||||
analysisResultDetails.patient.userId,
|
||||
);
|
||||
const client = getSupabaseServerClient();
|
||||
const userAnalysesApi = createUserAnalysesApi(client);
|
||||
const analysisResponses = await userAnalysesApi.getAllUserAnalysisResponses(
|
||||
patientAccount.id,
|
||||
);
|
||||
const currentAIResponseTimestamp = getLatestResponseTime(analysisResponses);
|
||||
|
||||
return (
|
||||
<Suspense
|
||||
fallback={
|
||||
<AnalysisFallback progress={66} progressTextKey="doctor:loadFeedback" />
|
||||
}
|
||||
>
|
||||
<NewAnalysisRecommendationsLoader
|
||||
account={doctorAccount}
|
||||
currentAIResponseTimestamp={currentAIResponseTimestamp}
|
||||
analysisResponses={analysisResponses}
|
||||
analysisResultDetails={analysisResultDetails}
|
||||
analyses={analyses}
|
||||
patient={patientAccount}
|
||||
/>
|
||||
</Suspense>
|
||||
);
|
||||
}
|
||||
|
||||
export default withI18n(PrepareAIParameters);
|
||||
@@ -1,98 +0,0 @@
|
||||
import { cache } from 'react';
|
||||
|
||||
import { PROMPT_NAME } from '@/app/home/(user)/_components/ai/types';
|
||||
import { generateDoctorFeedback } from '@/app/home/(user)/_lib/server/ai-actions';
|
||||
import {
|
||||
AnalysisResponse,
|
||||
Patient,
|
||||
} from '@/packages/features/doctor/src/lib/server/schema/doctor-analysis-detail-view.schema';
|
||||
import { getLogger } from '@/packages/shared/src/logger';
|
||||
import { getSupabaseServerClient } from '@/packages/supabase/src/clients/server-client';
|
||||
|
||||
export const loadDoctorFeedback = cache(doctorFeedbackLoader);
|
||||
|
||||
const PLACEHOLDER = {
|
||||
ANALYSES: 'SOOVITATUD_ANALYYSID_PLACEHOLDER',
|
||||
LIFE_STYLE_SUMMARY: 'ELUSTIILI_KOKKUVOTTE_PLACEHOLDER',
|
||||
PATIENT_NAME: 'PATSIENDI_NIMI_PLACEHOLDER',
|
||||
DOCTOR_NAME: 'ARSTI_NIMI_PLACEHOLDER',
|
||||
ANALYSES_DATE: 'ANALYYSI_KUUPAEV_PLACEHOLDER',
|
||||
};
|
||||
|
||||
export const prepareFeedback = ({
|
||||
aiResponse,
|
||||
recommendations,
|
||||
lifeStyleSummary,
|
||||
patientName,
|
||||
doctorName,
|
||||
aiResponseTimestamp,
|
||||
}: {
|
||||
aiResponse: string;
|
||||
recommendations?: string[];
|
||||
lifeStyleSummary: string | null;
|
||||
patientName: string;
|
||||
doctorName: string;
|
||||
aiResponseTimestamp: string;
|
||||
}) => {
|
||||
const recommendationsList = recommendations
|
||||
? recommendations.map((analysis) => `${analysis}`).join('\n')
|
||||
: '';
|
||||
const feedback = aiResponse
|
||||
.replace(PLACEHOLDER.ANALYSES, recommendationsList)
|
||||
.replace(PLACEHOLDER.LIFE_STYLE_SUMMARY, lifeStyleSummary ?? '')
|
||||
.replace(PLACEHOLDER.PATIENT_NAME, patientName)
|
||||
.replace(PLACEHOLDER.DOCTOR_NAME, doctorName)
|
||||
.replace(
|
||||
PLACEHOLDER.ANALYSES_DATE,
|
||||
new Date(aiResponseTimestamp).toLocaleString(),
|
||||
);
|
||||
|
||||
return feedback;
|
||||
};
|
||||
|
||||
async function doctorFeedbackLoader(
|
||||
patient: Patient | null,
|
||||
analysisResponses: AnalysisResponse[],
|
||||
aiResponseTimestamp: string,
|
||||
): Promise<string> {
|
||||
const logger = await getLogger();
|
||||
if (!patient?.personalCode) {
|
||||
return '';
|
||||
}
|
||||
const supabaseClient = getSupabaseServerClient();
|
||||
|
||||
logger.info(
|
||||
{
|
||||
aiResponseTimestamp,
|
||||
patientId: patient.userId,
|
||||
},
|
||||
'Attempting to receive existing doctor feedback',
|
||||
);
|
||||
|
||||
const { data, error } = await supabaseClient
|
||||
.schema('medreport')
|
||||
.from('ai_responses')
|
||||
.select('*')
|
||||
.eq('account_id', patient.userId)
|
||||
.eq('prompt_name', PROMPT_NAME.FEEDBACK)
|
||||
.eq('latest_data_change', aiResponseTimestamp)
|
||||
.limit(1)
|
||||
.maybeSingle();
|
||||
|
||||
logger.info({ data: !!data }, 'Existing doctor feedback');
|
||||
|
||||
if (error) {
|
||||
console.error('Error fetching AI response from DB: ', error);
|
||||
return '';
|
||||
}
|
||||
|
||||
if (data?.response) {
|
||||
return data.response as string;
|
||||
} else {
|
||||
return await generateDoctorFeedback({
|
||||
patient,
|
||||
analysisResponses,
|
||||
aiResponseTimestamp,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,15 @@
|
||||
import { Suspense, cache } from 'react';
|
||||
import { cache } from 'react';
|
||||
|
||||
import { getAnalysisResultsForDoctor } from '@kit/doctor/services/doctor-analysis.service';
|
||||
import { PageBody, PageHeader } from '@kit/ui/page';
|
||||
|
||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||
import {
|
||||
DoctorPageViewAction,
|
||||
createDoctorPageViewLog,
|
||||
} from '~/lib/services/audit/doctorPageView.service';
|
||||
|
||||
import AnalysisFallback from '../../_components/analysis-fallback';
|
||||
import AnalysisView from '../../_components/analysis-view';
|
||||
import { DoctorGuard } from '../../_components/doctor-guard';
|
||||
import PrepareAiParameters from '../../_components/prepare-ai-parameters';
|
||||
|
||||
async function AnalysisPage({
|
||||
params,
|
||||
@@ -38,21 +36,17 @@ async function AnalysisPage({
|
||||
return (
|
||||
<>
|
||||
<PageHeader />
|
||||
<PageBody className="px-12">
|
||||
<Suspense
|
||||
fallback={
|
||||
<AnalysisFallback
|
||||
progress={33}
|
||||
progressTextKey="doctor:loadParameters"
|
||||
/>
|
||||
}
|
||||
>
|
||||
<PrepareAiParameters analysisResultDetails={analysisResultDetails} />
|
||||
</Suspense>
|
||||
<PageBody>
|
||||
<AnalysisView
|
||||
patient={analysisResultDetails.patient}
|
||||
order={analysisResultDetails.order}
|
||||
analyses={analysisResultDetails.analysisResponse}
|
||||
feedback={analysisResultDetails.doctorFeedback}
|
||||
/>
|
||||
</PageBody>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default DoctorGuard(withI18n(AnalysisPage));
|
||||
export default DoctorGuard(AnalysisPage);
|
||||
const loadResult = cache(getAnalysisResultsForDoctor);
|
||||
|
||||
@@ -17,7 +17,7 @@ async function CompletedJobsPage() {
|
||||
return (
|
||||
<>
|
||||
<PageHeader />
|
||||
<PageBody className="px-12">
|
||||
<PageBody>
|
||||
<ResultsTableWrapper
|
||||
titleKey="doctor:completedReviews"
|
||||
action={getUserDoneResponsesAction}
|
||||
|
||||
@@ -17,7 +17,7 @@ async function MyReviewsPage() {
|
||||
return (
|
||||
<>
|
||||
<PageHeader />
|
||||
<PageBody className="px-12">
|
||||
<PageBody>
|
||||
<ResultsTableWrapper
|
||||
titleKey="doctor:myReviews"
|
||||
action={getUserInProgressResponsesAction}
|
||||
|
||||
@@ -17,7 +17,7 @@ async function OpenJobsPage() {
|
||||
return (
|
||||
<>
|
||||
<PageHeader />
|
||||
<PageBody className="px-12">
|
||||
<PageBody>
|
||||
<ResultsTableWrapper
|
||||
titleKey="doctor:openReviews"
|
||||
action={getOpenResponsesAction}
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
createDoctorPageViewLog,
|
||||
} from '~/lib/services/audit/doctorPageView.service';
|
||||
|
||||
import DoctorDashboard from './_components/doctor-dashboard';
|
||||
import Dashboard from './_components/doctor-dashboard';
|
||||
import { DoctorGuard } from './_components/doctor-guard';
|
||||
|
||||
async function DoctorPage() {
|
||||
@@ -16,8 +16,8 @@ async function DoctorPage() {
|
||||
return (
|
||||
<>
|
||||
<PageHeader />
|
||||
<PageBody className="px-12">
|
||||
<DoctorDashboard />
|
||||
<PageBody>
|
||||
<Dashboard />
|
||||
</PageBody>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -3,9 +3,6 @@ import React from 'react';
|
||||
import Link from 'next/link';
|
||||
import { redirect } from 'next/navigation';
|
||||
|
||||
import { createNotificationsApi } from '@/packages/features/notifications/src/server/api';
|
||||
import { getSupabaseServerClient } from '@/packages/supabase/src/clients/server-client';
|
||||
|
||||
import { ButtonTooltip } from '@kit/shared/components/ui/button-tooltip';
|
||||
import { pathsConfig } from '@kit/shared/config';
|
||||
import { Button } from '@kit/ui/button';
|
||||
@@ -28,9 +25,7 @@ export default async function AnalysisResultsPage({
|
||||
id: string;
|
||||
}>;
|
||||
}) {
|
||||
const supabaseClient = getSupabaseServerClient();
|
||||
const { id: analysisOrderId } = await params;
|
||||
const notificationsApi = createNotificationsApi(supabaseClient);
|
||||
|
||||
const [{ account }, analysisResponse] = await Promise.all([
|
||||
loadCurrentUserAccount(),
|
||||
@@ -46,11 +41,6 @@ export default async function AnalysisResultsPage({
|
||||
action: PageViewAction.VIEW_ANALYSIS_RESULTS,
|
||||
});
|
||||
|
||||
await notificationsApi.dismissNotification(
|
||||
`/home/analysis-results/${analysisOrderId}`,
|
||||
'link',
|
||||
);
|
||||
|
||||
if (!analysisResponse) {
|
||||
return (
|
||||
<>
|
||||
@@ -118,7 +108,7 @@ export default async function AnalysisResultsPage({
|
||||
)}
|
||||
<div className="flex flex-col gap-2">
|
||||
{orderedAnalysisElements ? (
|
||||
orderedAnalysisElements.map((element) => (
|
||||
orderedAnalysisElements.map((element, index) => (
|
||||
<React.Fragment key={element.analysisIdOriginal}>
|
||||
<Analysis element={element} />
|
||||
{element.results?.nestedElements?.map(
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { use } from 'react';
|
||||
|
||||
import Link from 'next/link';
|
||||
|
||||
import { createI18nServerInstance } from '@/lib/i18n/i18n.server';
|
||||
|
||||
@@ -3,7 +3,6 @@ import { PageBody, PageHeader } from '@/packages/ui/src/makerkit/page';
|
||||
import { retrieveCart } from '@lib/data/cart';
|
||||
import { listProductTypes } from '@lib/data/products';
|
||||
|
||||
import { AccountBalanceService } from '@kit/accounts/services/account-balance.service';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||
@@ -12,8 +11,9 @@ import { findProductTypeIdByHandle } from '~/lib/utils';
|
||||
|
||||
import Cart from '../../_components/cart';
|
||||
import CartTimer from '../../_components/cart/cart-timer';
|
||||
import { EnrichedCartItem } from '../../_components/cart/types';
|
||||
import { loadCurrentUserAccount } from '../../_lib/server/load-user-account';
|
||||
import { AccountBalanceService } from '@kit/accounts/services/account-balance.service';
|
||||
import { EnrichedCartItem } from '../../_components/cart/types';
|
||||
|
||||
export async function generateMetadata() {
|
||||
const { t } = await createI18nServerInstance();
|
||||
@@ -24,7 +24,11 @@ export async function generateMetadata() {
|
||||
}
|
||||
|
||||
async function CartPage() {
|
||||
const [cart, { productTypes }, { account }] = await Promise.all([
|
||||
const [
|
||||
cart,
|
||||
{ productTypes },
|
||||
{ account },
|
||||
] = await Promise.all([
|
||||
retrieveCart(),
|
||||
listProductTypes(),
|
||||
loadCurrentUserAccount(),
|
||||
@@ -34,9 +38,7 @@ async function CartPage() {
|
||||
return null;
|
||||
}
|
||||
|
||||
const balanceSummary = await new AccountBalanceService().getBalanceSummary(
|
||||
account.id,
|
||||
);
|
||||
const balanceSummary = await new AccountBalanceService().getBalanceSummary(account.id);
|
||||
|
||||
const synlabAnalysisTypeId = findProductTypeIdByHandle(
|
||||
productTypes,
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
import React from 'react';
|
||||
|
||||
import { createUserAnalysesApi } from '@/packages/features/user-analyses/src/server/api';
|
||||
import { getSupabaseServerClient } from '@/packages/supabase/src/clients/server-client';
|
||||
|
||||
import { PageBody } from '@kit/ui/makerkit/page';
|
||||
import { Trans } from '@kit/ui/makerkit/trans';
|
||||
import { Skeleton } from '@kit/ui/shadcn/skeleton';
|
||||
|
||||
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||
import {
|
||||
PageViewAction,
|
||||
createPageViewLog,
|
||||
} from '~/lib/services/audit/pageView.service';
|
||||
import { getLatestResponseTime } from '~/lib/utils';
|
||||
|
||||
import { HomeLayoutPageHeader } from '../../_components/home-page-header';
|
||||
import { loadLifeStyle } from '../../_lib/server/load-life-style';
|
||||
import { loadCurrentUserAccount } from '../../_lib/server/load-user-account';
|
||||
|
||||
export async function generateMetadata() {
|
||||
const { t } = await createI18nServerInstance();
|
||||
|
||||
return {
|
||||
title: t('common:lifeStyle.title'),
|
||||
};
|
||||
}
|
||||
|
||||
async function LifeStylePage() {
|
||||
const { account } = await loadCurrentUserAccount();
|
||||
if (!account) {
|
||||
return null;
|
||||
}
|
||||
const client = getSupabaseServerClient();
|
||||
const userAnalysesApi = createUserAnalysesApi(client);
|
||||
const analysisResponses = await userAnalysesApi.getAllUserAnalysisResponses();
|
||||
const currentAIResponseTimestamp = getLatestResponseTime(analysisResponses);
|
||||
const { response } = await loadLifeStyle({
|
||||
account,
|
||||
analysisResponses,
|
||||
aiResponseTimestamp: currentAIResponseTimestamp,
|
||||
});
|
||||
|
||||
await createPageViewLog({
|
||||
accountId: account.id,
|
||||
action: PageViewAction.VIEW_LIFE_STYLE,
|
||||
});
|
||||
|
||||
if (!response.lifestyle) {
|
||||
return <Skeleton className="mt-10 h-10 w-full" />;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<HomeLayoutPageHeader
|
||||
title={<Trans i18nKey={'common:lifeStyle.title'} />}
|
||||
description=""
|
||||
/>
|
||||
|
||||
<PageBody>
|
||||
<div className="mt-8">
|
||||
{response.lifestyle.map(({ title, description }, index) => (
|
||||
<React.Fragment key={`${index}-${title}`}>
|
||||
<div className="flex items-center gap-2">
|
||||
<h3>{title}</h3>
|
||||
</div>
|
||||
<p className="font-regular py-4">{description}</p>
|
||||
</React.Fragment>
|
||||
))}
|
||||
</div>
|
||||
</PageBody>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default withI18n(LifeStylePage);
|
||||
@@ -28,18 +28,17 @@ async function OrderAnalysisPackagePage() {
|
||||
<PageBody>
|
||||
<div className="space-y-3 text-center">
|
||||
<h3>
|
||||
<Trans i18nKey="order-analysis-package:selectPackage" />
|
||||
<Trans i18nKey={'marketing:selectPackage'} />
|
||||
</h3>
|
||||
<ComparePackagesModal
|
||||
analysisPackages={analysisPackages}
|
||||
analysisPackageElements={analysisPackageElements}
|
||||
triggerElement={
|
||||
<Button variant="secondary" className="gap-2">
|
||||
<Trans i18nKey="order-analysis-package:comparePackages" />
|
||||
<Trans i18nKey={'marketing:comparePackages'} />
|
||||
<Scale className="size-4 stroke-[1.5px]" />
|
||||
</Button>
|
||||
}
|
||||
countryCode={countryCode}
|
||||
/>
|
||||
</div>
|
||||
<SelectAnalysisPackages
|
||||
|
||||
@@ -37,8 +37,8 @@ async function OrderAnalysisPage() {
|
||||
return (
|
||||
<>
|
||||
<HomeLayoutPageHeader
|
||||
title={<Trans i18nKey="order-analysis:title" />}
|
||||
description={<Trans i18nKey="order-analysis:description" />}
|
||||
title={<Trans i18nKey={'order-analysis:title'} />}
|
||||
description={<Trans i18nKey={'order-analysis:description'} />}
|
||||
/>
|
||||
<PageBody>
|
||||
<OrderAnalysesCards analyses={analyses} countryCode={countryCode} />
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
|
||||
import CartTotals from '@/app/home/(user)/_components/order/cart-totals';
|
||||
import OrderDetails from '@/app/home/(user)/_components/order/order-details';
|
||||
import OrderItems from '@/app/home/(user)/_components/order/order-items';
|
||||
import { retrieveOrder } from '@lib/data/orders';
|
||||
import { StoreOrder } from '@medusajs/types';
|
||||
import Divider from '@modules/common/components/divider';
|
||||
|
||||
import { GlobalLoader } from '@kit/ui/makerkit/global-loader';
|
||||
import { PageBody, PageHeader } from '@kit/ui/page';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
import { AnalysisOrder } from '~/lib/types/order';
|
||||
import { StoreOrder } from '@medusajs/types';
|
||||
import { AnalysisOrder } from '~/lib/types/analysis-order';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { retrieveOrder } from '@lib/data/orders';
|
||||
import { GlobalLoader } from '@kit/ui/makerkit/global-loader';
|
||||
|
||||
function OrderConfirmedLoadingWrapper({
|
||||
medusaOrder: initialMedusaOrder,
|
||||
@@ -22,8 +21,7 @@ function OrderConfirmedLoadingWrapper({
|
||||
medusaOrder: StoreOrder;
|
||||
order: AnalysisOrder;
|
||||
}) {
|
||||
const [medusaOrder, setMedusaOrder] =
|
||||
useState<StoreOrder>(initialMedusaOrder);
|
||||
const [medusaOrder, setMedusaOrder] = useState<StoreOrder>(initialMedusaOrder);
|
||||
const fetchingRef = useRef(false);
|
||||
|
||||
const paymentStatus = medusaOrder.payment_status;
|
||||
@@ -54,7 +52,7 @@ function OrderConfirmedLoadingWrapper({
|
||||
if (!isPaid) {
|
||||
return (
|
||||
<PageBody>
|
||||
<div className="flex h-full flex-col items-center justify-start pt-[10vh]">
|
||||
<div className="flex flex-col justify-start items-center h-full pt-[10vh]">
|
||||
<div>
|
||||
<GlobalLoader />
|
||||
</div>
|
||||
@@ -71,14 +69,7 @@ function OrderConfirmedLoadingWrapper({
|
||||
<PageHeader title={<Trans i18nKey="cart:orderConfirmed.title" />} />
|
||||
<Divider />
|
||||
<div className="small:grid-cols-[1fr_360px] grid grid-cols-1 gap-x-40 gap-y-6 lg:px-4">
|
||||
<OrderDetails
|
||||
order={{
|
||||
id: order.medusa_order_id,
|
||||
created_at: order.created_at,
|
||||
location: null,
|
||||
serviceProvider: null,
|
||||
}}
|
||||
/>
|
||||
<OrderDetails order={order} />
|
||||
<Divider />
|
||||
<OrderItems medusaOrder={medusaOrder} />
|
||||
<CartTotals medusaOrder={medusaOrder} />
|
||||
|
||||
@@ -7,7 +7,6 @@ import { pathsConfig } from '@kit/shared/config';
|
||||
|
||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||
import { getAnalysisOrder } from '~/lib/services/order.service';
|
||||
|
||||
import OrderConfirmedLoadingWrapper from './order-confirmed-loading-wrapper';
|
||||
|
||||
export async function generateMetadata() {
|
||||
@@ -37,9 +36,7 @@ async function OrderConfirmedPage(props: {
|
||||
redirect(pathsConfig.app.myOrders);
|
||||
}
|
||||
|
||||
return (
|
||||
<OrderConfirmedLoadingWrapper medusaOrder={medusaOrder} order={order} />
|
||||
);
|
||||
return <OrderConfirmedLoadingWrapper medusaOrder={medusaOrder} order={order} />;
|
||||
}
|
||||
|
||||
export default withI18n(OrderConfirmedPage);
|
||||
|
||||
@@ -4,7 +4,6 @@ import CartTotals from '@/app/home/(user)/_components/order/cart-totals';
|
||||
import OrderDetails from '@/app/home/(user)/_components/order/order-details';
|
||||
import OrderItems from '@/app/home/(user)/_components/order/order-items';
|
||||
import { createI18nServerInstance } from '@/lib/i18n/i18n.server';
|
||||
import { getSupabaseServerClient } from '@/packages/supabase/src/clients/server-client';
|
||||
import { retrieveOrder } from '@lib/data/orders';
|
||||
import Divider from '@modules/common/components/divider';
|
||||
|
||||
@@ -13,6 +12,7 @@ import { PageBody, PageHeader } from '@kit/ui/page';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||
import { getAnalysisOrder } from '~/lib/services/order.service';
|
||||
|
||||
export async function generateMetadata() {
|
||||
const { t } = await createI18nServerInstance();
|
||||
@@ -25,46 +25,11 @@ export async function generateMetadata() {
|
||||
async function OrderConfirmedPage(props: {
|
||||
params: Promise<{ orderId: string }>;
|
||||
}) {
|
||||
const supabaseClient = getSupabaseServerClient();
|
||||
const params = await props.params;
|
||||
const medusaOrder = await retrieveOrder(params.orderId).catch(() => null);
|
||||
if (!medusaOrder) {
|
||||
redirect(pathsConfig.app.myOrders);
|
||||
}
|
||||
const ttoReservationId =
|
||||
medusaOrder.items &&
|
||||
(medusaOrder.items.find(
|
||||
({ metadata }) => !!metadata?.connectedOnlineReservationId,
|
||||
)?.metadata?.connectedOnlineReservationId as number);
|
||||
|
||||
const [{ data: ttoReservation }] = await Promise.all([
|
||||
ttoReservationId
|
||||
? await supabaseClient
|
||||
.schema('medreport')
|
||||
.from('connected_online_reservation')
|
||||
.select('*')
|
||||
.eq('id', ttoReservationId)
|
||||
.single()
|
||||
: { data: null },
|
||||
]);
|
||||
const [{ data: location }, { data: serviceProvider }] = await Promise.all([
|
||||
ttoReservation
|
||||
? supabaseClient
|
||||
.schema('medreport')
|
||||
.from('connected_online_locations')
|
||||
.select('name,address')
|
||||
.eq('sync_id', ttoReservation.location_sync_id || 0)
|
||||
.single()
|
||||
: { data: null },
|
||||
ttoReservation
|
||||
? supabaseClient
|
||||
.schema('medreport')
|
||||
.from('connected_online_providers')
|
||||
.select('email,phone_number,name')
|
||||
.eq('id', ttoReservation.clinic_id)
|
||||
.single()
|
||||
: { data: null },
|
||||
]);
|
||||
|
||||
return (
|
||||
<PageBody>
|
||||
@@ -75,8 +40,6 @@ async function OrderConfirmedPage(props: {
|
||||
order={{
|
||||
id: medusaOrder.id,
|
||||
created_at: medusaOrder.created_at,
|
||||
location,
|
||||
serviceProvider,
|
||||
}}
|
||||
/>
|
||||
<Divider />
|
||||
|
||||
@@ -29,13 +29,12 @@ export async function generateMetadata() {
|
||||
}
|
||||
|
||||
async function OrdersPage() {
|
||||
const [medusaOrders, analysisOrders, ttoOrders, { productTypes }] =
|
||||
await Promise.all([
|
||||
listOrders(ORDERS_LIMIT),
|
||||
getAnalysisOrders(),
|
||||
getTtoOrders(),
|
||||
listProductTypes(),
|
||||
]);
|
||||
const [medusaOrders, analysisOrders, ttoOrders, { productTypes }] = await Promise.all([
|
||||
listOrders(ORDERS_LIMIT),
|
||||
getAnalysisOrders(),
|
||||
getTtoOrders(),
|
||||
listProductTypes(),
|
||||
]);
|
||||
|
||||
if (!medusaOrders || !productTypes || !ttoOrders) {
|
||||
redirect(pathsConfig.auth.signIn);
|
||||
@@ -58,24 +57,13 @@ async function OrdersPage() {
|
||||
/>
|
||||
<PageBody>
|
||||
{medusaOrders.map((medusaOrder) => {
|
||||
if (!medusaOrder) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const analysisOrder = analysisOrders.find(
|
||||
({ medusa_order_id }) => medusa_order_id === medusaOrder.id,
|
||||
);
|
||||
|
||||
const orderIds = new Set(
|
||||
(medusaOrder?.items ?? [])
|
||||
.map((i) => i?.metadata?.connectedOnlineReservationId)
|
||||
.filter(Boolean)
|
||||
.map(String),
|
||||
);
|
||||
|
||||
const ttoReservation = ttoOrders.find((o) =>
|
||||
orderIds.has(String(o.id)),
|
||||
);
|
||||
if (!medusaOrder) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const medusaOrderItems = medusaOrder.items || [];
|
||||
const medusaOrderItemsAnalysisPackages = medusaOrderItems.filter(
|
||||
@@ -92,21 +80,13 @@ async function OrdersPage() {
|
||||
),
|
||||
);
|
||||
|
||||
if (
|
||||
medusaOrderItemsAnalysisPackages.length === 0 &&
|
||||
medusaOrderItemsOther.length === 0 &&
|
||||
medusaOrderItemsTtoServices.length === 0
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<React.Fragment key={medusaOrder.id}>
|
||||
<Divider className="my-6" />
|
||||
<OrderBlock
|
||||
medusaOrderId={medusaOrder.id}
|
||||
analysisOrder={analysisOrder}
|
||||
ttoReservation={ttoReservation}
|
||||
medusaOrderStatus={medusaOrder.status}
|
||||
itemsAnalysisPackage={medusaOrderItemsAnalysisPackages}
|
||||
itemsTtoService={medusaOrderItemsTtoServices}
|
||||
itemsOther={medusaOrderItemsOther}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { Suspense } from 'react';
|
||||
|
||||
import { redirect } from 'next/navigation';
|
||||
|
||||
import { toTitleCase } from '@/lib/utils';
|
||||
@@ -10,9 +12,11 @@ import { createUserAnalysesApi } from '@kit/user-analyses/api';
|
||||
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||
|
||||
import AIBlocks from '../_components/ai/ai-blocks';
|
||||
import Dashboard from '../_components/dashboard';
|
||||
import DashboardCards from '../_components/dashboard-cards';
|
||||
import Recommendations from '../_components/recommendations';
|
||||
import RecommendationsSkeleton from '../_components/recommendations-skeleton';
|
||||
import { isValidOpenAiEnv } from '../_lib/server/is-valid-open-ai-env';
|
||||
import { loadCurrentUserAccount } from '../_lib/server/load-user-account';
|
||||
|
||||
export const generateMetadata = async () => {
|
||||
@@ -29,10 +33,7 @@ async function UserHomePage() {
|
||||
|
||||
const { account } = await loadCurrentUserAccount();
|
||||
const api = createUserAnalysesApi(client);
|
||||
const userAnalysesApi = createUserAnalysesApi(client);
|
||||
|
||||
const bmiThresholds = await api.fetchBmiThresholds();
|
||||
const analysisResponses = await userAnalysesApi.getAllUserAnalysisResponses();
|
||||
|
||||
if (!account) {
|
||||
redirect('/');
|
||||
@@ -52,13 +53,16 @@ async function UserHomePage() {
|
||||
/>
|
||||
<PageBody>
|
||||
<Dashboard account={account} bmiThresholds={bmiThresholds} />
|
||||
|
||||
<h4>
|
||||
<Trans i18nKey="dashboard:recommendations.title" />
|
||||
</h4>
|
||||
<div className="mt-4 grid gap-6 sm:grid-cols-3">
|
||||
<AIBlocks account={account} analysisResponses={analysisResponses} />
|
||||
</div>
|
||||
{(await isValidOpenAiEnv()) && (
|
||||
<>
|
||||
<h4>
|
||||
<Trans i18nKey="dashboard:recommendations.title" />
|
||||
</h4>
|
||||
<Suspense fallback={<RecommendationsSkeleton />}>
|
||||
<Recommendations account={account} />
|
||||
</Suspense>
|
||||
</>
|
||||
)}
|
||||
</PageBody>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
'use server';
|
||||
|
||||
import React, { Suspense } from 'react';
|
||||
|
||||
import { AccountWithParams } from '@/packages/features/accounts/src/types/accounts';
|
||||
|
||||
import { isValidOpenAiEnv } from '../../_lib/server/is-valid-open-ai-env';
|
||||
import LifeStyleCard from './life-style-card';
|
||||
import OrderAnalysesPackageCard from './order-analyses-package-card';
|
||||
import Recommendations from './recommendations';
|
||||
import RecommendationsSkeleton from './recommendations-skeleton';
|
||||
import { AnalysisResponses } from './types';
|
||||
|
||||
const AIBlocks = async ({
|
||||
account,
|
||||
analysisResponses,
|
||||
}: {
|
||||
account: AccountWithParams;
|
||||
analysisResponses?: AnalysisResponses;
|
||||
}) => {
|
||||
const isOpenAiAvailable = await isValidOpenAiEnv();
|
||||
|
||||
if (!isOpenAiAvailable) {
|
||||
return <OrderAnalysesPackageCard />;
|
||||
}
|
||||
|
||||
if (analysisResponses?.length === 0) {
|
||||
return (
|
||||
<>
|
||||
<OrderAnalysesPackageCard />
|
||||
<Suspense fallback={<RecommendationsSkeleton amount={1} />}>
|
||||
<LifeStyleCard
|
||||
account={account}
|
||||
analysisResponses={analysisResponses}
|
||||
/>
|
||||
</Suspense>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Suspense fallback={<RecommendationsSkeleton />}>
|
||||
<LifeStyleCard account={account} analysisResponses={analysisResponses} />
|
||||
<Recommendations
|
||||
account={account}
|
||||
analysisResponses={analysisResponses}
|
||||
/>
|
||||
</Suspense>
|
||||
);
|
||||
};
|
||||
|
||||
export default AIBlocks;
|
||||
@@ -1,56 +0,0 @@
|
||||
'use server';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import Link from 'next/link';
|
||||
|
||||
import { AccountWithParams } from '@/packages/features/accounts/src/types/accounts';
|
||||
import { pathsConfig } from '@/packages/shared/src/config';
|
||||
import { ChevronRight } from 'lucide-react';
|
||||
|
||||
import { Trans } from '@kit/ui/makerkit/trans';
|
||||
import { Button } from '@kit/ui/shadcn/button';
|
||||
import { Card, CardHeader } from '@kit/ui/shadcn/card';
|
||||
|
||||
import { getLatestResponseTime } from '~/lib/utils';
|
||||
|
||||
import { loadLifeStyle } from '../../_lib/server/load-life-style';
|
||||
import { AnalysisResponses } from './types';
|
||||
|
||||
const LifeStyleCard = async ({
|
||||
account,
|
||||
analysisResponses,
|
||||
}: {
|
||||
account: AccountWithParams;
|
||||
analysisResponses?: AnalysisResponses;
|
||||
}) => {
|
||||
const aiResponseTimestamp = getLatestResponseTime(analysisResponses);
|
||||
const { response, dateCreated } = await loadLifeStyle({
|
||||
account,
|
||||
analysisResponses,
|
||||
aiResponseTimestamp,
|
||||
});
|
||||
|
||||
return (
|
||||
<Card variant="gradient-success" className="flex flex-col justify-between">
|
||||
<CardHeader className="flex-row justify-between">
|
||||
<div>
|
||||
<span className="text-xs">
|
||||
{new Date(dateCreated).toLocaleString()}
|
||||
</span>
|
||||
<h5 className="flex flex-col">
|
||||
<Trans i18nKey="dashboard:heroCard.lifeStyle.title" />
|
||||
</h5>
|
||||
</div>
|
||||
<Link href={pathsConfig.app.lifeStyle}>
|
||||
<Button size="icon" variant="outline" className="px-2 text-black">
|
||||
<ChevronRight className="size-4 stroke-2" />
|
||||
</Button>
|
||||
</Link>
|
||||
</CardHeader>
|
||||
<span className="text-primary p-4 text-sm">{response.summary}</span>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default LifeStyleCard;
|
||||
@@ -1,51 +0,0 @@
|
||||
import React from 'react';
|
||||
|
||||
import Link from 'next/link';
|
||||
|
||||
import { pathsConfig } from '@/packages/shared/src/config';
|
||||
import { ChevronRight, HeartPulse } from 'lucide-react';
|
||||
|
||||
import { Trans } from '@kit/ui/makerkit/trans';
|
||||
import { Button } from '@kit/ui/shadcn/button';
|
||||
import {
|
||||
Card,
|
||||
CardDescription,
|
||||
CardFooter,
|
||||
CardHeader,
|
||||
} from '@kit/ui/shadcn/card';
|
||||
|
||||
const OrderAnalysesPackageCard = () => {
|
||||
return (
|
||||
<Card
|
||||
variant="gradient-success"
|
||||
className="xs:w-1/2 flex w-full flex-col justify-between sm:w-auto"
|
||||
>
|
||||
<CardHeader className="flex-row sm:pb-0">
|
||||
<div
|
||||
className={
|
||||
'bg-primary/10 mb-6 flex size-8 items-center-safe justify-center-safe rounded-full text-white'
|
||||
}
|
||||
>
|
||||
<HeartPulse className="size-4 fill-green-500" />
|
||||
</div>
|
||||
<div className="bg-warning ml-auto flex size-8 items-center-safe justify-center-safe rounded-full text-white">
|
||||
<Link href={pathsConfig.app.orderAnalysisPackage}>
|
||||
<Button size="icon" variant="outline" className="px-2 text-black">
|
||||
<ChevronRight className="size-4 stroke-2" />
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardFooter className="flex flex-col items-start gap-2">
|
||||
<h5>
|
||||
<Trans i18nKey="dashboard:heroCard.orderPackage.title" />
|
||||
</h5>
|
||||
<CardDescription className="text-primary">
|
||||
<Trans i18nKey="dashboard:heroCard.orderPackage.description" />
|
||||
</CardDescription>
|
||||
</CardFooter>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default OrderAnalysesPackageCard;
|
||||
@@ -1,67 +0,0 @@
|
||||
import React from 'react';
|
||||
|
||||
import { InfoTooltip } from '@/packages/shared/src/components/ui/info-tooltip';
|
||||
|
||||
import { Button } from '@kit/ui/shadcn/button';
|
||||
import {
|
||||
Card,
|
||||
CardDescription,
|
||||
CardFooter,
|
||||
CardHeader,
|
||||
} from '@kit/ui/shadcn/card';
|
||||
import { Skeleton } from '@kit/ui/skeleton';
|
||||
|
||||
const RecommendationsSkeleton = ({ amount = 2 }: { amount?: number }) => {
|
||||
const emptyData = [
|
||||
{
|
||||
title: '1',
|
||||
description: '',
|
||||
subtitle: '',
|
||||
variant: { id: '' },
|
||||
price: 1,
|
||||
},
|
||||
];
|
||||
return Array.from({ length: amount }, (_, index) => {
|
||||
const { title, description, subtitle } = emptyData[0]!;
|
||||
|
||||
return (
|
||||
<Skeleton key={title + index}>
|
||||
<Card>
|
||||
<CardHeader className="flex-row">
|
||||
<div
|
||||
className={
|
||||
'mb-6 flex size-8 items-center-safe justify-center-safe'
|
||||
}
|
||||
/>
|
||||
<div className="ml-auto flex size-8 items-center-safe justify-center-safe">
|
||||
<Button size="icon" className="px-2" />
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardFooter className="flex">
|
||||
<div className="flex flex-1 flex-col items-start">
|
||||
<h5>
|
||||
{title}
|
||||
{description && (
|
||||
<>
|
||||
{' '}
|
||||
<InfoTooltip
|
||||
content={
|
||||
<div className="flex flex-col gap-2">
|
||||
<span>{description}</span>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</h5>
|
||||
{subtitle && <CardDescription>{subtitle}</CardDescription>}
|
||||
</div>
|
||||
<div className="flex flex-col items-end gap-2 self-end text-sm"></div>
|
||||
</CardFooter>
|
||||
</Card>
|
||||
</Skeleton>
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
export default RecommendationsSkeleton;
|
||||
@@ -1,41 +0,0 @@
|
||||
'use server';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import { AccountWithParams } from '@/packages/features/accounts/src/types/accounts';
|
||||
|
||||
import { getLatestResponseTime } from '~/lib/utils';
|
||||
|
||||
import { loadAnalyses } from '../../_lib/server/load-analyses';
|
||||
import { loadRecommendations } from '../../_lib/server/load-recommendations';
|
||||
import OrderAnalysesCards from '../order-analyses-cards';
|
||||
import { AnalysisResponses } from './types';
|
||||
|
||||
export default async function Recommendations({
|
||||
account,
|
||||
analysisResponses,
|
||||
}: {
|
||||
account: AccountWithParams;
|
||||
analysisResponses?: AnalysisResponses;
|
||||
}) {
|
||||
const { analyses, countryCode } = await loadAnalyses();
|
||||
|
||||
const currentAIResponseTimestamp = getLatestResponseTime(analysisResponses);
|
||||
const analysisRecommendations = await loadRecommendations({
|
||||
account,
|
||||
analyses,
|
||||
analysisResponses,
|
||||
aiResponseTimestamp: currentAIResponseTimestamp,
|
||||
});
|
||||
const orderAnalyses = analyses.filter((analysis) =>
|
||||
analysisRecommendations.includes(analysis.title),
|
||||
);
|
||||
|
||||
if (orderAnalyses.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<OrderAnalysesCards analyses={orderAnalyses} countryCode={countryCode} />
|
||||
);
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
import { Database } from '@/packages/supabase/src/database.types';
|
||||
|
||||
export interface ILifeStyleResponse {
|
||||
lifestyle: {
|
||||
title: string;
|
||||
description: string;
|
||||
score: 0 | 1 | 2;
|
||||
}[];
|
||||
summary: string | null;
|
||||
}
|
||||
|
||||
export enum PROMPT_NAME {
|
||||
LIFE_STYLE = 'Life Style',
|
||||
ANALYSIS_RECOMMENDATIONS = 'Analysis Recommendations',
|
||||
FEEDBACK = 'Doctor Feedback',
|
||||
}
|
||||
|
||||
export type AnalysisResponses =
|
||||
Database['medreport']['Functions']['get_latest_analysis_response_elements_for_current_user']['Returns'];
|
||||
@@ -32,16 +32,7 @@ const BookingContainer = ({
|
||||
<BookingProvider category={{ products }} service={cartItem?.product}>
|
||||
<div className="xs:flex-row flex max-h-full flex-col gap-6">
|
||||
<div className="flex flex-col">
|
||||
<ServiceSelector
|
||||
products={products.filter((product) => {
|
||||
if (product.metadata?.serviceIds) {
|
||||
return Array.isArray(
|
||||
JSON.parse(product.metadata.serviceIds as string),
|
||||
);
|
||||
}
|
||||
return false;
|
||||
})}
|
||||
/>
|
||||
<ServiceSelector products={products} />
|
||||
<BookingCalendar />
|
||||
<LocationSelector />
|
||||
</div>
|
||||
|
||||
@@ -1,113 +0,0 @@
|
||||
import React from 'react';
|
||||
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { Trans } from '@kit/ui/makerkit/trans';
|
||||
import { cn } from '@kit/ui/shadcn';
|
||||
import { Button } from '@kit/ui/shadcn/button';
|
||||
|
||||
const BookingPagination = ({
|
||||
totalPages,
|
||||
setCurrentPage,
|
||||
currentPage,
|
||||
}: {
|
||||
totalPages: number;
|
||||
setCurrentPage: (page: number) => void;
|
||||
currentPage: number;
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const generatePageNumbers = () => {
|
||||
const pages = [];
|
||||
const maxVisiblePages = 5;
|
||||
|
||||
if (totalPages <= maxVisiblePages) {
|
||||
for (let i = 1; i <= totalPages; i++) {
|
||||
pages.push(i);
|
||||
}
|
||||
} else {
|
||||
if (currentPage <= 3) {
|
||||
for (let i = 1; i <= 4; i++) {
|
||||
pages.push(i);
|
||||
}
|
||||
pages.push('...');
|
||||
pages.push(totalPages);
|
||||
} else if (currentPage >= totalPages - 2) {
|
||||
pages.push(1);
|
||||
pages.push('...');
|
||||
for (let i = totalPages - 3; i <= totalPages; i++) {
|
||||
pages.push(i);
|
||||
}
|
||||
} else {
|
||||
pages.push(1);
|
||||
pages.push('...');
|
||||
for (let i = currentPage - 1; i <= currentPage + 1; i++) {
|
||||
pages.push(i);
|
||||
}
|
||||
pages.push('...');
|
||||
pages.push(totalPages);
|
||||
}
|
||||
}
|
||||
|
||||
return pages;
|
||||
};
|
||||
|
||||
if (totalPages === 0) {
|
||||
return (
|
||||
<div className="wrap text-muted-foreground flex size-full content-center-safe justify-center-safe">
|
||||
<p>{t('booking:noResults')}</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
totalPages > 1 && (
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="text-muted-foreground text-sm">
|
||||
{t('common:pageOfPages', {
|
||||
page: currentPage,
|
||||
total: totalPages,
|
||||
})}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-1">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setCurrentPage(currentPage - 1)}
|
||||
disabled={currentPage === 1}
|
||||
>
|
||||
<Trans i18nKey="common:previous" defaultValue="Previous" />
|
||||
</Button>
|
||||
|
||||
{generatePageNumbers().map((page, index) => (
|
||||
<Button
|
||||
key={index}
|
||||
variant={page === currentPage ? 'default' : 'outline'}
|
||||
size="sm"
|
||||
onClick={() => typeof page === 'number' && setCurrentPage(page)}
|
||||
disabled={page === '...'}
|
||||
className={cn(
|
||||
'min-w-[2rem]',
|
||||
page === '...' && 'cursor-default hover:bg-transparent',
|
||||
)}
|
||||
>
|
||||
{page}
|
||||
</Button>
|
||||
))}
|
||||
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setCurrentPage(currentPage + 1)}
|
||||
disabled={currentPage === totalPages}
|
||||
>
|
||||
<Trans i18nKey="common:next" defaultValue="Next" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
export default BookingPagination;
|
||||
@@ -45,13 +45,14 @@ export const BookingProvider: React.FC<{
|
||||
const updateTimeSlots = async (serviceIds: number[]) => {
|
||||
setIsLoadingTimeSlots(true);
|
||||
try {
|
||||
console.log('serviceIds', serviceIds, selectedLocationId);
|
||||
const response = await getAvailableTimeSlotsForDisplay(
|
||||
serviceIds,
|
||||
selectedLocationId,
|
||||
);
|
||||
setTimeSlots(response.timeSlots);
|
||||
setLocations(response.locations);
|
||||
} catch {
|
||||
} catch (error) {
|
||||
setTimeSlots(null);
|
||||
} finally {
|
||||
setIsLoadingTimeSlots(false);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Label } from '@medusajs/ui';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { RadioGroup, RadioGroupItem } from '@kit/ui/radio-group';
|
||||
import { Card } from '@kit/ui/shadcn/card';
|
||||
@@ -7,6 +8,7 @@ import { Trans } from '@kit/ui/trans';
|
||||
import { useBooking } from './booking.provider';
|
||||
|
||||
const LocationSelector = () => {
|
||||
const { t } = useTranslation();
|
||||
const { selectedLocationId, setSelectedLocationId, locations } = useBooking();
|
||||
|
||||
const onLocationSelect = (locationId: number | string | null) => {
|
||||
@@ -14,15 +16,6 @@ const LocationSelector = () => {
|
||||
setSelectedLocationId(Number(locationId));
|
||||
};
|
||||
|
||||
const uniqueLocations = locations?.filter((item, index, self) => {
|
||||
return (
|
||||
index ===
|
||||
self.findIndex(
|
||||
(loc) => loc.sync_id === item.sync_id && loc.name === item.name,
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
return (
|
||||
<Card className="mb-4 p-4">
|
||||
<h5 className="text-semibold mb-2">
|
||||
@@ -33,23 +26,20 @@ const LocationSelector = () => {
|
||||
className="mb-2 flex flex-col"
|
||||
onValueChange={(val) => onLocationSelect(val)}
|
||||
>
|
||||
{/* <div className="flex items-center gap-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<RadioGroupItem
|
||||
value="all"
|
||||
id="all"
|
||||
value={'all'}
|
||||
id={'all'}
|
||||
checked={selectedLocationId === null}
|
||||
/>
|
||||
<Label htmlFor="all">{t('booking:showAllLocations')}</Label>
|
||||
</div> */}
|
||||
{uniqueLocations?.map((location, index) => (
|
||||
<Label htmlFor={'all'}>{t('booking:showAllLocations')}</Label>
|
||||
</div>
|
||||
{locations?.map((location) => (
|
||||
<div key={location.sync_id} className="flex items-center gap-2">
|
||||
<RadioGroupItem
|
||||
value={location.sync_id.toString()}
|
||||
id={location.sync_id.toString()}
|
||||
checked={
|
||||
selectedLocationId === location.sync_id ||
|
||||
(index === 0 && selectedLocationId === null)
|
||||
}
|
||||
checked={selectedLocationId === location.sync_id}
|
||||
/>
|
||||
<Label htmlFor={location.sync_id.toString()}>
|
||||
{location.name}
|
||||
|
||||
@@ -11,7 +11,6 @@ import { pathsConfig } from '@kit/shared/config';
|
||||
import { formatDateAndTime } from '@kit/shared/utils';
|
||||
import { Button } from '@kit/ui/shadcn/button';
|
||||
import { Card } from '@kit/ui/shadcn/card';
|
||||
import { Skeleton } from '@kit/ui/shadcn/skeleton';
|
||||
import { toast } from '@kit/ui/sonner';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
import { cn } from '@kit/ui/utils';
|
||||
@@ -20,7 +19,6 @@ import { updateReservationTime } from '~/lib/services/reservation.service';
|
||||
|
||||
import { createInitialReservationAction } from '../../_lib/server/actions';
|
||||
import { EnrichedCartItem } from '../cart/types';
|
||||
import BookingPagination from './booking-pagination';
|
||||
import { ServiceProvider, TimeSlot } from './booking.context';
|
||||
import { useBooking } from './booking.provider';
|
||||
|
||||
@@ -70,16 +68,57 @@ const TimeSlots = ({
|
||||
}) ?? [],
|
||||
'StartTime',
|
||||
'asc',
|
||||
).filter(({ StartTime }) => isSameDay(StartTime, selectedDate)),
|
||||
),
|
||||
[booking.timeSlots, selectedDate],
|
||||
);
|
||||
|
||||
const totalPages = Math.ceil(filteredBookings.length / PAGE_SIZE);
|
||||
|
||||
const paginatedBookings = useMemo(() => {
|
||||
const startIndex = (currentPage - 1) * PAGE_SIZE;
|
||||
const endIndex = startIndex + PAGE_SIZE;
|
||||
return filteredBookings.slice(startIndex, endIndex);
|
||||
}, [filteredBookings, currentPage, PAGE_SIZE]);
|
||||
|
||||
const handlePageChange = (page: number) => {
|
||||
setCurrentPage(page);
|
||||
};
|
||||
|
||||
const generatePageNumbers = () => {
|
||||
const pages = [];
|
||||
const maxVisiblePages = 5;
|
||||
|
||||
if (totalPages <= maxVisiblePages) {
|
||||
for (let i = 1; i <= totalPages; i++) {
|
||||
pages.push(i);
|
||||
}
|
||||
} else {
|
||||
if (currentPage <= 3) {
|
||||
for (let i = 1; i <= 4; i++) {
|
||||
pages.push(i);
|
||||
}
|
||||
pages.push('...');
|
||||
pages.push(totalPages);
|
||||
} else if (currentPage >= totalPages - 2) {
|
||||
pages.push(1);
|
||||
pages.push('...');
|
||||
for (let i = totalPages - 3; i <= totalPages; i++) {
|
||||
pages.push(i);
|
||||
}
|
||||
} else {
|
||||
pages.push(1);
|
||||
pages.push('...');
|
||||
for (let i = currentPage - 1; i <= currentPage + 1; i++) {
|
||||
pages.push(i);
|
||||
}
|
||||
pages.push('...');
|
||||
pages.push(totalPages);
|
||||
}
|
||||
}
|
||||
|
||||
return pages;
|
||||
};
|
||||
|
||||
if (!booking?.timeSlots?.length) {
|
||||
return null;
|
||||
}
|
||||
@@ -104,17 +143,12 @@ const TimeSlots = ({
|
||||
timeSlot.StartTime,
|
||||
booking.selectedLocationId ? booking.selectedLocationId : null,
|
||||
comments,
|
||||
)
|
||||
.then(() => {
|
||||
if (onComplete) {
|
||||
onComplete();
|
||||
}
|
||||
router.push(pathsConfig.app.cart);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Booking error: ', error);
|
||||
throw error;
|
||||
});
|
||||
).then(() => {
|
||||
if (onComplete) {
|
||||
onComplete();
|
||||
}
|
||||
router.push(pathsConfig.app.cart);
|
||||
});
|
||||
|
||||
toast.promise(() => bookTimePromise, {
|
||||
success: <Trans i18nKey={'booking:bookTimeSuccess'} />,
|
||||
@@ -169,13 +203,10 @@ const TimeSlots = ({
|
||||
};
|
||||
|
||||
return (
|
||||
<Skeleton
|
||||
isLoading={booking.isLoadingTimeSlots}
|
||||
className="flex w-full flex-col gap-4"
|
||||
>
|
||||
<div className="flex w-full flex-col gap-4">
|
||||
<div className="flex h-full w-full flex-col gap-2 overflow-auto">
|
||||
{paginatedBookings.map((timeSlot, index) => {
|
||||
const isHaigeKassa = timeSlot.HKServiceID > 0;
|
||||
const isEHIF = timeSlot.HKServiceID > 0;
|
||||
const serviceProviderTitle = getServiceProviderTitle(
|
||||
currentLocale,
|
||||
timeSlot.serviceProvider,
|
||||
@@ -183,10 +214,9 @@ const TimeSlots = ({
|
||||
const price =
|
||||
booking.selectedService?.variants?.[0]?.calculated_price
|
||||
?.calculated_amount ?? cartItem?.unit_price;
|
||||
|
||||
return (
|
||||
<Card
|
||||
className="xs:flex xs:justify-between w-full justify-center-safe gap-3 p-4"
|
||||
className="xs:flex xs:justify-between grid w-full justify-center-safe gap-3 p-4"
|
||||
key={index}
|
||||
>
|
||||
<div>
|
||||
@@ -194,7 +224,7 @@ const TimeSlots = ({
|
||||
<div className="flex">
|
||||
<h5
|
||||
className={cn(
|
||||
(serviceProviderTitle || isHaigeKassa) &&
|
||||
(serviceProviderTitle || isEHIF) &&
|
||||
"after:mx-2 after:content-['·']",
|
||||
)}
|
||||
>
|
||||
@@ -202,14 +232,12 @@ const TimeSlots = ({
|
||||
</h5>
|
||||
{serviceProviderTitle && (
|
||||
<span
|
||||
className={cn(
|
||||
isHaigeKassa && "after:mx-2 after:content-['·']",
|
||||
)}
|
||||
className={cn(isEHIF && "after:mx-2 after:content-['·']")}
|
||||
>
|
||||
{serviceProviderTitle}
|
||||
</span>
|
||||
)}
|
||||
{isHaigeKassa && <span>{t('booking:ehifBooking')}</span>}
|
||||
{isEHIF && <span>{t('booking:ehifBooking')}</span>}
|
||||
</div>
|
||||
<div className="flex text-xs">{timeSlot.location?.address}</div>
|
||||
</div>
|
||||
@@ -228,14 +256,63 @@ const TimeSlots = ({
|
||||
</Card>
|
||||
);
|
||||
})}
|
||||
|
||||
{!paginatedBookings.length && (
|
||||
<div className="wrap text-muted-foreground flex size-full content-center-safe justify-center-safe">
|
||||
<p>{t('booking:noResults')}</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<BookingPagination
|
||||
totalPages={Math.ceil(filteredBookings.length / PAGE_SIZE)}
|
||||
setCurrentPage={setCurrentPage}
|
||||
currentPage={currentPage}
|
||||
/>
|
||||
</Skeleton>
|
||||
{totalPages > 1 && (
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="text-muted-foreground text-sm">
|
||||
{t('common:pageOfPages', {
|
||||
page: currentPage,
|
||||
total: totalPages,
|
||||
})}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-1">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => handlePageChange(currentPage - 1)}
|
||||
disabled={currentPage === 1}
|
||||
>
|
||||
<Trans i18nKey="common:previous" defaultValue="Previous" />
|
||||
</Button>
|
||||
|
||||
{generatePageNumbers().map((page, index) => (
|
||||
<Button
|
||||
key={index}
|
||||
variant={page === currentPage ? 'default' : 'outline'}
|
||||
size="sm"
|
||||
onClick={() =>
|
||||
typeof page === 'number' && handlePageChange(page)
|
||||
}
|
||||
disabled={page === '...'}
|
||||
className={cn(
|
||||
'min-w-[2rem]',
|
||||
page === '...' && 'cursor-default hover:bg-transparent',
|
||||
)}
|
||||
>
|
||||
{page}
|
||||
</Button>
|
||||
))}
|
||||
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => handlePageChange(currentPage + 1)}
|
||||
disabled={currentPage === totalPages}
|
||||
>
|
||||
<Trans i18nKey="common:next" defaultValue="Next" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
'use client';
|
||||
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { StoreCart, StoreCartLineItem } from '@medusajs/types';
|
||||
import { useFormContext } from 'react-hook-form';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { toast } from 'sonner';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { Form } from '@kit/ui/form';
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
@@ -19,6 +22,10 @@ import { Trans } from '@kit/ui/trans';
|
||||
import { updateCartPartnerLocation } from '../../_lib/server/update-cart-partner-location';
|
||||
import partnerLocations from './partner-locations.json';
|
||||
|
||||
const AnalysisLocationSchema = z.object({
|
||||
locationId: z.string().min(1),
|
||||
});
|
||||
|
||||
export default function AnalysisLocation({
|
||||
cart,
|
||||
synlabAnalyses,
|
||||
@@ -28,15 +35,21 @@ export default function AnalysisLocation({
|
||||
}) {
|
||||
const { t } = useTranslation('cart');
|
||||
|
||||
const { watch, setValue } = useFormContext();
|
||||
const currentValue = watch('locationId');
|
||||
const form = useForm<z.infer<typeof AnalysisLocationSchema>>({
|
||||
defaultValues: {
|
||||
locationId: (cart.metadata?.partner_location_id as string) ?? '',
|
||||
},
|
||||
resolver: zodResolver(AnalysisLocationSchema),
|
||||
});
|
||||
|
||||
const getLocation = (locationId: string) =>
|
||||
partnerLocations.find(({ name }) => name === locationId);
|
||||
|
||||
const selectedLocation = getLocation(currentValue);
|
||||
const selectedLocation = getLocation(form.watch('locationId'));
|
||||
|
||||
const handleUpdateCartPartnerLocation = async (locationId: string) => {
|
||||
const onSubmit = async ({
|
||||
locationId,
|
||||
}: z.infer<typeof AnalysisLocationSchema>) => {
|
||||
const promise = updateCartPartnerLocation({
|
||||
cartId: cart.id,
|
||||
lineIds: synlabAnalyses.map(({ id }) => id),
|
||||
@@ -57,48 +70,53 @@ export default function AnalysisLocation({
|
||||
<Trans i18nKey={'cart:locations.description'} />
|
||||
</p>
|
||||
|
||||
<div className="mb-2 flex w-full flex-1 gap-x-2">
|
||||
<Select
|
||||
value={currentValue}
|
||||
onValueChange={(value) => {
|
||||
setValue('locationId', value, {
|
||||
shouldValidate: true,
|
||||
shouldDirty: true,
|
||||
shouldTouch: true,
|
||||
});
|
||||
|
||||
return handleUpdateCartPartnerLocation(value);
|
||||
}}
|
||||
<Form {...form}>
|
||||
<form
|
||||
onSubmit={form.handleSubmit((data) => onSubmit(data))}
|
||||
className="mb-2 flex w-full flex-1 gap-x-2"
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder={t('cart:locations.locationSelect')} />
|
||||
</SelectTrigger>
|
||||
<Select
|
||||
value={form.watch('locationId')}
|
||||
onValueChange={(value) => {
|
||||
form.setValue('locationId', value, {
|
||||
shouldValidate: true,
|
||||
shouldDirty: true,
|
||||
shouldTouch: true,
|
||||
});
|
||||
|
||||
<SelectContent>
|
||||
{Object.entries(
|
||||
partnerLocations.reduce(
|
||||
(acc, curr) => ({
|
||||
...acc,
|
||||
[curr.city]: [
|
||||
...((acc[curr.city] as typeof partnerLocations) ?? []),
|
||||
curr,
|
||||
],
|
||||
}),
|
||||
{} as Record<string, typeof partnerLocations>,
|
||||
),
|
||||
).map(([city, locations]) => (
|
||||
<SelectGroup key={city}>
|
||||
<SelectLabel>{city}</SelectLabel>
|
||||
{locations.map((location) => (
|
||||
<SelectItem key={location.name} value={location.name}>
|
||||
{location.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectGroup>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
return onSubmit(form.getValues());
|
||||
}}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder={t('cart:locations.locationSelect')} />
|
||||
</SelectTrigger>
|
||||
|
||||
<SelectContent>
|
||||
{Object.entries(
|
||||
partnerLocations.reduce(
|
||||
(acc, curr) => ({
|
||||
...acc,
|
||||
[curr.city]: [
|
||||
...((acc[curr.city] as typeof partnerLocations) ?? []),
|
||||
curr,
|
||||
],
|
||||
}),
|
||||
{} as Record<string, typeof partnerLocations>,
|
||||
),
|
||||
).map(([city, locations]) => (
|
||||
<SelectGroup key={city}>
|
||||
<SelectLabel>{city}</SelectLabel>
|
||||
{locations.map((location) => (
|
||||
<SelectItem key={location.name} value={location.name}>
|
||||
{location.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectGroup>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</form>
|
||||
</Form>
|
||||
|
||||
{selectedLocation && (
|
||||
<div className="mb-4 flex flex-col gap-y-2">
|
||||
|
||||
@@ -1,219 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import { formatCurrency } from '@/packages/shared/src/utils';
|
||||
import {
|
||||
StoreCart,
|
||||
StoreCartLineItem,
|
||||
StoreCartPromotion,
|
||||
} from '@medusajs/types';
|
||||
import { Loader2 } from 'lucide-react';
|
||||
import { useFormContext } from 'react-hook-form';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { Button } from '@kit/ui/button';
|
||||
import { Card, CardContent, CardHeader } from '@kit/ui/card';
|
||||
import { Checkbox } from '@kit/ui/checkbox';
|
||||
import { FormControl, FormField, FormItem, FormLabel } from '@kit/ui/form';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
import { cn } from '~/lib/utils';
|
||||
|
||||
import AnalysisLocation from './analysis-location';
|
||||
import CartItems from './cart-items';
|
||||
import CartServiceItems from './cart-service-items';
|
||||
import DiscountCode from './discount-code';
|
||||
import { EnrichedCartItem, GetBalanceSummarySelection } from './types';
|
||||
|
||||
const IS_DISCOUNT_SHOWN = true as boolean;
|
||||
|
||||
export default function CartFormContent({
|
||||
cart,
|
||||
synlabAnalyses,
|
||||
ttoServiceItems,
|
||||
unavailableLineItemIds,
|
||||
isInitiatingSession,
|
||||
getBalanceSummarySelection,
|
||||
}: {
|
||||
cart: StoreCart & {
|
||||
promotions: StoreCartPromotion[];
|
||||
};
|
||||
synlabAnalyses: StoreCartLineItem[];
|
||||
ttoServiceItems: EnrichedCartItem[];
|
||||
unavailableLineItemIds?: string[];
|
||||
isInitiatingSession: boolean;
|
||||
getBalanceSummarySelection: GetBalanceSummarySelection;
|
||||
}) {
|
||||
const {
|
||||
i18n: { language },
|
||||
} = useTranslation();
|
||||
const { watch } = useFormContext();
|
||||
|
||||
const items = cart?.items ?? [];
|
||||
const hasCartItems = cart && Array.isArray(items) && items.length > 0;
|
||||
|
||||
const isLocationsShown = synlabAnalyses.length > 0;
|
||||
|
||||
const useCompanyBenefits = watch('useCompanyBenefits');
|
||||
const balanceSummary = getBalanceSummarySelection({ useCompanyBenefits });
|
||||
|
||||
const { benefitsAmount, benefitsAmountTotal, montonioAmount } =
|
||||
balanceSummary;
|
||||
|
||||
const hasBenefitsApplied = benefitsAmountTotal > 0 && !!useCompanyBenefits;
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="flex flex-col gap-y-6 bg-white">
|
||||
<CartItems
|
||||
cart={cart}
|
||||
items={synlabAnalyses}
|
||||
productColumnLabelKey="cart:items.synlabAnalyses.productColumnLabel"
|
||||
/>
|
||||
<CartServiceItems
|
||||
cart={cart}
|
||||
items={ttoServiceItems}
|
||||
productColumnLabelKey="cart:items.ttoServices.productColumnLabel"
|
||||
unavailableLineItemIds={unavailableLineItemIds}
|
||||
/>
|
||||
</div>
|
||||
{hasCartItems && (
|
||||
<>
|
||||
<div className="flex gap-x-4 px-4 pt-2 sm:justify-end sm:px-6 sm:pt-4">
|
||||
<div className="w-full sm:mr-[42px] sm:w-auto">
|
||||
<p className="text-muted-foreground ml-0 text-sm font-bold">
|
||||
<Trans i18nKey="cart:order.subtotal" />
|
||||
</p>
|
||||
</div>
|
||||
<div className={`sm:mr-[112px] sm:w-[50px]`}>
|
||||
<p className="text-right text-sm">
|
||||
{formatCurrency({
|
||||
value: cart.subtotal,
|
||||
currencyCode: cart.currency_code,
|
||||
locale: language,
|
||||
})}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
className={cn(
|
||||
'flex gap-x-4 px-4 pt-2 sm:justify-end sm:px-6 sm:pt-4',
|
||||
{
|
||||
'py-2 sm:py-4': !hasBenefitsApplied,
|
||||
},
|
||||
)}
|
||||
>
|
||||
<div className="w-full sm:mr-[42px] sm:w-auto">
|
||||
<p className="text-muted-foreground ml-0 text-sm font-bold">
|
||||
<Trans i18nKey="cart:order.promotionsTotal" />
|
||||
</p>
|
||||
</div>
|
||||
<div className={`sm:mr-[112px] sm:w-[50px]`}>
|
||||
<p className="text-right text-sm">
|
||||
{formatCurrency({
|
||||
value: cart.discount_total,
|
||||
currencyCode: cart.currency_code,
|
||||
locale: language,
|
||||
})}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{hasBenefitsApplied && (
|
||||
<div className="flex gap-x-4 px-4 py-2 sm:justify-end sm:px-6 sm:py-4">
|
||||
<div className="w-full sm:mr-[42px] sm:w-auto">
|
||||
<p className="text-muted-foreground ml-0 text-sm font-bold">
|
||||
<Trans i18nKey="cart:order.companyBenefitsTotal" />
|
||||
</p>
|
||||
</div>
|
||||
<div className={`sm:mr-[112px] sm:w-[50px]`}>
|
||||
<p className="text-right text-sm">
|
||||
{formatCurrency({
|
||||
value: benefitsAmount,
|
||||
currencyCode: cart.currency_code,
|
||||
locale: language,
|
||||
})}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex gap-x-4 px-4 py-2 sm:justify-end sm:px-6 sm:py-4">
|
||||
<div className="w-full sm:mr-[42px] sm:w-auto">
|
||||
<p className="ml-0 text-sm font-bold">
|
||||
<Trans i18nKey="cart:order.total" />
|
||||
</p>
|
||||
</div>
|
||||
<div className={`sm:mr-[112px] sm:w-[50px]`}>
|
||||
<p className="text-right text-sm">
|
||||
{formatCurrency({
|
||||
value: montonioAmount,
|
||||
currencyCode: cart.currency_code,
|
||||
locale: language,
|
||||
})}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{benefitsAmountTotal > 0 && (
|
||||
<FormField
|
||||
name="useCompanyBenefits"
|
||||
render={({ field }) => (
|
||||
<FormItem className="mt-8">
|
||||
<div className="flex flex-row items-center gap-2 pb-1">
|
||||
<FormControl>
|
||||
<Checkbox
|
||||
checked={field.value}
|
||||
onCheckedChange={field.onChange}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormLabel>
|
||||
<Trans i18nKey={'cart:companyBenefits.label'} />
|
||||
</FormLabel>
|
||||
</div>
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
<div className="flex flex-col gap-x-4 gap-y-6 py-4 sm:flex-row sm:py-8">
|
||||
{IS_DISCOUNT_SHOWN && (
|
||||
<Card className="flex w-full flex-col justify-between sm:w-1/2">
|
||||
<CardHeader className="pb-4">
|
||||
<h5>
|
||||
<Trans i18nKey="cart:discountCode.title" />
|
||||
</h5>
|
||||
</CardHeader>
|
||||
<CardContent className="h-full">
|
||||
<DiscountCode cart={{ ...cart }} />
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{isLocationsShown && (
|
||||
<Card className="flex w-full flex-col justify-between sm:w-1/2">
|
||||
<CardHeader className="pb-4">
|
||||
<h5>
|
||||
<Trans i18nKey="cart:locations.title" />
|
||||
</h5>
|
||||
</CardHeader>
|
||||
<CardContent className="h-full">
|
||||
<AnalysisLocation
|
||||
cart={{ ...cart }}
|
||||
synlabAnalyses={synlabAnalyses}
|
||||
/>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Button className="h-10" type="submit" disabled={isInitiatingSession}>
|
||||
{isInitiatingSession && (
|
||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||
)}
|
||||
<Trans i18nKey="cart:checkout.goToCheckout" />
|
||||
</Button>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import type { StoreCart } from '@medusajs/types';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { Form } from '@kit/ui/form';
|
||||
|
||||
const CartFormSchema = z.object({
|
||||
code: z.string().optional(),
|
||||
locationId: z.string().optional(),
|
||||
useCompanyBenefits: z.boolean(),
|
||||
});
|
||||
|
||||
export type CartFormOnSubmit = (
|
||||
data: z.infer<typeof CartFormSchema>,
|
||||
) => Promise<void>;
|
||||
|
||||
export default function CartForm({
|
||||
children,
|
||||
cart,
|
||||
onSubmit,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
cart: StoreCart;
|
||||
onSubmit: CartFormOnSubmit;
|
||||
}) {
|
||||
const form = useForm<z.infer<typeof CartFormSchema>>({
|
||||
defaultValues: {
|
||||
code: '',
|
||||
locationId: (cart.metadata?.partner_location_id as string) ?? '',
|
||||
useCompanyBenefits: true,
|
||||
},
|
||||
resolver: zodResolver(CartFormSchema),
|
||||
});
|
||||
|
||||
const handleSubmit: CartFormOnSubmit = async (data) => {
|
||||
await onSubmit(data);
|
||||
};
|
||||
|
||||
return (
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit((data) => handleSubmit(data))}>
|
||||
{children}
|
||||
</form>
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
@@ -38,7 +38,6 @@ const CartItemDelete = ({
|
||||
<button
|
||||
className="text-ui-fg-subtle hover:text-ui-fg-base flex cursor-pointer gap-x-1"
|
||||
onClick={() => handleDelete()}
|
||||
type="button"
|
||||
>
|
||||
{isDeleting ? <Spinner className="animate-spin" /> : <Trash />}
|
||||
<span>{children}</span>
|
||||
|
||||
@@ -20,7 +20,7 @@ export default function CartItem({
|
||||
} = useTranslation();
|
||||
|
||||
return (
|
||||
<TableRow className="sm:w-full" data-testid="product-row">
|
||||
<TableRow className="w-full" data-testid="product-row">
|
||||
<TableCell className="w-[100%] px-4 text-left sm:px-6">
|
||||
<p
|
||||
className="txt-medium-plus text-ui-fg-base"
|
||||
@@ -41,12 +41,11 @@ export default function CartItem({
|
||||
</TableCell>
|
||||
|
||||
<TableCell className="min-w-[80px] px-4 text-right sm:px-6">
|
||||
{item.total &&
|
||||
formatCurrency({
|
||||
value: item.total,
|
||||
currencyCode,
|
||||
locale: language,
|
||||
})}
|
||||
{formatCurrency({
|
||||
value: item.total,
|
||||
currencyCode,
|
||||
locale: language,
|
||||
})}
|
||||
</TableCell>
|
||||
|
||||
<TableCell className="px-4 text-right sm:px-6">
|
||||
|
||||
@@ -10,7 +10,6 @@ import {
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
import CartItem from './cart-item';
|
||||
import MobileCartItems from './mobile-cart-items';
|
||||
|
||||
export default function CartItems({
|
||||
cart,
|
||||
@@ -26,54 +25,37 @@ export default function CartItems({
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Table className="hidden border-separate rounded-lg border sm:block">
|
||||
<TableHeader className="text-ui-fg-subtle txt-medium-plus">
|
||||
<TableRow>
|
||||
<TableHead className="px-4 sm:px-6">
|
||||
<Trans i18nKey={productColumnLabelKey} />
|
||||
</TableHead>
|
||||
<TableHead className="px-4 sm:px-6">
|
||||
<Trans i18nKey="cart:table.quantity" />
|
||||
</TableHead>
|
||||
<TableHead className="min-w-[100px] px-4 sm:px-6">
|
||||
<Trans i18nKey="cart:table.price" />
|
||||
</TableHead>
|
||||
<TableHead className="min-w-[100px] px-4 text-right sm:px-6">
|
||||
<Trans i18nKey="cart:table.total" />
|
||||
</TableHead>
|
||||
<TableHead className="px-4 sm:px-6"></TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{items
|
||||
.sort((a, b) =>
|
||||
(a.created_at ?? '') > (b.created_at ?? '') ? -1 : 1,
|
||||
)
|
||||
.map((item) => (
|
||||
<CartItem
|
||||
key={item.id}
|
||||
item={item}
|
||||
currencyCode={cart.currency_code}
|
||||
/>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
|
||||
<div className="sm:hidden">
|
||||
<Table className="border-separate rounded-lg border">
|
||||
<TableHeader className="text-ui-fg-subtle txt-medium-plus">
|
||||
<TableRow>
|
||||
<TableHead className="px-4 sm:px-6">
|
||||
<Trans i18nKey={productColumnLabelKey} />
|
||||
</TableHead>
|
||||
<TableHead className="px-4 sm:px-6">
|
||||
<Trans i18nKey="cart:table.quantity" />
|
||||
</TableHead>
|
||||
<TableHead className="min-w-[100px] px-4 sm:px-6">
|
||||
<Trans i18nKey="cart:table.price" />
|
||||
</TableHead>
|
||||
<TableHead className="min-w-[100px] px-4 text-right sm:px-6">
|
||||
<Trans i18nKey="cart:table.total" />
|
||||
</TableHead>
|
||||
<TableHead className="px-4 sm:px-6"></TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{items
|
||||
.sort((a, b) =>
|
||||
(a.created_at ?? '') > (b.created_at ?? '') ? -1 : 1,
|
||||
)
|
||||
.map((item) => (
|
||||
<MobileCartItems
|
||||
<CartItem
|
||||
key={item.id}
|
||||
item={item}
|
||||
currencyCode={cart.currency_code}
|
||||
productColumnLabelKey={productColumnLabelKey}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
</TableBody>
|
||||
</Table>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,26 +1,76 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
|
||||
import { formatCurrency, formatDateAndTime } from '@/packages/shared/src/utils';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { Button } from '@kit/ui/button';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@kit/ui/dialog';
|
||||
import { TableCell, TableRow } from '@kit/ui/table';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
import BookingContainer from '../booking/booking-container';
|
||||
import CartItemDelete from './cart-item-delete';
|
||||
import { EnrichedCartItem } from './types';
|
||||
|
||||
const EditCartServiceItemModal = ({
|
||||
item,
|
||||
onComplete,
|
||||
}: {
|
||||
item: EnrichedCartItem | null;
|
||||
onComplete: () => void;
|
||||
}) => {
|
||||
if (!item) return null;
|
||||
|
||||
return (
|
||||
<Dialog defaultOpen>
|
||||
<DialogContent className="xs:max-w-[90vw] flex max-h-screen max-w-full flex-col items-center gap-4 space-y-4 overflow-y-scroll">
|
||||
<DialogHeader className="items-center text-center">
|
||||
<DialogTitle>
|
||||
<Trans i18nKey="cart:editServiceItem.title" />
|
||||
</DialogTitle>
|
||||
<DialogDescription>
|
||||
<Trans i18nKey="cart:editServiceItem.description" />
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div>
|
||||
{item.product && item.reservation.countryCode ? (
|
||||
<BookingContainer
|
||||
category={{
|
||||
products: [item.product],
|
||||
countryCode: item.reservation.countryCode,
|
||||
}}
|
||||
cartItem={item}
|
||||
onComplete={onComplete}
|
||||
/>
|
||||
) : (
|
||||
<p>
|
||||
<Trans i18nKey="booking:noProducts" />
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
|
||||
export default function CartServiceItem({
|
||||
item,
|
||||
currencyCode,
|
||||
isUnavailable,
|
||||
setEditingItem,
|
||||
}: {
|
||||
item: EnrichedCartItem;
|
||||
currencyCode: string;
|
||||
isUnavailable?: boolean;
|
||||
setEditingItem: (item: EnrichedCartItem | null) => void;
|
||||
}) {
|
||||
const [editingItem, setEditingItem] = useState<EnrichedCartItem | null>(null);
|
||||
const {
|
||||
i18n: { language },
|
||||
} = useTranslation();
|
||||
@@ -56,21 +106,16 @@ export default function CartServiceItem({
|
||||
</TableCell>
|
||||
|
||||
<TableCell className="min-w-[80px] px-4 text-right sm:px-6">
|
||||
{item.total &&
|
||||
formatCurrency({
|
||||
value: item.total,
|
||||
currencyCode,
|
||||
locale: language,
|
||||
})}
|
||||
{formatCurrency({
|
||||
value: item.total,
|
||||
currencyCode,
|
||||
locale: language,
|
||||
})}
|
||||
</TableCell>
|
||||
|
||||
<TableCell className="px-4 text-right sm:px-6">
|
||||
<span className="flex justify-end gap-x-1">
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
onClick={() => setEditingItem(item)}
|
||||
>
|
||||
<Button size="sm" onClick={() => setEditingItem(item)}>
|
||||
<Trans i18nKey="common:change" />
|
||||
</Button>
|
||||
</span>
|
||||
@@ -92,6 +137,10 @@ export default function CartServiceItem({
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
<EditCartServiceItemModal
|
||||
item={editingItem}
|
||||
onComplete={() => setEditingItem(null)}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,5 @@
|
||||
import { useState } from 'react';
|
||||
|
||||
import { StoreCart } from '@medusajs/types';
|
||||
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@kit/ui/shadcn/dialog';
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
@@ -18,52 +9,9 @@ import {
|
||||
} from '@kit/ui/table';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
import BookingContainer from '../booking/booking-container';
|
||||
import CartServiceItem from './cart-service-item';
|
||||
import MobileCartServiceItems from './mobile-cart-service-items';
|
||||
import { EnrichedCartItem } from './types';
|
||||
|
||||
const EditCartServiceItemModal = ({
|
||||
item,
|
||||
onComplete,
|
||||
}: {
|
||||
item: EnrichedCartItem | null;
|
||||
onComplete: () => void;
|
||||
}) => {
|
||||
if (!item) return null;
|
||||
|
||||
return (
|
||||
<Dialog defaultOpen>
|
||||
<DialogContent className="xs:max-w-[90vw] flex max-h-screen max-w-full flex-col items-center gap-4 space-y-4 overflow-y-scroll">
|
||||
<DialogHeader className="items-center text-center">
|
||||
<DialogTitle>
|
||||
<Trans i18nKey="cart:editServiceItem.title" />
|
||||
</DialogTitle>
|
||||
<DialogDescription>
|
||||
<Trans i18nKey="cart:editServiceItem.description" />
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div>
|
||||
{item.product && item.reservation.countryCode ? (
|
||||
<BookingContainer
|
||||
category={{
|
||||
products: [item.product],
|
||||
countryCode: item.reservation.countryCode,
|
||||
}}
|
||||
cartItem={item}
|
||||
onComplete={onComplete}
|
||||
/>
|
||||
) : (
|
||||
<p>
|
||||
<Trans i18nKey="booking:noProducts" />
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
|
||||
export default function CartServiceItems({
|
||||
cart,
|
||||
items,
|
||||
@@ -75,75 +23,50 @@ export default function CartServiceItems({
|
||||
productColumnLabelKey: string;
|
||||
unavailableLineItemIds?: string[];
|
||||
}) {
|
||||
const [editingItem, setEditingItem] = useState<EnrichedCartItem | null>(null);
|
||||
if (!items || items.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Table className="hidden border-separate rounded-lg border sm:block">
|
||||
<TableHeader className="text-ui-fg-subtle txt-medium-plus">
|
||||
<TableRow>
|
||||
<TableHead className="px-4 sm:px-6">
|
||||
<Trans i18nKey={productColumnLabelKey} />
|
||||
</TableHead>
|
||||
<TableHead className="px-4 sm:px-6">
|
||||
<Trans i18nKey="cart:table.time" />
|
||||
</TableHead>
|
||||
<TableHead className="px-4 sm:px-6">
|
||||
<Trans i18nKey="cart:table.location" />
|
||||
</TableHead>
|
||||
<TableHead className="px-4 sm:px-6">
|
||||
<Trans i18nKey="cart:table.quantity" />
|
||||
</TableHead>
|
||||
<TableHead className="min-w-[100px] px-4 sm:px-6">
|
||||
<Trans i18nKey="cart:table.price" />
|
||||
</TableHead>
|
||||
<TableHead className="min-w-[100px] px-4 text-right sm:px-6">
|
||||
<Trans i18nKey="cart:table.total" />
|
||||
</TableHead>
|
||||
<TableHead className="px-4 sm:px-6"></TableHead>
|
||||
<TableHead className="px-4 sm:px-6"></TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{items
|
||||
.sort((a, b) =>
|
||||
(a.created_at ?? '') > (b.created_at ?? '') ? -1 : 1,
|
||||
)
|
||||
.map((item) => (
|
||||
<CartServiceItem
|
||||
key={item.id}
|
||||
item={item}
|
||||
currencyCode={cart.currency_code}
|
||||
isUnavailable={unavailableLineItemIds?.includes(item.id)}
|
||||
setEditingItem={setEditingItem}
|
||||
/>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
<div className="sm:hidden">
|
||||
<Table className="border-separate rounded-lg border">
|
||||
<TableHeader className="text-ui-fg-subtle txt-medium-plus">
|
||||
<TableRow>
|
||||
<TableHead className="px-4 sm:px-6">
|
||||
<Trans i18nKey={productColumnLabelKey} />
|
||||
</TableHead>
|
||||
<TableHead className="px-4 sm:px-6">
|
||||
<Trans i18nKey="cart:table.time" />
|
||||
</TableHead>
|
||||
<TableHead className="px-4 sm:px-6">
|
||||
<Trans i18nKey="cart:table.location" />
|
||||
</TableHead>
|
||||
<TableHead className="px-4 sm:px-6">
|
||||
<Trans i18nKey="cart:table.quantity" />
|
||||
</TableHead>
|
||||
<TableHead className="min-w-[100px] px-4 sm:px-6">
|
||||
<Trans i18nKey="cart:table.price" />
|
||||
</TableHead>
|
||||
<TableHead className="min-w-[100px] px-4 text-right sm:px-6">
|
||||
<Trans i18nKey="cart:table.total" />
|
||||
</TableHead>
|
||||
<TableHead className="px-4 sm:px-6"></TableHead>
|
||||
<TableHead className="px-4 sm:px-6"></TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{items
|
||||
.sort((a, b) =>
|
||||
(a.created_at ?? '') > (b.created_at ?? '') ? -1 : 1,
|
||||
)
|
||||
.map((item) => (
|
||||
<MobileCartServiceItems
|
||||
<CartServiceItem
|
||||
key={item.id}
|
||||
item={item}
|
||||
currencyCode={cart.currency_code}
|
||||
isUnavailable={unavailableLineItemIds?.includes(item.id)}
|
||||
productColumnLabelKey={productColumnLabelKey}
|
||||
setEditingItem={setEditingItem}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<EditCartServiceItemModal
|
||||
item={editingItem}
|
||||
onComplete={() => setEditingItem(null)}
|
||||
/>
|
||||
</>
|
||||
</TableBody>
|
||||
</Table>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState } from 'react';
|
||||
import React from 'react';
|
||||
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { convertToLocale } from '@lib/util/money';
|
||||
import { StoreCart, StoreCartPromotion } from '@medusajs/types';
|
||||
import { StoreCart, StorePromotion } from '@medusajs/types';
|
||||
import { Badge, Text } from '@medusajs/ui';
|
||||
import Trash from '@modules/common/icons/trash';
|
||||
import { useFormContext } from 'react-hook-form';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { Button } from '@kit/ui/button';
|
||||
import { FormControl, FormField, FormItem } from '@kit/ui/form';
|
||||
import { Form, FormControl, FormField, FormItem } from '@kit/ui/form';
|
||||
import { Input } from '@kit/ui/input';
|
||||
import { toast } from '@kit/ui/sonner';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
@@ -20,22 +22,21 @@ import {
|
||||
removePromotionCodeAction,
|
||||
} from './discount-code-actions';
|
||||
|
||||
const DiscountCodeSchema = z.object({
|
||||
code: z.string().min(1),
|
||||
});
|
||||
|
||||
export default function DiscountCode({
|
||||
cart,
|
||||
}: {
|
||||
cart: StoreCart & {
|
||||
promotions: StoreCartPromotion[];
|
||||
promotions: StorePromotion[];
|
||||
};
|
||||
}) {
|
||||
const { t } = useTranslation('cart');
|
||||
|
||||
const { setValue, watch } = useFormContext();
|
||||
const currentValue = watch('code');
|
||||
|
||||
const { promotions = [] } = cart;
|
||||
|
||||
const [isAddingPromotionCode, setIsAddingPromotionCode] = useState(false);
|
||||
|
||||
const removePromotionCode = async (code: string) => {
|
||||
const appliedCodes = promotions
|
||||
.filter((p) => p.code !== undefined)
|
||||
@@ -54,56 +55,57 @@ export default function DiscountCode({
|
||||
};
|
||||
|
||||
const addPromotionCode = async (code: string) => {
|
||||
if (!code || code.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
setIsAddingPromotionCode(true);
|
||||
const loading = toast.loading(t('cart:discountCode.addLoading'));
|
||||
const result = await addPromotionCodeAction(code);
|
||||
|
||||
toast.dismiss(loading);
|
||||
if (result.success) {
|
||||
toast.success(t('cart:discountCode.addSuccess'));
|
||||
setValue('code', '');
|
||||
form.reset();
|
||||
} else {
|
||||
toast.error(t('cart:discountCode.addError'));
|
||||
}
|
||||
setIsAddingPromotionCode(false);
|
||||
};
|
||||
|
||||
const form = useForm<z.infer<typeof DiscountCodeSchema>>({
|
||||
defaultValues: {
|
||||
code: '',
|
||||
},
|
||||
resolver: zodResolver(DiscountCodeSchema),
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="txt-medium flex h-full w-full flex-col gap-y-4 bg-white">
|
||||
<p className="text-muted-foreground text-sm">
|
||||
<Trans i18nKey={'cart:discountCode.subtitle'} />
|
||||
</p>
|
||||
|
||||
<div className="mb-2 flex w-full flex-1 flex-col gap-x-2 gap-y-2 sm:flex-row">
|
||||
<FormField
|
||||
name={'code'}
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex-1">
|
||||
<FormControl>
|
||||
<Input
|
||||
type="text"
|
||||
{...field}
|
||||
placeholder={t('cart:discountCode.placeholder')}
|
||||
/>
|
||||
</FormControl>
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Button
|
||||
type="button"
|
||||
variant="secondary"
|
||||
className="h-min"
|
||||
onClick={() => addPromotionCode(currentValue)}
|
||||
disabled={isAddingPromotionCode}
|
||||
<Form {...form}>
|
||||
<form
|
||||
onSubmit={form.handleSubmit((data) => addPromotionCode(data.code))}
|
||||
className="mb-2 flex w-full flex-1 flex-col gap-x-2 gap-y-2 sm:flex-row"
|
||||
>
|
||||
<Trans i18nKey={'cart:discountCode.apply'} />
|
||||
</Button>
|
||||
</div>
|
||||
<FormField
|
||||
name={'code'}
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex-1">
|
||||
<FormControl>
|
||||
<Input
|
||||
required
|
||||
type="text"
|
||||
{...field}
|
||||
placeholder={t('cart:discountCode.placeholder')}
|
||||
/>
|
||||
</FormControl>
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Button type="submit" variant="secondary" className="h-min">
|
||||
<Trans i18nKey={'cart:discountCode.apply'} />
|
||||
</Button>
|
||||
</form>
|
||||
</Form>
|
||||
|
||||
{promotions.length > 0 && (
|
||||
<div className="mt-4 flex w-full items-center">
|
||||
|
||||
@@ -1,24 +1,27 @@
|
||||
'use client';
|
||||
|
||||
import { useCallback, useState } from 'react';
|
||||
import { useState } from 'react';
|
||||
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
import {
|
||||
StoreCart,
|
||||
StoreCartLineItem,
|
||||
StoreCartPromotion,
|
||||
} from '@medusajs/types';
|
||||
import { formatCurrency } from '@/packages/shared/src/utils';
|
||||
import { StoreCart, StoreCartLineItem } from '@medusajs/types';
|
||||
import { Loader2 } from 'lucide-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { AccountBalanceSummary } from '@kit/accounts/services/account-balance.service';
|
||||
import { Button } from '@kit/ui/button';
|
||||
import { Card, CardContent, CardHeader } from '@kit/ui/card';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
import AnalysisLocation from './analysis-location';
|
||||
import CartItems from './cart-items';
|
||||
import CartServiceItems from './cart-service-items';
|
||||
import DiscountCode from './discount-code';
|
||||
import { initiatePayment } from '../../_lib/server/cart-actions';
|
||||
import CartForm, { CartFormOnSubmit } from './cart-form';
|
||||
import CartFormContent from './cart-form-content';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { AccountBalanceSummary } from '@kit/accounts/services/account-balance.service';
|
||||
import { EnrichedCartItem } from './types';
|
||||
|
||||
const IS_DISCOUNT_SHOWN = true as boolean;
|
||||
|
||||
export default function Cart({
|
||||
accountId,
|
||||
cart,
|
||||
@@ -27,11 +30,7 @@ export default function Cart({
|
||||
balanceSummary,
|
||||
}: {
|
||||
accountId: string;
|
||||
cart:
|
||||
| (StoreCart & {
|
||||
promotions: StoreCartPromotion[];
|
||||
})
|
||||
| null;
|
||||
cart: StoreCart | null;
|
||||
synlabAnalyses: StoreCartLineItem[];
|
||||
ttoServiceItems: EnrichedCartItem[];
|
||||
balanceSummary: AccountBalanceSummary | null;
|
||||
@@ -45,47 +44,6 @@ export default function Cart({
|
||||
const [unavailableLineItemIds, setUnavailableLineItemIds] =
|
||||
useState<string[]>();
|
||||
|
||||
const getBalanceSummarySelection = useCallback(
|
||||
({
|
||||
useCompanyBenefits,
|
||||
}: {
|
||||
useCompanyBenefits: boolean;
|
||||
}): {
|
||||
benefitsAmount: number;
|
||||
benefitsAmountTotal: number;
|
||||
montonioAmount: number;
|
||||
} => {
|
||||
if (!cart) {
|
||||
return {
|
||||
benefitsAmount: 0,
|
||||
benefitsAmountTotal: 0,
|
||||
montonioAmount: 0,
|
||||
};
|
||||
}
|
||||
|
||||
const benefitsAmountTotal = balanceSummary?.totalBalance ?? 0;
|
||||
const cartTotal = cart.total;
|
||||
if (!useCompanyBenefits) {
|
||||
return {
|
||||
benefitsAmount: 0,
|
||||
benefitsAmountTotal,
|
||||
montonioAmount: cartTotal,
|
||||
};
|
||||
}
|
||||
|
||||
const benefitsAmount =
|
||||
benefitsAmountTotal > cartTotal ? cartTotal : benefitsAmountTotal;
|
||||
const montonioAmount =
|
||||
benefitsAmount > 0 ? cartTotal - benefitsAmount : cartTotal;
|
||||
return {
|
||||
benefitsAmount,
|
||||
benefitsAmountTotal,
|
||||
montonioAmount,
|
||||
};
|
||||
},
|
||||
[balanceSummary, cart],
|
||||
);
|
||||
|
||||
const items = cart?.items ?? [];
|
||||
const hasCartItems = cart && Array.isArray(items) && items.length > 0;
|
||||
|
||||
@@ -109,20 +67,16 @@ export default function Cart({
|
||||
);
|
||||
}
|
||||
|
||||
const initiateSession: CartFormOnSubmit = async ({ useCompanyBenefits }) => {
|
||||
async function initiateSession() {
|
||||
setIsInitiatingSession(true);
|
||||
|
||||
try {
|
||||
const { benefitsAmount } = getBalanceSummarySelection({
|
||||
useCompanyBenefits,
|
||||
const { url, isFullyPaidByBenefits, orderId, unavailableLineItemIds } = await initiatePayment({
|
||||
accountId,
|
||||
balanceSummary: balanceSummary!,
|
||||
cart: cart!,
|
||||
language,
|
||||
});
|
||||
const { url, isFullyPaidByBenefits, orderId, unavailableLineItemIds } =
|
||||
await initiatePayment({
|
||||
accountId,
|
||||
benefitsAmount,
|
||||
cart: cart!,
|
||||
language,
|
||||
});
|
||||
if (unavailableLineItemIds) {
|
||||
setUnavailableLineItemIds(unavailableLineItemIds);
|
||||
}
|
||||
@@ -138,20 +92,142 @@ export default function Cart({
|
||||
console.error('Failed to initiate payment', error);
|
||||
setIsInitiatingSession(false);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const isLocationsShown = synlabAnalyses.length > 0;
|
||||
|
||||
const companyBenefitsTotal = balanceSummary?.totalBalance ?? 0;
|
||||
const montonioTotal = cart && companyBenefitsTotal > 0 ? cart.total - companyBenefitsTotal : cart.total;
|
||||
|
||||
return (
|
||||
<div className="small:grid-cols-[1fr_360px] grid grid-cols-1 gap-x-40 lg:px-4">
|
||||
<CartForm cart={cart} onSubmit={initiateSession}>
|
||||
<CartFormContent
|
||||
<div className="flex flex-col gap-y-6 bg-white">
|
||||
<CartItems
|
||||
cart={cart}
|
||||
synlabAnalyses={synlabAnalyses}
|
||||
ttoServiceItems={ttoServiceItems}
|
||||
unavailableLineItemIds={unavailableLineItemIds}
|
||||
isInitiatingSession={isInitiatingSession}
|
||||
getBalanceSummarySelection={getBalanceSummarySelection}
|
||||
items={synlabAnalyses}
|
||||
productColumnLabelKey="cart:items.synlabAnalyses.productColumnLabel"
|
||||
/>
|
||||
</CartForm>
|
||||
<CartServiceItems
|
||||
cart={cart}
|
||||
items={ttoServiceItems}
|
||||
productColumnLabelKey="cart:items.ttoServices.productColumnLabel"
|
||||
unavailableLineItemIds={unavailableLineItemIds}
|
||||
/>
|
||||
</div>
|
||||
{hasCartItems && (
|
||||
<>
|
||||
<div className="flex gap-x-4 px-4 pt-2 sm:justify-end sm:px-6 sm:pt-4">
|
||||
<div className="w-full sm:mr-[42px] sm:w-auto">
|
||||
<p className="text-muted-foreground ml-0 text-sm font-bold">
|
||||
<Trans i18nKey="cart:order.subtotal" />
|
||||
</p>
|
||||
</div>
|
||||
<div className={`sm:mr-[112px] sm:w-[50px]`}>
|
||||
<p className="text-right text-sm">
|
||||
{formatCurrency({
|
||||
value: cart.subtotal,
|
||||
currencyCode: cart.currency_code,
|
||||
locale: language,
|
||||
})}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex gap-x-4 px-4 pt-2 sm:justify-end sm:px-6 sm:pt-4">
|
||||
<div className="w-full sm:mr-[42px] sm:w-auto">
|
||||
<p className="text-muted-foreground ml-0 text-sm font-bold">
|
||||
<Trans i18nKey="cart:order.promotionsTotal" />
|
||||
</p>
|
||||
</div>
|
||||
<div className={`sm:mr-[112px] sm:w-[50px]`}>
|
||||
<p className="text-right text-sm">
|
||||
{formatCurrency({
|
||||
value: cart.discount_total,
|
||||
currencyCode: cart.currency_code,
|
||||
locale: language,
|
||||
})}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{companyBenefitsTotal > 0 && (
|
||||
<div className="flex gap-x-4 px-4 py-2 sm:justify-end sm:px-6 sm:py-4">
|
||||
<div className="w-full sm:mr-[42px] sm:w-auto">
|
||||
<p className="text-muted-foreground ml-0 text-sm font-bold">
|
||||
<Trans i18nKey="cart:order.companyBenefitsTotal" />
|
||||
</p>
|
||||
</div>
|
||||
<div className={`sm:mr-[112px] sm:w-[50px]`}>
|
||||
<p className="text-right text-sm">
|
||||
{formatCurrency({
|
||||
value: (companyBenefitsTotal > cart.total ? cart.total : companyBenefitsTotal),
|
||||
currencyCode: cart.currency_code,
|
||||
locale: language,
|
||||
})}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex gap-x-4 px-4 sm:justify-end sm:px-6">
|
||||
<div className="w-full sm:mr-[42px] sm:w-auto">
|
||||
<p className="ml-0 text-sm font-bold">
|
||||
<Trans i18nKey="cart:order.total" />
|
||||
</p>
|
||||
</div>
|
||||
<div className={`sm:mr-[112px] sm:w-[50px]`}>
|
||||
<p className="text-right text-sm">
|
||||
{formatCurrency({
|
||||
value: montonioTotal < 0 ? 0 : montonioTotal,
|
||||
currencyCode: cart.currency_code,
|
||||
locale: language,
|
||||
})}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
<div className="flex flex-col gap-x-4 gap-y-6 py-4 sm:flex-row sm:py-8">
|
||||
{IS_DISCOUNT_SHOWN && (
|
||||
<Card className="flex w-full flex-col justify-between sm:w-1/2">
|
||||
<CardHeader className="pb-4">
|
||||
<h5>
|
||||
<Trans i18nKey="cart:discountCode.title" />
|
||||
</h5>
|
||||
</CardHeader>
|
||||
<CardContent className="h-full">
|
||||
<DiscountCode cart={{ ...cart }} />
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{isLocationsShown && (
|
||||
<Card className="flex w-full flex-col justify-between sm:w-1/2">
|
||||
<CardHeader className="pb-4">
|
||||
<h5>
|
||||
<Trans i18nKey="cart:locations.title" />
|
||||
</h5>
|
||||
</CardHeader>
|
||||
<CardContent className="h-full">
|
||||
<AnalysisLocation
|
||||
cart={{ ...cart }}
|
||||
synlabAnalyses={synlabAnalyses}
|
||||
/>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Button
|
||||
className="h-10"
|
||||
onClick={initiateSession}
|
||||
disabled={isInitiatingSession}
|
||||
>
|
||||
{isInitiatingSession && (
|
||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||
)}
|
||||
<Trans i18nKey="cart:checkout.goToCheckout" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
import React from 'react';
|
||||
|
||||
import { formatCurrency } from '@/packages/shared/src/utils';
|
||||
import { StoreCartLineItem } from '@medusajs/types';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { Table, TableBody } from '@kit/ui/shadcn/table';
|
||||
|
||||
import MobileTableRow from './mobile-table-row';
|
||||
|
||||
const MobileCartItems = ({
|
||||
item,
|
||||
currencyCode,
|
||||
productColumnLabelKey,
|
||||
}: {
|
||||
item: StoreCartLineItem;
|
||||
currencyCode: string;
|
||||
productColumnLabelKey: string;
|
||||
}) => {
|
||||
const {
|
||||
i18n: { language, t },
|
||||
} = useTranslation();
|
||||
|
||||
return (
|
||||
<Table className="border-separate rounded-lg border p-2">
|
||||
<TableBody>
|
||||
<MobileTableRow
|
||||
title={t(productColumnLabelKey)}
|
||||
value={item.product_title}
|
||||
/>
|
||||
<MobileTableRow title={t('cart:table.time')} value={item.quantity} />
|
||||
<MobileTableRow
|
||||
title={t('cart:table.price')}
|
||||
value={formatCurrency({
|
||||
value: item.unit_price,
|
||||
currencyCode,
|
||||
locale: language,
|
||||
})}
|
||||
/>
|
||||
<MobileTableRow
|
||||
title={t('cart:table.total')}
|
||||
value={
|
||||
item.total &&
|
||||
formatCurrency({
|
||||
value: item.total,
|
||||
currencyCode,
|
||||
locale: language,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</TableBody>
|
||||
</Table>
|
||||
);
|
||||
};
|
||||
|
||||
export default MobileCartItems;
|
||||
@@ -1,94 +0,0 @@
|
||||
import React from 'react';
|
||||
|
||||
import { formatCurrency, formatDateAndTime } from '@/packages/shared/src/utils';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { Trans } from '@kit/ui/makerkit/trans';
|
||||
import { Button } from '@kit/ui/shadcn/button';
|
||||
import { Table, TableBody, TableCell, TableRow } from '@kit/ui/shadcn/table';
|
||||
|
||||
import CartItemDelete from './cart-item-delete';
|
||||
import MobileTableRow from './mobile-table-row';
|
||||
import { EnrichedCartItem } from './types';
|
||||
|
||||
const MobileCartServiceItems = ({
|
||||
item,
|
||||
currencyCode,
|
||||
isUnavailable,
|
||||
productColumnLabelKey,
|
||||
setEditingItem,
|
||||
}: {
|
||||
item: EnrichedCartItem;
|
||||
currencyCode: string;
|
||||
isUnavailable?: boolean;
|
||||
productColumnLabelKey: string;
|
||||
setEditingItem: (item: EnrichedCartItem | null) => void;
|
||||
}) => {
|
||||
const {
|
||||
i18n: { language, t },
|
||||
} = useTranslation();
|
||||
|
||||
return (
|
||||
<Table className="border-separate rounded-lg border p-2">
|
||||
<TableBody>
|
||||
<MobileTableRow
|
||||
title={t(productColumnLabelKey)}
|
||||
value={item.product_title}
|
||||
/>
|
||||
<MobileTableRow
|
||||
title={t('cart:table.time')}
|
||||
value={formatDateAndTime(item.reservation.startTime.toString())}
|
||||
/>
|
||||
<MobileTableRow
|
||||
title={t('cart:table.location')}
|
||||
value={item.reservation.location?.address ?? '-'}
|
||||
/>
|
||||
<MobileTableRow
|
||||
title={t('cart:table.quantity')}
|
||||
value={item.quantity}
|
||||
/>
|
||||
<MobileTableRow
|
||||
title={t('cart:table.price')}
|
||||
value={formatCurrency({
|
||||
value: item.unit_price,
|
||||
currencyCode,
|
||||
locale: language,
|
||||
})}
|
||||
/>
|
||||
<MobileTableRow
|
||||
title={t('cart:table.total')}
|
||||
value={
|
||||
item.total &&
|
||||
formatCurrency({
|
||||
value: item.total,
|
||||
currencyCode,
|
||||
locale: language,
|
||||
})
|
||||
}
|
||||
/>
|
||||
<TableRow>
|
||||
<TableCell />
|
||||
<TableCell className="flex w-full items-center justify-end gap-4 p-0 pt-2">
|
||||
<CartItemDelete id={item.id} />
|
||||
<Button type="button" onClick={() => setEditingItem(item)}>
|
||||
<Trans i18nKey="common:change" />
|
||||
</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
|
||||
{isUnavailable && (
|
||||
<TableRow>
|
||||
<TableCell
|
||||
colSpan={8}
|
||||
className="text-destructive px-4 text-left sm:px-6"
|
||||
>
|
||||
<Trans i18nKey="booking:timeSlotUnavailable" />
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
);
|
||||
};
|
||||
|
||||
export default MobileCartServiceItems;
|
||||
@@ -1,21 +0,0 @@
|
||||
import React from 'react';
|
||||
|
||||
import { TableCell, TableHead, TableRow } from '@kit/ui/shadcn/table';
|
||||
|
||||
const MobleTableRow = ({
|
||||
title,
|
||||
value,
|
||||
}: {
|
||||
title?: string;
|
||||
value?: string | number;
|
||||
}) => (
|
||||
<TableRow>
|
||||
<TableHead className="h-2 font-bold">{title}</TableHead>
|
||||
|
||||
<TableCell className="p-0 text-right">
|
||||
<p className="txt-medium-plus text-ui-fg-base">{value}</p>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
|
||||
export default MobleTableRow;
|
||||
@@ -1,6 +1,5 @@
|
||||
import { StoreCartLineItem } from '@medusajs/types';
|
||||
|
||||
import { Reservation } from '~/lib/types/reservation';
|
||||
import { StoreCartLineItem } from "@medusajs/types";
|
||||
import { Reservation } from "~/lib/types/reservation";
|
||||
|
||||
export interface MontonioOrderToken {
|
||||
uuid: string;
|
||||
@@ -14,6 +13,12 @@ export interface MontonioOrderToken {
|
||||
| 'PENDING'
|
||||
| 'EXPIRED'
|
||||
| 'REFUNDED';
|
||||
| 'PAID'
|
||||
| 'FAILED'
|
||||
| 'CANCELLED'
|
||||
| 'PENDING'
|
||||
| 'EXPIRED'
|
||||
| 'REFUNDED';
|
||||
paymentMethod: string;
|
||||
grandTotal: number;
|
||||
currency: string;
|
||||
@@ -31,13 +36,3 @@ export enum CartItemType {
|
||||
}
|
||||
|
||||
export type EnrichedCartItem = StoreCartLineItem & { reservation: Reservation };
|
||||
|
||||
export type GetBalanceSummarySelection = ({
|
||||
useCompanyBenefits,
|
||||
}: {
|
||||
useCompanyBenefits: boolean;
|
||||
}) => {
|
||||
benefitsAmount: number;
|
||||
benefitsAmountTotal: number;
|
||||
montonioAmount: number;
|
||||
};
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import { Check } from 'lucide-react';
|
||||
|
||||
export const CheckWithBackground = () => {
|
||||
return (
|
||||
<div className="bg-primary w-min rounded-full p-1 text-white">
|
||||
<Check className="size-3 stroke-2" />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -1,115 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState } from 'react';
|
||||
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
import { AnalysisPackageWithVariant } from '@/packages/shared/src/components/select-analysis-package';
|
||||
import { pathsConfig } from '@/packages/shared/src/config';
|
||||
|
||||
import { Spinner } from '@kit/ui/makerkit/spinner';
|
||||
import { Trans } from '@kit/ui/makerkit/trans';
|
||||
import { Button } from '@kit/ui/shadcn/button';
|
||||
import { toast } from '@kit/ui/shadcn/sonner';
|
||||
import { Table, TableBody, TableCell, TableRow } from '@kit/ui/shadcn/table';
|
||||
|
||||
import { handleAddToCart } from '~/lib/services/medusaCart.service';
|
||||
import { cn } from '~/lib/utils';
|
||||
|
||||
const AddToCartButton = ({
|
||||
onClick,
|
||||
disabled,
|
||||
isLoading,
|
||||
}: {
|
||||
onClick: () => void;
|
||||
disabled: boolean;
|
||||
isLoading: boolean;
|
||||
}) => {
|
||||
return (
|
||||
<TableCell align="center" className="xs:px-2 px-1 py-6">
|
||||
<Button
|
||||
onClick={onClick}
|
||||
disabled={disabled}
|
||||
className="xs:p-6 xs:text-sm relative p-2 text-[10px]"
|
||||
>
|
||||
{isLoading && (
|
||||
<div className="absolute inset-0 flex items-center justify-center">
|
||||
<Spinner />
|
||||
</div>
|
||||
)}
|
||||
<div
|
||||
className={cn({
|
||||
invisible: isLoading,
|
||||
})}
|
||||
>
|
||||
<Trans i18nKey="compare-packages-modal:selectThisPackage" />
|
||||
</div>
|
||||
</Button>
|
||||
</TableCell>
|
||||
);
|
||||
};
|
||||
|
||||
const ComparePackagesAddToCartButtons = ({
|
||||
countryCode,
|
||||
standardPackage,
|
||||
standardPlusPackage,
|
||||
premiumPackage,
|
||||
}: {
|
||||
countryCode: string;
|
||||
standardPackage: AnalysisPackageWithVariant;
|
||||
standardPlusPackage: AnalysisPackageWithVariant;
|
||||
premiumPackage: AnalysisPackageWithVariant;
|
||||
}) => {
|
||||
const [addedPackage, setAddedPackage] = useState<string | null>(null);
|
||||
const router = useRouter();
|
||||
|
||||
const handleSelect = async ({ variantId }: AnalysisPackageWithVariant) => {
|
||||
setAddedPackage(variantId);
|
||||
try {
|
||||
await handleAddToCart({
|
||||
selectedVariant: { id: variantId },
|
||||
countryCode,
|
||||
});
|
||||
setAddedPackage(null);
|
||||
toast.success(
|
||||
<Trans i18nKey={'order-analysis-package:analysisPackageAddedToCart'} />,
|
||||
);
|
||||
router.push(pathsConfig.app.cart);
|
||||
} catch (e) {
|
||||
toast.error(
|
||||
<Trans
|
||||
i18nKey={'order-analysis-package:analysisPackageAddToCartError'}
|
||||
/>,
|
||||
);
|
||||
setAddedPackage(null);
|
||||
console.error(e);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Table>
|
||||
<TableBody>
|
||||
<TableRow>
|
||||
<TableCell className="w-[30vw] py-6" />
|
||||
<AddToCartButton
|
||||
onClick={() => handleSelect(standardPackage)}
|
||||
disabled={!!addedPackage}
|
||||
isLoading={addedPackage === standardPackage.variantId}
|
||||
/>
|
||||
<AddToCartButton
|
||||
onClick={() => handleSelect(standardPlusPackage)}
|
||||
disabled={!!addedPackage}
|
||||
isLoading={addedPackage === standardPlusPackage.variantId}
|
||||
/>
|
||||
<AddToCartButton
|
||||
onClick={() => handleSelect(premiumPackage)}
|
||||
disabled={!!addedPackage}
|
||||
isLoading={addedPackage === premiumPackage.variantId}
|
||||
/>
|
||||
</TableRow>
|
||||
</TableBody>
|
||||
</Table>
|
||||
);
|
||||
};
|
||||
|
||||
export default ComparePackagesAddToCartButtons;
|
||||
@@ -3,7 +3,7 @@ import { JSX } from 'react';
|
||||
import { StoreProduct } from '@medusajs/types';
|
||||
import { QuestionMarkCircledIcon } from '@radix-ui/react-icons';
|
||||
import { VisuallyHidden } from '@radix-ui/react-visually-hidden';
|
||||
import { X } from 'lucide-react';
|
||||
import { Check, X } from 'lucide-react';
|
||||
|
||||
import { PackageHeader } from '@kit/shared/components/package-header';
|
||||
import { AnalysisPackageWithVariant } from '@kit/shared/components/select-analysis-package';
|
||||
@@ -26,10 +26,6 @@ import {
|
||||
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||
|
||||
import { CheckWithBackground } from './check-with-background';
|
||||
import ComparePackagesAddToCartButtons from './compare-packages-add-to-cart-buttons';
|
||||
import DefaultPackageFeaturesRows from './default-package-features-rows';
|
||||
|
||||
export type AnalysisPackageElement = Pick<
|
||||
StoreProduct,
|
||||
'title' | 'id' | 'description'
|
||||
@@ -39,6 +35,14 @@ export type AnalysisPackageElement = Pick<
|
||||
isIncludedInPremium: boolean;
|
||||
};
|
||||
|
||||
const CheckWithBackground = () => {
|
||||
return (
|
||||
<div className="bg-primary w-min rounded-full p-1 text-white">
|
||||
<Check className="size-3 stroke-2" />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const PackageTableHead = async ({
|
||||
product,
|
||||
}: {
|
||||
@@ -49,7 +53,7 @@ const PackageTableHead = async ({
|
||||
const { title, price, nrOfAnalyses } = product;
|
||||
|
||||
return (
|
||||
<TableHead className="xs:content-normal content-start py-2">
|
||||
<TableHead className="py-2">
|
||||
<PackageHeader
|
||||
title={t(title)}
|
||||
tagColor="bg-cyan"
|
||||
@@ -65,12 +69,10 @@ const ComparePackagesModal = async ({
|
||||
analysisPackages,
|
||||
analysisPackageElements,
|
||||
triggerElement,
|
||||
countryCode,
|
||||
}: {
|
||||
analysisPackages: AnalysisPackageWithVariant[];
|
||||
analysisPackageElements: AnalysisPackageElement[];
|
||||
triggerElement: JSX.Element;
|
||||
countryCode: string;
|
||||
}) => {
|
||||
const { t } = await createI18nServerInstance();
|
||||
|
||||
@@ -90,7 +92,7 @@ const ComparePackagesModal = async ({
|
||||
<DialogContent
|
||||
className="min-h-screen max-w-fit min-w-screen"
|
||||
customClose={
|
||||
<div className="absolute top-6 right-0 flex place-items-center-safe sm:top-0">
|
||||
<div className="inline-flex place-items-center-safe gap-1 align-middle">
|
||||
<p className="text-sm font-medium text-black">
|
||||
{t('common:close')}
|
||||
</p>
|
||||
@@ -104,13 +106,11 @@ const ComparePackagesModal = async ({
|
||||
</VisuallyHidden>
|
||||
<div className="m-auto">
|
||||
<div className="space-y-6 text-center">
|
||||
<h3 className="sm:text-xxl text-lg">
|
||||
{t('product:healthPackageComparison.label')}
|
||||
</h3>
|
||||
<p className="text-muted-foreground text-sm sm:mx-auto sm:w-3/5">
|
||||
<h3>{t('product:healthPackageComparison.label')}</h3>
|
||||
<p className="text-muted-foreground mx-auto w-3/5 text-sm">
|
||||
{t('product:healthPackageComparison.description')}
|
||||
</p>
|
||||
<div className="max-h-[50vh] overflow-y-auto rounded-md border sm:max-h-[70vh]">
|
||||
<div className="max-h-[80vh] overflow-y-auto rounded-md border">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
@@ -121,8 +121,6 @@ const ComparePackagesModal = async ({
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
<DefaultPackageFeaturesRows />
|
||||
|
||||
{analysisPackageElements.map(
|
||||
({
|
||||
title,
|
||||
@@ -138,14 +136,12 @@ const ComparePackagesModal = async ({
|
||||
|
||||
return (
|
||||
<TableRow key={id}>
|
||||
<TableCell className="relative py-6 sm:w-[30vw]">
|
||||
<TableCell className="py-6 sm:max-w-[30vw]">
|
||||
{title}{' '}
|
||||
{description && (
|
||||
<InfoTooltip
|
||||
content={description}
|
||||
icon={
|
||||
<QuestionMarkCircledIcon className="absolute top-2 right-0 size-5 sm:static sm:ml-2 sm:size-4" />
|
||||
}
|
||||
icon={<QuestionMarkCircledIcon />}
|
||||
/>
|
||||
)}
|
||||
</TableCell>
|
||||
@@ -168,12 +164,6 @@ const ComparePackagesModal = async ({
|
||||
</Table>
|
||||
</div>
|
||||
</div>
|
||||
<ComparePackagesAddToCartButtons
|
||||
countryCode={countryCode}
|
||||
standardPackage={standardPackage}
|
||||
premiumPackage={premiumPackage}
|
||||
standardPlusPackage={standardPlusPackage}
|
||||
/>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import Link from 'next/link';
|
||||
|
||||
import { createI18nServerInstance } from '@/lib/i18n/i18n.server';
|
||||
import { formatCurrency } from '@/packages/shared/src/utils';
|
||||
import { ChevronRight, HeartPulse } from 'lucide-react';
|
||||
|
||||
import { Button } from '@kit/ui/button';
|
||||
@@ -13,27 +11,25 @@ import {
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from '@kit/ui/card';
|
||||
import { cn } from '@kit/ui/lib/utils';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
import { getAccountBalanceSummary } from '../_lib/server/balance-actions';
|
||||
import { formatCurrency } from '@/packages/shared/src/utils';
|
||||
import { createI18nServerInstance } from '@/lib/i18n/i18n.server';
|
||||
import { cn } from '@kit/ui/lib/utils';
|
||||
import { loadCurrentUserAccount } from '../_lib/server/load-user-account';
|
||||
import { getAccountBalanceSummary } from '../_lib/server/balance-actions';
|
||||
|
||||
export default async function DashboardCards() {
|
||||
const { language } = await createI18nServerInstance();
|
||||
|
||||
|
||||
const { account } = await loadCurrentUserAccount();
|
||||
const balanceSummary = account
|
||||
? await getAccountBalanceSummary(account.id)
|
||||
: null;
|
||||
const balanceSummary = account ? await getAccountBalanceSummary(account.id) : null;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
'grid grid-cols-1 gap-4',
|
||||
'md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
|
||||
)}
|
||||
>
|
||||
)}>
|
||||
<Card
|
||||
variant="gradient-success"
|
||||
className="xs:w-1/2 flex w-full flex-col justify-between sm:w-auto"
|
||||
@@ -83,7 +79,7 @@ export default async function DashboardCards() {
|
||||
<Trans
|
||||
i18nKey="dashboard:heroCard.benefits.validUntil"
|
||||
values={{ date: '31.12.2025' }}
|
||||
/>
|
||||
/>
|
||||
</CardDescription>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
@@ -14,10 +14,7 @@ import {
|
||||
User,
|
||||
} from 'lucide-react';
|
||||
|
||||
import type {
|
||||
AccountWithParams,
|
||||
BmiThresholds,
|
||||
} from '@kit/accounts/types/accounts';
|
||||
import type { AccountWithParams, BmiThresholds } from '@kit/accounts/types/accounts';
|
||||
import { pathsConfig } from '@kit/shared/config';
|
||||
import { Button } from '@kit/ui/button';
|
||||
import {
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import { InfoTooltip } from '@/packages/shared/src/components/ui/info-tooltip';
|
||||
import { QuestionMarkCircledIcon } from '@radix-ui/react-icons';
|
||||
|
||||
import { Trans } from '@kit/ui/makerkit/trans';
|
||||
import { TableCell, TableRow } from '@kit/ui/shadcn/table';
|
||||
|
||||
import { CheckWithBackground } from './check-with-background';
|
||||
|
||||
const DefaultPackageFeaturesRows = () => {
|
||||
return (
|
||||
<>
|
||||
<TableRow key="digital-doctor-feedback">
|
||||
<TableCell className="relative max-w-[30vw] py-6">
|
||||
<Trans i18nKey="order-analysis-package:digitalDoctorFeedback" />
|
||||
<InfoTooltip
|
||||
content={
|
||||
<Trans i18nKey="order-analysis-package:digitalDoctorFeedbackInfo" />
|
||||
}
|
||||
icon={
|
||||
<QuestionMarkCircledIcon className="absolute top-2 right-0 size-5 sm:static sm:ml-2 sm:size-4" />
|
||||
}
|
||||
/>
|
||||
</TableCell>
|
||||
<TableCell align="center" className="py-6">
|
||||
<CheckWithBackground />
|
||||
</TableCell>
|
||||
<TableCell align="center" className="py-6">
|
||||
<CheckWithBackground />
|
||||
</TableCell>
|
||||
<TableCell align="center" className="py-6">
|
||||
<CheckWithBackground />
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
|
||||
<TableRow key="give-analyses">
|
||||
<TableCell className="py-6 sm:max-w-[30vw]">
|
||||
<Trans i18nKey="order-analysis-package:giveAnalyses" />
|
||||
</TableCell>
|
||||
<TableCell align="center" className="py-6">
|
||||
<CheckWithBackground />
|
||||
</TableCell>
|
||||
<TableCell align="center" className="py-6">
|
||||
<CheckWithBackground />
|
||||
</TableCell>
|
||||
<TableCell align="center" className="py-6">
|
||||
<CheckWithBackground />
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default DefaultPackageFeaturesRows;
|
||||
@@ -9,12 +9,12 @@ import { ShoppingCart } from 'lucide-react';
|
||||
|
||||
import { AppLogo } from '@kit/shared/components/app-logo';
|
||||
import { ProfileAccountDropdownContainer } from '@kit/shared/components/personal-account-dropdown-container';
|
||||
import { Search } from '@kit/shared/components/ui/search';
|
||||
import { Button } from '@kit/ui/button';
|
||||
import { Card } from '@kit/ui/shadcn/card';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
import { UserNotifications } from '../_components/user-notifications';
|
||||
import { getAccountBalanceSummary } from '../_lib/server/balance-actions';
|
||||
import { type UserWorkspace } from '../_lib/server/load-user-workspace';
|
||||
|
||||
export async function HomeMenuNavigation(props: {
|
||||
@@ -23,9 +23,13 @@ export async function HomeMenuNavigation(props: {
|
||||
}) {
|
||||
const { language } = await createI18nServerInstance();
|
||||
const { workspace, user, accounts } = props.workspace;
|
||||
const balanceSummary = workspace?.id
|
||||
? await getAccountBalanceSummary(workspace.id)
|
||||
: null;
|
||||
const totalValue = props.cart?.total
|
||||
? formatCurrency({
|
||||
currencyCode: props.cart.currency_code,
|
||||
locale: language,
|
||||
value: props.cart.total,
|
||||
})
|
||||
: 0;
|
||||
|
||||
const cartQuantityTotal =
|
||||
props.cart?.items?.reduce((acc, item) => acc + item.quantity, 0) ?? 0;
|
||||
@@ -43,32 +47,29 @@ export async function HomeMenuNavigation(props: {
|
||||
/> */}
|
||||
|
||||
<div className="flex items-center justify-end gap-3">
|
||||
{/* TODO: add wallet functionality
|
||||
<Card className="px-6 py-2">
|
||||
<span>
|
||||
{formatCurrency({
|
||||
value: balanceSummary?.totalBalance || 0,
|
||||
locale: language,
|
||||
currencyCode: 'EUR',
|
||||
})}
|
||||
</span>
|
||||
<span>€ {Number(0).toFixed(2).replace('.', ',')}</span>
|
||||
</Card>
|
||||
|
||||
*/}
|
||||
{hasCartItems && (
|
||||
<Button
|
||||
className="relative mr-0 h-10 cursor-pointer border-1 px-4 py-2"
|
||||
variant="ghost"
|
||||
>
|
||||
<span className="flex items-center text-nowrap">{totalValue}</span>
|
||||
</Button>
|
||||
)}
|
||||
<Link href={pathsConfig.app.cart}>
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="relative mr-0 h-10 cursor-pointer border-1 px-4 py-2"
|
||||
>
|
||||
<ShoppingCart className="stroke-[1.5px]" />
|
||||
<Trans i18nKey="common:shoppingCart" />{' '}
|
||||
{hasCartItems && (
|
||||
<>
|
||||
(
|
||||
<span className="text-success font-bold">
|
||||
{cartQuantityTotal}
|
||||
</span>
|
||||
)
|
||||
</>
|
||||
)}
|
||||
<Trans
|
||||
i18nKey="common:shoppingCartCount"
|
||||
values={{ count: cartQuantityTotal }}
|
||||
/>
|
||||
</Button>
|
||||
</Link>
|
||||
<UserNotifications userId={user.id} />
|
||||
|
||||
@@ -25,22 +25,16 @@ import {
|
||||
DropdownMenuTrigger,
|
||||
} from '@kit/ui/dropdown-menu';
|
||||
import { If } from '@kit/ui/if';
|
||||
import { cn } from '@kit/ui/shadcn';
|
||||
import { Avatar, AvatarFallback, AvatarImage } from '@kit/ui/shadcn/avatar';
|
||||
import { Button } from '@kit/ui/shadcn/button';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
// home imports
|
||||
import type { UserWorkspace } from '../_lib/server/load-user-workspace';
|
||||
import { UserNotifications } from './user-notifications';
|
||||
|
||||
const PERSONAL_ACCOUNT_SLUG = 'personal';
|
||||
|
||||
export function HomeMobileNavigation(props: {
|
||||
workspace: UserWorkspace;
|
||||
cart: StoreCart | null;
|
||||
}) {
|
||||
const { user, accounts } = props.workspace;
|
||||
const user = props.workspace.user;
|
||||
|
||||
const signOut = useSignOut();
|
||||
const { data: personalAccountData } = usePersonalAccountData(user.id);
|
||||
@@ -82,8 +76,8 @@ export function HomeMobileNavigation(props: {
|
||||
const hasDoctorRole =
|
||||
personalAccountData?.application_role === ApplicationRoleEnum.Doctor;
|
||||
|
||||
return hasDoctorRole;
|
||||
}, [personalAccountData]);
|
||||
return hasDoctorRole && hasTotpFactor;
|
||||
}, [user, personalAccountData, hasTotpFactor]);
|
||||
|
||||
const cartQuantityTotal =
|
||||
props.cart?.items?.reduce((acc, item) => acc + item.quantity, 0) ?? 0;
|
||||
@@ -91,31 +85,10 @@ export function HomeMobileNavigation(props: {
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<div className="flex justify-between gap-3">
|
||||
<Link href={pathsConfig.app.cart}>
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="relative mr-0 h-10 cursor-pointer border-1 px-4 py-2"
|
||||
>
|
||||
<ShoppingCart className="stroke-[1.5px]" />
|
||||
{hasCartItems && (
|
||||
<>
|
||||
(
|
||||
<span className="text-success font-bold">
|
||||
{cartQuantityTotal}
|
||||
</span>
|
||||
)
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
</Link>
|
||||
<DropdownMenuTrigger>
|
||||
<Menu className={'h-9'} />
|
||||
</DropdownMenuTrigger>
|
||||
|
||||
<UserNotifications userId={user.id} />
|
||||
|
||||
<DropdownMenuTrigger>
|
||||
<Menu className="h-6 w-6" />
|
||||
</DropdownMenuTrigger>
|
||||
</div>
|
||||
<DropdownMenuContent sideOffset={10} className={'w-screen rounded-none'}>
|
||||
<If condition={props.cart && hasCartItems}>
|
||||
<DropdownMenuGroup>
|
||||
@@ -175,46 +148,6 @@ export function HomeMobileNavigation(props: {
|
||||
</If>
|
||||
<DropdownMenuSeparator />
|
||||
|
||||
<If condition={accounts.length > 0}>
|
||||
<span className="text-muted-foreground px-2 text-xs">
|
||||
<Trans
|
||||
i18nKey={'teams:yourTeams'}
|
||||
values={{ teamsCount: accounts.length }}
|
||||
/>
|
||||
</span>
|
||||
|
||||
{accounts.map((account) => (
|
||||
<DropdownMenuItem key={account.value} asChild>
|
||||
<Link
|
||||
className={'s-full flex cursor-pointer items-center space-x-2'}
|
||||
href={`${pathsConfig.app.home}/${account.value}`}
|
||||
>
|
||||
<div className={'flex items-center'}>
|
||||
<Avatar className={'h-5 w-5 rounded-xs ' + account.image}>
|
||||
<AvatarImage
|
||||
{...(account.image && { src: account.image })}
|
||||
/>
|
||||
|
||||
<AvatarFallback
|
||||
className={cn('rounded-md', {
|
||||
['bg-background']:
|
||||
PERSONAL_ACCOUNT_SLUG === account.value,
|
||||
['group-hover:bg-background']:
|
||||
PERSONAL_ACCOUNT_SLUG !== account.value,
|
||||
})}
|
||||
>
|
||||
{account.label ? account.label[0] : ''}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
|
||||
<span className={'pl-3'}>{account.label}</span>
|
||||
</div>
|
||||
</Link>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
<DropdownMenuSeparator />
|
||||
</If>
|
||||
|
||||
<SignOutDropdownItem onSignOut={() => signOut.mutateAsync()} />
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
@@ -57,64 +57,72 @@ export default function OrderAnalysesCards({
|
||||
}
|
||||
};
|
||||
|
||||
return analyses.map(({ title, variant, description, subtitle, price }) => {
|
||||
const formattedPrice =
|
||||
typeof price === 'number'
|
||||
? formatCurrency({
|
||||
currencyCode: 'eur',
|
||||
locale: language,
|
||||
value: price,
|
||||
})
|
||||
: null;
|
||||
return (
|
||||
<Card
|
||||
key={title}
|
||||
variant="gradient-success"
|
||||
className="flex flex-col justify-between"
|
||||
>
|
||||
<CardHeader className="flex-row">
|
||||
<div className="bg-primary/10 mb-6 flex size-8 items-center-safe justify-center-safe rounded-full text-white">
|
||||
<HeartPulse className="size-4 fill-green-500" />
|
||||
</div>
|
||||
<div className="bg-warning ml-auto flex size-8 items-center-safe justify-center-safe rounded-full text-white">
|
||||
<Button
|
||||
size="icon"
|
||||
variant="outline"
|
||||
className="px-2 text-black"
|
||||
onClick={() => handleSelect(variant.id)}
|
||||
>
|
||||
{variantAddingToCart === variant.id ? (
|
||||
<Loader2 className="size-4 animate-spin stroke-2" />
|
||||
) : (
|
||||
<ShoppingCart className="size-4 stroke-2" />
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardFooter className="flex gap-2">
|
||||
<div className="flex flex-1 flex-col items-start gap-2">
|
||||
<h5>
|
||||
{title}
|
||||
{description && (
|
||||
<>
|
||||
<InfoTooltip
|
||||
content={
|
||||
<div className="flex flex-col gap-2">
|
||||
<span>{formattedPrice}</span>
|
||||
<span>{description}</span>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</h5>
|
||||
{subtitle && <CardDescription>{subtitle}</CardDescription>}
|
||||
</div>
|
||||
<div className="flex flex-col items-end gap-2 self-end text-sm">
|
||||
<span>{formattedPrice}</span>
|
||||
</div>
|
||||
</CardFooter>
|
||||
</Card>
|
||||
);
|
||||
});
|
||||
return (
|
||||
<div className="xs:grid-cols-3 mt-4 grid gap-6">
|
||||
{analyses.map(({ title, variant, description, subtitle, price }) => {
|
||||
const formattedPrice =
|
||||
typeof price === 'number'
|
||||
? formatCurrency({
|
||||
currencyCode: 'eur',
|
||||
locale: language,
|
||||
value: price,
|
||||
})
|
||||
: null;
|
||||
return (
|
||||
<Card
|
||||
key={title}
|
||||
variant="gradient-success"
|
||||
className="flex flex-col justify-between"
|
||||
>
|
||||
<CardHeader className="flex-row">
|
||||
<div
|
||||
className={
|
||||
'bg-primary/10 mb-6 flex size-8 items-center-safe justify-center-safe rounded-full text-white'
|
||||
}
|
||||
>
|
||||
<HeartPulse className="size-4 fill-green-500" />
|
||||
</div>
|
||||
<div className="bg-warning ml-auto flex size-8 items-center-safe justify-center-safe rounded-full text-white">
|
||||
<Button
|
||||
size="icon"
|
||||
variant="outline"
|
||||
className="px-2 text-black"
|
||||
onClick={() => handleSelect(variant.id)}
|
||||
>
|
||||
{variantAddingToCart === variant.id ? (
|
||||
<Loader2 className="size-4 animate-spin stroke-2" />
|
||||
) : (
|
||||
<ShoppingCart className="size-4 stroke-2" />
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardFooter className="flex gap-2">
|
||||
<div className="flex flex-1 flex-col items-start gap-2">
|
||||
<h5>
|
||||
{title}
|
||||
{description && (
|
||||
<>
|
||||
<InfoTooltip
|
||||
content={
|
||||
<div className="flex flex-col gap-2">
|
||||
<span>{formattedPrice}</span>
|
||||
<span>{description}</span>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</h5>
|
||||
{subtitle && <CardDescription>{subtitle}</CardDescription>}
|
||||
</div>
|
||||
<div className="flex flex-col items-end gap-2 self-end text-sm">
|
||||
<span>{formattedPrice}</span>
|
||||
</div>
|
||||
</CardFooter>
|
||||
</Card>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import Link from 'next/link';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { pathsConfig } from '@/packages/shared/src/config';
|
||||
import { ComponentInstanceIcon } from '@radix-ui/react-icons';
|
||||
import { ChevronRight } from 'lucide-react';
|
||||
import { ChevronRight, HeartPulse } from 'lucide-react';
|
||||
|
||||
import { Button } from '@kit/ui/button';
|
||||
import {
|
||||
|
||||
@@ -9,8 +9,8 @@ import { useTranslation } from 'react-i18next';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
const PaymentProviderIds = {
|
||||
COMPANY_BENEFITS: 'pp_company-benefits_company-benefits',
|
||||
MONTONIO: 'pp_montonio_montonio',
|
||||
COMPANY_BENEFITS: "pp_company-benefits_company-benefits",
|
||||
MONTONIO: "pp_montonio_montonio",
|
||||
};
|
||||
|
||||
export default function CartTotals({
|
||||
@@ -30,12 +30,10 @@ export default function CartTotals({
|
||||
payment_collections,
|
||||
} = medusaOrder;
|
||||
|
||||
const montonioPayment = payment_collections?.[0]?.payments?.find(
|
||||
({ provider_id }) => provider_id === PaymentProviderIds.MONTONIO,
|
||||
);
|
||||
const companyBenefitsPayment = payment_collections?.[0]?.payments?.find(
|
||||
({ provider_id }) => provider_id === PaymentProviderIds.COMPANY_BENEFITS,
|
||||
);
|
||||
const montonioPayment = payment_collections?.[0]?.payments
|
||||
?.find(({ provider_id }) => provider_id === PaymentProviderIds.MONTONIO);
|
||||
const companyBenefitsPayment = payment_collections?.[0]?.payments
|
||||
?.find(({ provider_id }) => provider_id === PaymentProviderIds.COMPANY_BENEFITS);
|
||||
|
||||
return (
|
||||
<div>
|
||||
@@ -98,6 +96,7 @@ export default function CartTotals({
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
</div>
|
||||
|
||||
<div className="my-4 h-px w-full border-b border-gray-200" />
|
||||
@@ -127,10 +126,7 @@ export default function CartTotals({
|
||||
<span className="flex items-center gap-x-1">
|
||||
<Trans i18nKey="cart:order.benefitsTotal" />
|
||||
</span>
|
||||
<span
|
||||
data-testid="cart-subtotal"
|
||||
data-value={companyBenefitsPayment.amount || 0}
|
||||
>
|
||||
<span data-testid="cart-subtotal" data-value={companyBenefitsPayment.amount || 0}>
|
||||
-{' '}
|
||||
{formatCurrency({
|
||||
value: companyBenefitsPayment.amount ?? 0,
|
||||
@@ -146,10 +142,7 @@ export default function CartTotals({
|
||||
<span className="flex items-center gap-x-1">
|
||||
<Trans i18nKey="cart:order.montonioTotal" />
|
||||
</span>
|
||||
<span
|
||||
data-testid="cart-subtotal"
|
||||
data-value={montonioPayment.amount || 0}
|
||||
>
|
||||
<span data-testid="cart-subtotal" data-value={montonioPayment.amount || 0}>
|
||||
-{' '}
|
||||
{formatCurrency({
|
||||
value: montonioPayment.amount ?? 0,
|
||||
|
||||
@@ -1,63 +1,27 @@
|
||||
import { formatDate } from 'date-fns';
|
||||
|
||||
import { Database } from '@kit/supabase/database';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
export default function OrderDetails({
|
||||
order,
|
||||
}: {
|
||||
order: {
|
||||
id: string;
|
||||
created_at: string | Date;
|
||||
location: Pick<
|
||||
Database['medreport']['Tables']['connected_online_locations']['Row'],
|
||||
'name' | 'address'
|
||||
> | null;
|
||||
serviceProvider: Pick<
|
||||
Database['medreport']['Tables']['connected_online_providers']['Row'],
|
||||
'email' | 'phone_number' | 'name'
|
||||
> | null;
|
||||
};
|
||||
order: { id: string; created_at: string | Date };
|
||||
}) {
|
||||
const { id, created_at, location, serviceProvider } = order;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-y-2">
|
||||
<div>
|
||||
<span className="font-bold">
|
||||
<Trans i18nKey="cart:orderConfirmed.orderNumber" />:{' '}
|
||||
</span>
|
||||
<span className="break-all">{id}</span>
|
||||
<span className="break-all">{order.id}</span>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span className="font-bold">
|
||||
<Trans i18nKey="cart:orderConfirmed.orderDate" />:{' '}
|
||||
</span>
|
||||
<span>{formatDate(created_at, 'dd.MM.yyyy HH:mm')}</span>
|
||||
<span>{formatDate(order.created_at, 'dd.MM.yyyy HH:mm')}</span>
|
||||
</div>
|
||||
{(location?.name || location?.address) && (
|
||||
<div>
|
||||
<span className="font-bold">
|
||||
<Trans i18nKey="cart:orderConfirmed.location" />:{' '}
|
||||
</span>
|
||||
<span>
|
||||
{location.name || location.address}{' '}
|
||||
{location?.name ? location.address : ''}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{serviceProvider && (
|
||||
<div className="flex flex-col">
|
||||
<span className="font-bold">
|
||||
<Trans i18nKey="cart:orderConfirmed.serviceProvider" />:{' '}
|
||||
</span>
|
||||
<span>{serviceProvider.name}</span>
|
||||
<span>{serviceProvider.phone_number}</span>
|
||||
<span>{serviceProvider.email}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,22 +5,20 @@ import { Eye } from 'lucide-react';
|
||||
|
||||
import { Trans } from '@kit/ui/makerkit/trans';
|
||||
|
||||
import type { AnalysisOrder, TTOOrder } from '~/lib/types/order';
|
||||
import type { AnalysisOrder } from '~/lib/types/order';
|
||||
|
||||
import OrderItemsTable from './order-items-table';
|
||||
|
||||
export default function OrderBlock({
|
||||
analysisOrder,
|
||||
ttoLocation,
|
||||
ttoReservation,
|
||||
medusaOrderStatus,
|
||||
itemsAnalysisPackage,
|
||||
itemsTtoService,
|
||||
itemsOther,
|
||||
medusaOrderId,
|
||||
}: {
|
||||
analysisOrder?: AnalysisOrder;
|
||||
ttoLocation?: { name: string };
|
||||
ttoReservation?: TTOOrder;
|
||||
medusaOrderStatus: string;
|
||||
itemsAnalysisPackage: StoreOrderLineItem[];
|
||||
itemsTtoService: StoreOrderLineItem[];
|
||||
itemsOther: StoreOrderLineItem[];
|
||||
@@ -40,7 +38,7 @@ export default function OrderBlock({
|
||||
<Trans i18nKey={`orders:status.${analysisOrder.status}`} />
|
||||
</h5>
|
||||
<Link
|
||||
href={`/home/order/${medusaOrderId}`}
|
||||
href={`/home/order/${analysisOrder.id}`}
|
||||
className="text-small-regular flex items-center justify-between"
|
||||
>
|
||||
<button className="text-ui-fg-subtle hover:text-ui-fg-base flex cursor-pointer gap-x-1">
|
||||
@@ -49,7 +47,7 @@ export default function OrderBlock({
|
||||
</Link>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex flex-col sm:gap-4">
|
||||
<div className="flex flex-col gap-4">
|
||||
{analysisOrder && (
|
||||
<OrderItemsTable
|
||||
items={itemsAnalysisPackage}
|
||||
@@ -59,7 +57,6 @@ export default function OrderBlock({
|
||||
id: analysisOrder.id,
|
||||
status: analysisOrder.status,
|
||||
}}
|
||||
isPackage
|
||||
/>
|
||||
)}
|
||||
{itemsTtoService && (
|
||||
@@ -68,12 +65,8 @@ export default function OrderBlock({
|
||||
title="orders:table.ttoService"
|
||||
type="ttoService"
|
||||
order={{
|
||||
status: ttoReservation?.status,
|
||||
status: medusaOrderStatus.toUpperCase(),
|
||||
medusaOrderId,
|
||||
location: ttoLocation?.name,
|
||||
bookingCode: ttoReservation?.booking_code,
|
||||
clinicId: ttoReservation?.clinic_id,
|
||||
medusaLineItemId: ttoReservation?.medusa_cart_line_item_id,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
@@ -81,8 +74,6 @@ export default function OrderBlock({
|
||||
items={itemsOther}
|
||||
title="orders:table.otherOrders"
|
||||
order={{
|
||||
medusaOrderId: analysisOrder?.medusa_order_id,
|
||||
id: analysisOrder?.id,
|
||||
status: analysisOrder?.status,
|
||||
}}
|
||||
/>
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
import { redirect, useRouter } from 'next/navigation';
|
||||
|
||||
import ConfirmationModal from '@/packages/shared/src/components/confirmation-modal';
|
||||
import { StoreOrderLineItem } from '@medusajs/types';
|
||||
import { formatDate } from 'date-fns';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { pathsConfig } from '@kit/shared/config';
|
||||
import { Button } from '@kit/ui/button';
|
||||
@@ -23,8 +19,6 @@ import { Trans } from '@kit/ui/trans';
|
||||
|
||||
import type { Order } from '~/lib/types/order';
|
||||
|
||||
import { cancelTtoBooking } from '../../_lib/server/actions';
|
||||
import MobileTableRow from '../cart/mobile-table-row';
|
||||
import { logAnalysisResultsNavigateAction } from './actions';
|
||||
|
||||
export type OrderItemType = 'analysisOrder' | 'ttoService';
|
||||
@@ -34,31 +28,19 @@ export default function OrderItemsTable({
|
||||
title,
|
||||
order,
|
||||
type = 'analysisOrder',
|
||||
isPackage = false,
|
||||
}: {
|
||||
items: StoreOrderLineItem[];
|
||||
title: string;
|
||||
order: Order;
|
||||
type?: OrderItemType;
|
||||
isPackage?: boolean;
|
||||
}) {
|
||||
const {
|
||||
i18n: { t },
|
||||
} = useTranslation();
|
||||
const router = useRouter();
|
||||
const [isConfirmOpen, setIsConfirmOpen] = useState(false);
|
||||
const isCancelOrderAllowed =
|
||||
order?.bookingCode &&
|
||||
order?.clinicId &&
|
||||
order?.medusaLineItemId &&
|
||||
order?.status === 'CONFIRMED';
|
||||
|
||||
if (!items || items.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const isAnalysisOrder = type === 'analysisOrder';
|
||||
const isTtoservice = type === 'ttoService';
|
||||
|
||||
const openDetailedView = async () => {
|
||||
if (isAnalysisOrder && order?.medusaOrderId && order?.id) {
|
||||
@@ -70,159 +52,52 @@ export default function OrderItemsTable({
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Table className="border-separate rounded-lg border p-2 sm:hidden">
|
||||
<TableBody>
|
||||
{items
|
||||
.sort((a, b) =>
|
||||
(a.created_at ?? '') > (b.created_at ?? '') ? -1 : 1,
|
||||
)
|
||||
.map((orderItem) => (
|
||||
<React.Fragment key={`${orderItem.id}-mobile`}>
|
||||
<MobileTableRow
|
||||
title={t(title)}
|
||||
value={orderItem.product_title || ''}
|
||||
/>
|
||||
<MobileTableRow
|
||||
title={t('orders:table.createdAt')}
|
||||
value={formatDate(orderItem.created_at, 'dd.MM.yyyy HH:mm')}
|
||||
/>
|
||||
{order.location && (
|
||||
<MobileTableRow
|
||||
title={t('orders:table.location')}
|
||||
value={order.location}
|
||||
/>
|
||||
)}
|
||||
<MobileTableRow
|
||||
title={t('orders:table.status')}
|
||||
value={
|
||||
isPackage
|
||||
? t(
|
||||
`orders:status.analysisPackageOrder.${order?.status ?? 'CONFIRMED'}`,
|
||||
)
|
||||
: t(
|
||||
`orders:status.${type}.${order?.status ?? 'CONFIRMED'}`,
|
||||
)
|
||||
}
|
||||
/>
|
||||
<TableRow>
|
||||
<TableCell />
|
||||
<TableCell className="flex w-full items-center justify-end gap-2 p-0 pt-2">
|
||||
<Button size="sm" onClick={openDetailedView}>
|
||||
<Trans
|
||||
i18nKey={
|
||||
isTtoservice ? 'orders:view' : 'analysis-results:view'
|
||||
}
|
||||
/>
|
||||
</Button>
|
||||
{isTtoservice && order.bookingCode && (
|
||||
<Button
|
||||
size="sm"
|
||||
className="bg-warning/90 hover:bg-warning"
|
||||
onClick={() => setIsConfirmOpen(true)}
|
||||
>
|
||||
<Trans i18nKey="analysis-results:cancel" />
|
||||
</Button>
|
||||
)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
</React.Fragment>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
<Table className="border-separate rounded-lg border">
|
||||
<TableHeader className="text-ui-fg-subtle txt-medium-plus">
|
||||
<TableRow>
|
||||
<TableHead className="px-6">
|
||||
<Trans i18nKey={title} />
|
||||
</TableHead>
|
||||
<TableHead className="px-6">
|
||||
<Trans i18nKey="orders:table.createdAt" />
|
||||
</TableHead>
|
||||
<TableHead className="px-6">
|
||||
<Trans i18nKey="orders:table.status" />
|
||||
</TableHead>
|
||||
{isAnalysisOrder && <TableHead className="px-6"></TableHead>}
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{items
|
||||
.sort((a, b) =>
|
||||
(a.created_at ?? '') > (b.created_at ?? '') ? -1 : 1,
|
||||
)
|
||||
.map((orderItem) => (
|
||||
<TableRow className="w-full" key={orderItem.id}>
|
||||
<TableCell className="w-[100%] px-6 text-left">
|
||||
<p className="txt-medium-plus text-ui-fg-base">
|
||||
{orderItem.product_title}
|
||||
</p>
|
||||
</TableCell>
|
||||
|
||||
<Table className="hidden border-separate rounded-lg border sm:block">
|
||||
<TableHeader className="text-ui-fg-subtle txt-medium-plus">
|
||||
<TableRow>
|
||||
<TableHead className="px-6">
|
||||
<Trans i18nKey={title} />
|
||||
</TableHead>
|
||||
<TableHead className="px-6">
|
||||
<Trans i18nKey="orders:table.createdAt" />
|
||||
</TableHead>
|
||||
{order.location && (
|
||||
<TableHead className="px-6">
|
||||
<Trans i18nKey="orders:table.location" />
|
||||
</TableHead>
|
||||
)}
|
||||
<TableHead className="px-6">
|
||||
<Trans i18nKey="orders:table.status" />
|
||||
</TableHead>
|
||||
{isAnalysisOrder && <TableHead className="px-6"></TableHead>}
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{items
|
||||
.sort((a, b) =>
|
||||
(a.created_at ?? '') > (b.created_at ?? '') ? -1 : 1,
|
||||
)
|
||||
.map((orderItem) => (
|
||||
<TableRow className="w-full" key={orderItem.id}>
|
||||
<TableCell className="w-[100%] px-6 text-left">
|
||||
<p className="txt-medium-plus text-ui-fg-base">
|
||||
{orderItem.product_title}
|
||||
</p>
|
||||
</TableCell>
|
||||
<TableCell className="px-6 whitespace-nowrap">
|
||||
{formatDate(orderItem.created_at, 'dd.MM.yyyy HH:mm')}
|
||||
</TableCell>
|
||||
|
||||
<TableCell className="px-6 whitespace-nowrap">
|
||||
{formatDate(orderItem.created_at, 'dd.MM.yyyy HH:mm')}
|
||||
</TableCell>
|
||||
{order.location && (
|
||||
<TableCell className="min-w-[180px] px-6">
|
||||
{order.location}
|
||||
</TableCell>
|
||||
)}
|
||||
<TableCell className="min-w-[180px] px-6">
|
||||
{isPackage ? (
|
||||
<Trans
|
||||
i18nKey={`orders:status.analysisPackageOrder.${order?.status ?? 'CONFIRMED'}`}
|
||||
/>
|
||||
) : (
|
||||
<Trans
|
||||
i18nKey={`orders:status.${type}.${order?.status ?? 'CONFIRMED'}`}
|
||||
/>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell className="min-w-[180px] px-6">
|
||||
<Trans
|
||||
i18nKey={`orders:status.${type}.${order?.status ?? 'CONFIRMED'}`}
|
||||
/>
|
||||
</TableCell>
|
||||
|
||||
<TableCell className="px-6 text-right">
|
||||
<Button size="sm" onClick={openDetailedView}>
|
||||
<Trans
|
||||
i18nKey={
|
||||
isTtoservice ? 'orders:view' : 'analysis-results:view'
|
||||
}
|
||||
/>
|
||||
</Button>
|
||||
{isCancelOrderAllowed && (
|
||||
<Button
|
||||
size="sm"
|
||||
className="bg-warning/90 hover:bg-warning mt-2 w-full"
|
||||
onClick={() => setIsConfirmOpen(true)}
|
||||
>
|
||||
<Trans i18nKey="analysis-results:cancel" />
|
||||
</Button>
|
||||
)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
{isCancelOrderAllowed && (
|
||||
<ConfirmationModal
|
||||
isOpen={isConfirmOpen}
|
||||
onClose={() => setIsConfirmOpen(false)}
|
||||
onConfirm={async () => {
|
||||
cancelTtoBooking(
|
||||
order.bookingCode!,
|
||||
order.clinicId!,
|
||||
order.medusaLineItemId!,
|
||||
).then(() => {
|
||||
redirect(pathsConfig.app.myOrders);
|
||||
});
|
||||
}}
|
||||
titleKey="orders:confirmBookingCancel.title"
|
||||
descriptionKey="orders:confirmBookingCancel.description"
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
<TableCell className="px-6 text-right">
|
||||
<Button size="sm" onClick={openDetailedView}>
|
||||
<Trans i18nKey="analysis-results:view" />
|
||||
</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
);
|
||||
}
|
||||
|
||||
75
app/home/(user)/_components/recommendations-skeleton.tsx
Normal file
75
app/home/(user)/_components/recommendations-skeleton.tsx
Normal file
@@ -0,0 +1,75 @@
|
||||
import React from 'react';
|
||||
|
||||
import { InfoTooltip } from '@/packages/shared/src/components/ui/info-tooltip';
|
||||
import { HeartPulse } from 'lucide-react';
|
||||
|
||||
import { Button } from '@kit/ui/shadcn/button';
|
||||
import {
|
||||
Card,
|
||||
CardDescription,
|
||||
CardFooter,
|
||||
CardHeader,
|
||||
} from '@kit/ui/shadcn/card';
|
||||
import { Skeleton } from '@kit/ui/skeleton';
|
||||
|
||||
const RecommendationsSkeleton = () => {
|
||||
const emptyData = [
|
||||
{
|
||||
title: '1',
|
||||
description: '',
|
||||
subtitle: '',
|
||||
variant: { id: '' },
|
||||
price: 1,
|
||||
},
|
||||
{
|
||||
title: '2',
|
||||
description: '',
|
||||
subtitle: '',
|
||||
variant: { id: '' },
|
||||
price: 1,
|
||||
},
|
||||
];
|
||||
return (
|
||||
<div className="xs:grid-cols-3 mt-4 grid gap-6">
|
||||
{emptyData.map(({ title, description, subtitle }) => (
|
||||
<Skeleton key={title}>
|
||||
<Card>
|
||||
<CardHeader className="flex-row">
|
||||
<div
|
||||
className={
|
||||
'mb-6 flex size-8 items-center-safe justify-center-safe'
|
||||
}
|
||||
/>
|
||||
<div className="ml-auto flex size-8 items-center-safe justify-center-safe">
|
||||
<Button size="icon" className="px-2" />
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardFooter className="flex">
|
||||
<div className="flex flex-1 flex-col items-start">
|
||||
<h5>
|
||||
{title}
|
||||
{description && (
|
||||
<>
|
||||
{' '}
|
||||
<InfoTooltip
|
||||
content={
|
||||
<div className="flex flex-col gap-2">
|
||||
<span>{description}</span>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</h5>
|
||||
{subtitle && <CardDescription>{subtitle}</CardDescription>}
|
||||
</div>
|
||||
<div className="flex flex-col items-end gap-2 self-end text-sm"></div>
|
||||
</CardFooter>
|
||||
</Card>
|
||||
</Skeleton>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default RecommendationsSkeleton;
|
||||
30
app/home/(user)/_components/recommendations.tsx
Normal file
30
app/home/(user)/_components/recommendations.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
'use server';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import { AccountWithParams } from '@/packages/features/accounts/src/types/accounts';
|
||||
|
||||
import { loadAnalyses } from '../_lib/server/load-analyses';
|
||||
import { loadRecommendations } from '../_lib/server/load-recommendations';
|
||||
import OrderAnalysesCards from './order-analyses-cards';
|
||||
|
||||
export default async function Recommendations({
|
||||
account,
|
||||
}: {
|
||||
account: AccountWithParams;
|
||||
}) {
|
||||
const { analyses, countryCode } = await loadAnalyses();
|
||||
|
||||
const analysisRecommendations = await loadRecommendations(analyses, account);
|
||||
const orderAnalyses = analyses.filter((analysis) =>
|
||||
analysisRecommendations.includes(analysis.title),
|
||||
);
|
||||
|
||||
if (orderAnalyses.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<OrderAnalysesCards analyses={orderAnalyses} countryCode={countryCode} />
|
||||
);
|
||||
}
|
||||
@@ -1,18 +1,10 @@
|
||||
'use server';
|
||||
|
||||
import { getSupabaseServerClient } from '@/packages/supabase/src/clients/server-client';
|
||||
import { updateLineItem } from '@lib/data/cart';
|
||||
import { StoreProductVariant } from '@medusajs/types';
|
||||
|
||||
import logRequestResult from '~/lib/services/audit.service';
|
||||
import { handleAddToCart } from '~/lib/services/medusaCart.service';
|
||||
import {
|
||||
cancelReservation,
|
||||
createInitialReservation,
|
||||
} from '~/lib/services/reservation.service';
|
||||
import { RequestStatus } from '~/lib/types/audit';
|
||||
import { ConnectedOnlineMethodName } from '~/lib/types/connected-online';
|
||||
import { ExternalApi } from '~/lib/types/external';
|
||||
import { createInitialReservation } from '~/lib/services/reservation.service';
|
||||
|
||||
export async function createInitialReservationAction(
|
||||
selectedVariant: Pick<StoreProductVariant, 'id'>,
|
||||
@@ -49,63 +41,3 @@ export async function createInitialReservationAction(
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export async function cancelTtoBooking(
|
||||
bookingCode: string,
|
||||
clinicId: number,
|
||||
medusaLineItemId: string,
|
||||
) {
|
||||
try {
|
||||
await fetch(
|
||||
`${process.env.CONNECTED_ONLINE_URL}/${ConnectedOnlineMethodName.ConfirmedCancel}`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
param: `{'Value':'${bookingCode}|${clinicId}|et'}`,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
await cancelReservation(medusaLineItemId);
|
||||
|
||||
await logRequestResult(
|
||||
ExternalApi.ConnectedOnline,
|
||||
ConnectedOnlineMethodName.ConfirmedCancel,
|
||||
RequestStatus.Success,
|
||||
medusaLineItemId,
|
||||
);
|
||||
} catch (error) {
|
||||
await logRequestResult(
|
||||
ExternalApi.ConnectedOnline,
|
||||
ConnectedOnlineMethodName.ConfirmedCancel,
|
||||
RequestStatus.Fail,
|
||||
JSON.stringify(error),
|
||||
);
|
||||
if (error instanceof Error) {
|
||||
console.error('Error cancelling booking: ' + error.message);
|
||||
}
|
||||
console.error('Error cancelling booking: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function isPaymentRequiredForService(serviceId: number) {
|
||||
const supabaseClient = getSupabaseServerClient();
|
||||
|
||||
try {
|
||||
const { data } = await supabaseClient
|
||||
.schema('medreport')
|
||||
.from('connected_online_services')
|
||||
.select('requires_payment')
|
||||
.eq('id', serviceId)
|
||||
.is('requires_payment', true)
|
||||
.maybeSingle();
|
||||
|
||||
return !!data;
|
||||
} catch (error) {
|
||||
console.error('Error checking payment requirement: ', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,324 +0,0 @@
|
||||
'use server';
|
||||
|
||||
import { AccountWithParams } from '@/packages/features/accounts/src/types/accounts';
|
||||
import {
|
||||
AnalysisResponse,
|
||||
Patient,
|
||||
} from '@/packages/features/doctor/src/lib/server/schema/doctor-analysis-detail-view.schema';
|
||||
import { getLogger } from '@/packages/shared/src/logger';
|
||||
import { getSupabaseServerClient } from '@/packages/supabase/src/clients/server-client';
|
||||
import OpenAI from 'openai';
|
||||
|
||||
import PersonalCode from '~/lib/utils';
|
||||
|
||||
import {
|
||||
AnalysisResponses,
|
||||
ILifeStyleResponse,
|
||||
PROMPT_NAME,
|
||||
} from '../../_components/ai/types';
|
||||
import { OrderAnalysisCard } from '../../_components/order-analyses-cards';
|
||||
|
||||
export async function updateLifeStyle({
|
||||
account,
|
||||
analysisResponses,
|
||||
isDoctorView = false,
|
||||
aiResponseTimestamp,
|
||||
}: {
|
||||
account: AccountWithParams;
|
||||
analysisResponses?: AnalysisResponses;
|
||||
isDoctorView?: boolean;
|
||||
aiResponseTimestamp: string;
|
||||
}): Promise<ILifeStyleResponse> {
|
||||
const LIFE_STYLE_PROMPT_ID = process.env.PROMPT_ID_LIFE_STYLE;
|
||||
if (!LIFE_STYLE_PROMPT_ID || !account?.personal_code) {
|
||||
return {
|
||||
lifestyle: [],
|
||||
summary: null,
|
||||
};
|
||||
}
|
||||
|
||||
const openAIClient = new OpenAI();
|
||||
const supabaseClient = getSupabaseServerClient();
|
||||
const { gender, age } = PersonalCode.parsePersonalCode(account.personal_code);
|
||||
const weight = account.accountParams?.weight || 'unknown';
|
||||
const height = account.accountParams?.height || 'unknown';
|
||||
const isSmoker = !!account.accountParams?.isSmoker;
|
||||
const cholesterol =
|
||||
analysisResponses
|
||||
?.find((ar) => ar.analysis_name_lab === 'Kolesterool')
|
||||
?.response_value.toString() || 'unknown';
|
||||
const ldl =
|
||||
analysisResponses
|
||||
?.find((ar) => ar.analysis_name_lab === 'LDL kolesterool')
|
||||
?.response_value.toString() || 'unknown';
|
||||
const hdl =
|
||||
analysisResponses
|
||||
?.find((ar) => ar.analysis_name_lab === 'HDL kolesterool')
|
||||
?.response_value.toString() || 'unknown';
|
||||
const vitamind =
|
||||
analysisResponses
|
||||
?.find((ar) => ar.analysis_name_lab === 'Vitamiin D (25-OH)')
|
||||
?.response_value.toString() || 'unknown';
|
||||
|
||||
try {
|
||||
const response = await openAIClient.responses.create({
|
||||
store: false,
|
||||
prompt: {
|
||||
id: LIFE_STYLE_PROMPT_ID,
|
||||
variables: {
|
||||
gender: gender.value,
|
||||
age: age.toString(),
|
||||
weight: weight.toString(),
|
||||
height: height.toString(),
|
||||
cholesterol,
|
||||
ldl,
|
||||
hdl,
|
||||
vitamind,
|
||||
is_smoker: isSmoker.toString(),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await supabaseClient
|
||||
.schema('medreport')
|
||||
.from('ai_responses')
|
||||
.insert({
|
||||
account_id: account.id,
|
||||
prompt_name: PROMPT_NAME.LIFE_STYLE,
|
||||
prompt_id: LIFE_STYLE_PROMPT_ID,
|
||||
input: JSON.stringify({
|
||||
gender: gender.value,
|
||||
age: age.toString(),
|
||||
weight: weight.toString(),
|
||||
cholesterol,
|
||||
ldl,
|
||||
hdl,
|
||||
vitamind,
|
||||
is_smoker: isSmoker.toString(),
|
||||
}),
|
||||
latest_data_change: aiResponseTimestamp,
|
||||
response: response.output_text,
|
||||
is_visible_to_customer: !isDoctorView,
|
||||
});
|
||||
|
||||
const json = JSON.parse(response.output_text);
|
||||
|
||||
return json;
|
||||
} catch (error) {
|
||||
console.error('Error calling OpenAI: ', error);
|
||||
return {
|
||||
lifestyle: [],
|
||||
summary: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateRecommendations({
|
||||
analyses,
|
||||
analysisResponses,
|
||||
account,
|
||||
aiResponseTimestamp,
|
||||
}: {
|
||||
analyses: OrderAnalysisCard[];
|
||||
analysisResponses?: AnalysisResponses;
|
||||
account: AccountWithParams;
|
||||
aiResponseTimestamp: string;
|
||||
}) {
|
||||
const RECOMMENDATIONS_PROMPT_IT =
|
||||
process.env.PROMPT_ID_ANALYSIS_RECOMMENDATIONS;
|
||||
|
||||
if (!RECOMMENDATIONS_PROMPT_IT || !account?.personal_code) {
|
||||
console.error('No prompt ID for analysis recommendations');
|
||||
return [];
|
||||
}
|
||||
|
||||
const openAIClient = new OpenAI();
|
||||
const supabaseClient = getSupabaseServerClient();
|
||||
|
||||
const { gender, age } = PersonalCode.parsePersonalCode(account.personal_code);
|
||||
const weight = account.accountParams?.weight || 'unknown';
|
||||
|
||||
const formattedAnalysisResponses = analysisResponses?.map(
|
||||
({
|
||||
analysis_name_lab,
|
||||
response_value,
|
||||
norm_upper,
|
||||
norm_lower,
|
||||
norm_status,
|
||||
}) => ({
|
||||
name: analysis_name_lab,
|
||||
value: response_value,
|
||||
normUpper: norm_upper,
|
||||
normLower: norm_lower,
|
||||
normStatus: norm_status,
|
||||
}),
|
||||
);
|
||||
const formattedAnalyses = analyses.map(({ description, title }) => ({
|
||||
description,
|
||||
title,
|
||||
}));
|
||||
|
||||
try {
|
||||
const response = await openAIClient.responses.create({
|
||||
store: false,
|
||||
prompt: {
|
||||
id: RECOMMENDATIONS_PROMPT_IT,
|
||||
variables: {
|
||||
analyses: JSON.stringify(formattedAnalyses),
|
||||
results: JSON.stringify(formattedAnalysisResponses),
|
||||
gender: gender.value,
|
||||
age: age.toString(),
|
||||
weight: weight.toString(),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await supabaseClient
|
||||
.schema('medreport')
|
||||
.from('ai_responses')
|
||||
.insert({
|
||||
account_id: account.id,
|
||||
prompt_name: PROMPT_NAME.ANALYSIS_RECOMMENDATIONS,
|
||||
prompt_id: RECOMMENDATIONS_PROMPT_IT,
|
||||
input: JSON.stringify({
|
||||
analyses: formattedAnalyses,
|
||||
results: formattedAnalysisResponses,
|
||||
gender,
|
||||
age,
|
||||
weight,
|
||||
}),
|
||||
latest_data_change: aiResponseTimestamp,
|
||||
response: response.output_text,
|
||||
is_visible_to_customer: false,
|
||||
});
|
||||
|
||||
const json = JSON.parse(response.output_text);
|
||||
|
||||
return json.recommended;
|
||||
} catch (error) {
|
||||
console.error('Error getting recommendations: ', error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export async function generateDoctorFeedback({
|
||||
patient,
|
||||
analysisResponses,
|
||||
aiResponseTimestamp,
|
||||
}: {
|
||||
patient: Patient;
|
||||
analysisResponses: AnalysisResponse[];
|
||||
aiResponseTimestamp: string;
|
||||
}): Promise<string> {
|
||||
const DOCTOR_FEEDBACK_PROMPT_ID = process.env.PROMPT_ID_DOCTOR_FEEDBACK;
|
||||
|
||||
if (!DOCTOR_FEEDBACK_PROMPT_ID) {
|
||||
console.error('No secrets for doctor feedback');
|
||||
return '';
|
||||
}
|
||||
|
||||
const openAIClient = new OpenAI();
|
||||
const supabaseClient = getSupabaseServerClient();
|
||||
|
||||
const formattedAnalysisResponses = analysisResponses?.map(
|
||||
({
|
||||
analysis_name,
|
||||
response_value,
|
||||
norm_upper,
|
||||
norm_lower,
|
||||
norm_status,
|
||||
}) => ({
|
||||
name: analysis_name,
|
||||
value: response_value,
|
||||
normUpper: norm_upper,
|
||||
normLower: norm_lower,
|
||||
normStatus: norm_status,
|
||||
}),
|
||||
);
|
||||
|
||||
try {
|
||||
const response = await openAIClient.responses.create({
|
||||
store: false,
|
||||
prompt: {
|
||||
id: DOCTOR_FEEDBACK_PROMPT_ID,
|
||||
variables: {
|
||||
analysesresults: JSON.stringify(formattedAnalysisResponses),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await supabaseClient
|
||||
.schema('medreport')
|
||||
.from('ai_responses')
|
||||
.insert({
|
||||
account_id: patient.userId,
|
||||
prompt_name: PROMPT_NAME.FEEDBACK,
|
||||
prompt_id: DOCTOR_FEEDBACK_PROMPT_ID,
|
||||
input: JSON.stringify({
|
||||
analysesresults: formattedAnalysisResponses,
|
||||
}),
|
||||
latest_data_change: aiResponseTimestamp,
|
||||
response: response.output_text,
|
||||
});
|
||||
|
||||
return response.output_text;
|
||||
} catch (error) {
|
||||
console.error('Error getting doctor feedback: ', error);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
export async function confirmPatientAIResponses(
|
||||
patientId: string,
|
||||
aiResponseTimestamp: string,
|
||||
recommendations: string[],
|
||||
isRecommendationsEdited: boolean,
|
||||
) {
|
||||
const logger = await getLogger();
|
||||
const supabaseClient = getSupabaseServerClient();
|
||||
|
||||
const { error } = await supabaseClient
|
||||
.schema('medreport')
|
||||
.from('ai_responses')
|
||||
.update({
|
||||
is_visible_to_customer: true,
|
||||
})
|
||||
.eq('latest_data_change', aiResponseTimestamp)
|
||||
.eq('account_id', patientId)
|
||||
.eq('prompt_name', PROMPT_NAME.LIFE_STYLE);
|
||||
|
||||
if (error) {
|
||||
logger.error(
|
||||
{ error, patientId, aiResponseTimestamp },
|
||||
'Failed updating life style',
|
||||
);
|
||||
}
|
||||
|
||||
const { error: _error } = await supabaseClient
|
||||
.schema('medreport')
|
||||
.from('ai_responses')
|
||||
.update({
|
||||
is_visible_to_customer: true,
|
||||
...(isRecommendationsEdited && {
|
||||
response: JSON.stringify({
|
||||
why: 'This was edited by doctor',
|
||||
recommended: recommendations,
|
||||
}),
|
||||
}),
|
||||
})
|
||||
.eq('latest_data_change', aiResponseTimestamp)
|
||||
.eq('account_id', patientId)
|
||||
.eq('prompt_name', PROMPT_NAME.ANALYSIS_RECOMMENDATIONS);
|
||||
|
||||
if (_error) {
|
||||
logger.error(
|
||||
{
|
||||
error,
|
||||
aiResponseTimestamp,
|
||||
patientId,
|
||||
isRecommendationsEdited,
|
||||
},
|
||||
'Failed updating analysis recommendations',
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,8 @@
|
||||
'use server';
|
||||
|
||||
import {
|
||||
AccountBalanceService,
|
||||
AccountBalanceSummary,
|
||||
} from '@kit/accounts/services/account-balance.service';
|
||||
import { AccountBalanceService, AccountBalanceSummary } from '@kit/accounts/services/account-balance.service';
|
||||
|
||||
export async function getAccountBalanceSummary(
|
||||
accountId: string,
|
||||
): Promise<AccountBalanceSummary | null> {
|
||||
export async function getAccountBalanceSummary(accountId: string): Promise<AccountBalanceSummary | null> {
|
||||
try {
|
||||
const service = new AccountBalanceService();
|
||||
return await service.getBalanceSummary(accountId);
|
||||
|
||||
@@ -1,27 +1,25 @@
|
||||
'use server';
|
||||
|
||||
import { AccountWithParams } from '@/packages/features/accounts/src/types/accounts';
|
||||
import { listProductTypes } from '@lib/data';
|
||||
import { initiateMultiPaymentSession, placeOrder } from '@lib/data/cart';
|
||||
import type { StoreCart, StoreOrder } from '@medusajs/types';
|
||||
import jwt from 'jsonwebtoken';
|
||||
import { z } from 'zod';
|
||||
import jwt from 'jsonwebtoken';
|
||||
|
||||
import { getLogger } from '@kit/shared/logger';
|
||||
import type { StoreCart, StoreOrder } from "@medusajs/types";
|
||||
|
||||
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
||||
import { bookAppointment } from '~/lib/services/connected-online.service';
|
||||
import { sendOrderToMedipost } from '~/lib/services/medipost/medipostPrivateMessage.service';
|
||||
import { handleNavigateToPayment } from '~/lib/services/medusaCart.service';
|
||||
import { getOrderedAnalysisIds } from '~/lib/services/medusaOrder.service';
|
||||
import {
|
||||
createAnalysisOrder,
|
||||
getAnalysisOrder,
|
||||
} from '~/lib/services/order.service';
|
||||
import { getOrderedTtoServices } from '~/lib/services/reservation.service';
|
||||
import { initiateMultiPaymentSession, placeOrder } from "@lib/data/cart";
|
||||
import type { AccountBalanceSummary } from "@kit/accounts/services/account-balance.service";
|
||||
import { handleNavigateToPayment } from "~/lib/services/medusaCart.service";
|
||||
import { loadCurrentUserAccount } from "./load-user-account";
|
||||
import { getOrderedAnalysisIds } from "~/lib/services/medusaOrder.service";
|
||||
import { createAnalysisOrder, getAnalysisOrder } from "~/lib/services/order.service";
|
||||
import { listProductTypes } from "@lib/data";
|
||||
import { sendOrderToMedipost } from "~/lib/services/medipost/medipostPrivateMessage.service";
|
||||
import { AccountWithParams } from "@/packages/features/accounts/src/types/accounts";
|
||||
import { createI18nServerInstance } from "~/lib/i18n/i18n.server";
|
||||
import { getSupabaseServerAdminClient } from "@/packages/supabase/src/clients/server-admin-client";
|
||||
import { createNotificationsApi } from "@/packages/features/notifications/src/server/api";
|
||||
import { FailureReason } from '~/lib/types/connected-online';
|
||||
|
||||
import { loadCurrentUserAccount } from './load-user-account';
|
||||
import { getOrderedTtoServices } from '~/lib/services/reservation.service';
|
||||
import { bookAppointment } from '~/lib/services/connected-online.service';
|
||||
|
||||
const ANALYSIS_PACKAGES_TYPE_HANDLE = 'analysis-packages';
|
||||
const ANALYSIS_TYPE_HANDLE = 'synlab-analysis';
|
||||
@@ -42,16 +40,12 @@ const env = () =>
|
||||
isEnabledDispatchOnMontonioCallback: z.boolean({
|
||||
error: 'MEDIPOST_ENABLE_DISPATCH_ON_MONTONIO_CALLBACK is required',
|
||||
}),
|
||||
medusaBackendPublicUrl: z
|
||||
.string({
|
||||
error: 'MEDUSA_BACKEND_PUBLIC_URL is required',
|
||||
})
|
||||
.min(1),
|
||||
companyBenefitsPaymentSecretKey: z
|
||||
.string({
|
||||
error: 'COMPANY_BENEFITS_PAYMENT_SECRET_KEY is required',
|
||||
})
|
||||
.min(1),
|
||||
medusaBackendPublicUrl: z.string({
|
||||
error: 'MEDUSA_BACKEND_PUBLIC_URL is required',
|
||||
}).min(1),
|
||||
companyBenefitsPaymentSecretKey: z.string({
|
||||
error: 'COMPANY_BENEFITS_PAYMENT_SECRET_KEY is required',
|
||||
}).min(1),
|
||||
})
|
||||
.parse({
|
||||
emailSender: process.env.EMAIL_SENDER,
|
||||
@@ -59,18 +53,17 @@ const env = () =>
|
||||
isEnabledDispatchOnMontonioCallback:
|
||||
process.env.MEDIPOST_ENABLE_DISPATCH_ON_MONTONIO_CALLBACK === 'true',
|
||||
medusaBackendPublicUrl: process.env.MEDUSA_BACKEND_PUBLIC_URL!,
|
||||
companyBenefitsPaymentSecretKey:
|
||||
process.env.COMPANY_BENEFITS_PAYMENT_SECRET_KEY!,
|
||||
companyBenefitsPaymentSecretKey: process.env.COMPANY_BENEFITS_PAYMENT_SECRET_KEY!,
|
||||
});
|
||||
|
||||
export const initiatePayment = async ({
|
||||
accountId,
|
||||
benefitsAmount,
|
||||
balanceSummary,
|
||||
cart,
|
||||
language,
|
||||
}: {
|
||||
accountId: string;
|
||||
benefitsAmount: number;
|
||||
balanceSummary: AccountBalanceSummary;
|
||||
cart: StoreCart;
|
||||
language: string;
|
||||
}) => {
|
||||
@@ -81,7 +74,7 @@ export const initiatePayment = async ({
|
||||
totalByMontonio,
|
||||
totalByBenefits,
|
||||
isFullyPaidByBenefits,
|
||||
} = await initiateMultiPaymentSession(cart, benefitsAmount);
|
||||
} = await initiateMultiPaymentSession(cart, balanceSummary.totalBalance);
|
||||
|
||||
if (!isFullyPaidByBenefits) {
|
||||
if (!montonioPaymentSessionId) {
|
||||
@@ -99,30 +92,23 @@ export const initiatePayment = async ({
|
||||
// place order if all paid already
|
||||
const { orderId } = await handlePlaceOrder({ cart });
|
||||
|
||||
const companyBenefitsOrderToken = jwt.sign(
|
||||
{
|
||||
accountId,
|
||||
companyBenefitsPaymentSessionId,
|
||||
orderId,
|
||||
totalByBenefits,
|
||||
const companyBenefitsOrderToken = jwt.sign({
|
||||
accountId,
|
||||
companyBenefitsPaymentSessionId,
|
||||
orderId,
|
||||
totalByBenefits,
|
||||
}, env().companyBenefitsPaymentSecretKey, {
|
||||
algorithm: 'HS256',
|
||||
});
|
||||
const webhookResponse = await fetch(`${env().medusaBackendPublicUrl}/hooks/payment/company-benefits_company-benefits`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
orderToken: companyBenefitsOrderToken,
|
||||
}),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
env().companyBenefitsPaymentSecretKey,
|
||||
{
|
||||
algorithm: 'HS256',
|
||||
},
|
||||
);
|
||||
const webhookResponse = await fetch(
|
||||
`${env().medusaBackendPublicUrl}/hooks/payment/company-benefits_company-benefits`,
|
||||
{
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
orderToken: companyBenefitsOrderToken,
|
||||
}),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
},
|
||||
);
|
||||
});
|
||||
if (!webhookResponse.ok) {
|
||||
throw new Error('Failed to send company benefits webhook');
|
||||
}
|
||||
@@ -132,16 +118,14 @@ export const initiatePayment = async ({
|
||||
console.error('Error initiating payment', error);
|
||||
}
|
||||
|
||||
return {
|
||||
url: null,
|
||||
isFullyPaidByBenefits: false,
|
||||
orderId: null,
|
||||
unavailableLineItemIds: [],
|
||||
};
|
||||
};
|
||||
return { url: null, isFullyPaidByBenefits: false, orderId: null, unavailableLineItemIds: [] };
|
||||
}
|
||||
|
||||
export async function handlePlaceOrder({ cart }: { cart: StoreCart }) {
|
||||
const logger = await getLogger();
|
||||
export async function handlePlaceOrder({
|
||||
cart,
|
||||
}: {
|
||||
cart: StoreCart;
|
||||
}) {
|
||||
const { account } = await loadCurrentUserAccount();
|
||||
if (!account) {
|
||||
throw new Error('Account not found in context');
|
||||
@@ -161,7 +145,7 @@ export async function handlePlaceOrder({ cart }: { cart: StoreCart }) {
|
||||
const existingAnalysisOrder = await getAnalysisOrder({
|
||||
medusaOrderId: medusaOrder.id,
|
||||
});
|
||||
logger.info(
|
||||
console.info(
|
||||
`Analysis order already exists for medusaOrderId=${medusaOrder.id}, orderId=${existingAnalysisOrder.id}`,
|
||||
);
|
||||
return { success: true, orderId: existingAnalysisOrder.id };
|
||||
@@ -186,8 +170,7 @@ export async function handlePlaceOrder({ cart }: { cart: StoreCart }) {
|
||||
let bookServiceResults: {
|
||||
success: boolean;
|
||||
reason?: FailureReason;
|
||||
bookingCode: string | null;
|
||||
clinicKey: string | null;
|
||||
serviceId?: number;
|
||||
}[] = [];
|
||||
if (orderedTtoServices?.length) {
|
||||
const bookingPromises = orderedTtoServices.map((service) =>
|
||||
@@ -210,35 +193,22 @@ export async function handlePlaceOrder({ cart }: { cart: StoreCart }) {
|
||||
analysisPackageOrder,
|
||||
});
|
||||
} else {
|
||||
logger.info(`Order has no analysis package, skipping email.`);
|
||||
console.info(`Order has no analysis package, skipping email.`);
|
||||
}
|
||||
|
||||
if (analysisItemsOrder) {
|
||||
// @TODO send email for separate analyses
|
||||
logger.warn(
|
||||
console.warn(
|
||||
`Order has analysis items, but no email template exists yet`,
|
||||
);
|
||||
} else {
|
||||
logger.info(`Order has no analysis items, skipping email.`);
|
||||
console.info(`Order has no analysis items, skipping email.`);
|
||||
}
|
||||
} else {
|
||||
logger.error('Missing email to send order result email', orderResult);
|
||||
console.error('Missing email to send order result email', orderResult);
|
||||
}
|
||||
|
||||
// if (bookServiceResults?.length) {
|
||||
// bookServiceResults.forEach(async ({ bookingCode, clinicKey }) => {
|
||||
// if (!bookingCode || !clinicKey) {
|
||||
// logger.info('A booking is missing either bookingCode or clinicKey', {
|
||||
// bookingCode,
|
||||
// clinicKey,
|
||||
// });
|
||||
// return;
|
||||
// }
|
||||
// await getConfirmedService(bookingCode, clinicKey);
|
||||
// });
|
||||
// }
|
||||
|
||||
if (env().isEnabledDispatchOnMontonioCallback && orderContainsSynlabItems) {
|
||||
if (env().isEnabledDispatchOnMontonioCallback) {
|
||||
await sendOrderToMedipost({ medusaOrderId, orderedAnalysisElements });
|
||||
}
|
||||
|
||||
@@ -341,6 +311,7 @@ const sendEmail = async ({
|
||||
partnerLocationName: string;
|
||||
language: string;
|
||||
}) => {
|
||||
const client = getSupabaseServerAdminClient();
|
||||
try {
|
||||
const { renderSynlabAnalysisPackageEmail } = await import(
|
||||
'@kit/email-templates'
|
||||
@@ -366,6 +337,10 @@ const sendEmail = async ({
|
||||
.catch((error) => {
|
||||
throw new Error(`Failed to send email, message=${error}`);
|
||||
});
|
||||
await createNotificationsApi(client).createNotification({
|
||||
account_id: account.id,
|
||||
body: html,
|
||||
});
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to send email, message=${error}`);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@ export const isValidOpenAiEnv = async () => {
|
||||
const client = new OpenAI();
|
||||
await client.models.list();
|
||||
return true;
|
||||
} catch {
|
||||
} catch (e) {
|
||||
console.log('No openAI env');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@ import { cache } from 'react';
|
||||
import { getAnalysisElementMedusaProductIds } from '@/utils/medusa-product';
|
||||
import { listProductTypes, listProducts } from '@lib/data/products';
|
||||
import { listRegions } from '@lib/data/regions';
|
||||
import type { StoreProduct, StoreProductType } from '@medusajs/types';
|
||||
import type { StoreProduct } from '@medusajs/types';
|
||||
|
||||
import type { AccountWithParams } from '@kit/accounts/types/accounts';
|
||||
import type { AnalysisPackageWithVariant } from '@kit/shared/components/select-analysis-package';
|
||||
@@ -118,12 +118,17 @@ async function analysisPackageElementsLoader({
|
||||
async function analysisPackagesWithVariantLoader({
|
||||
account,
|
||||
countryCode,
|
||||
productType,
|
||||
}: {
|
||||
account: AccountWithParams;
|
||||
countryCode: string;
|
||||
productType: StoreProductType;
|
||||
}) {
|
||||
const productTypes = await loadProductTypes();
|
||||
const productType = productTypes.find(
|
||||
({ metadata }) => metadata?.handle === 'analysis-packages',
|
||||
);
|
||||
if (!productType) {
|
||||
return null;
|
||||
}
|
||||
const analysisPackagesResponse = await listProducts({
|
||||
countryCode,
|
||||
queryParams: { limit: 100, 'type_id[0]': productType.id },
|
||||
@@ -166,23 +171,12 @@ async function analysisPackagesLoader() {
|
||||
throw new Error('Account not found');
|
||||
}
|
||||
|
||||
const [countryCodes, productTypes] = await Promise.all([
|
||||
loadCountryCodes(),
|
||||
loadProductTypes(),
|
||||
]);
|
||||
const countryCodes = await loadCountryCodes();
|
||||
const countryCode = countryCodes[0]!;
|
||||
const productType = productTypes.find(
|
||||
({ metadata }) => metadata?.handle === 'analysis-packages',
|
||||
);
|
||||
|
||||
if (!productType) {
|
||||
return { analysisPackageElements: [], analysisPackages: [], countryCode };
|
||||
}
|
||||
|
||||
const analysisPackagesWithVariant = await analysisPackagesWithVariantLoader({
|
||||
account,
|
||||
countryCode,
|
||||
productType,
|
||||
});
|
||||
if (!analysisPackagesWithVariant) {
|
||||
return { analysisPackageElements: [], analysisPackages: [], countryCode };
|
||||
|
||||
@@ -1,31 +1,19 @@
|
||||
import { cache } from 'react';
|
||||
|
||||
import {
|
||||
getProductCategories,
|
||||
listProductTypes,
|
||||
listProducts,
|
||||
} from '@lib/data';
|
||||
import { getProductCategories, listProducts } from '@lib/data';
|
||||
|
||||
import { findProductTypeIdByHandle } from '~/lib/utils';
|
||||
|
||||
import { isPaymentRequiredForService } from './actions';
|
||||
import { loadCountryCodes } from './load-analyses';
|
||||
|
||||
async function categoryLoader({ handle }: { handle: string }) {
|
||||
const [response, countryCodes, { productTypes }] = await Promise.all([
|
||||
const [response, countryCodes] = await Promise.all([
|
||||
getProductCategories({
|
||||
handle,
|
||||
limit: 1,
|
||||
}),
|
||||
loadCountryCodes(),
|
||||
listProductTypes(),
|
||||
]);
|
||||
const category = response.product_categories[0];
|
||||
const countryCode = countryCodes[0]!;
|
||||
const ttoServiceTypeId = findProductTypeIdByHandle(
|
||||
productTypes,
|
||||
'tto-service',
|
||||
);
|
||||
|
||||
if (!response.product_categories?.[0]?.id) {
|
||||
return { category: null };
|
||||
@@ -38,27 +26,6 @@ async function categoryLoader({ handle }: { handle: string }) {
|
||||
queryParams: { limit: 100, category_id: response.product_categories[0].id },
|
||||
});
|
||||
|
||||
const productsWithNoRequiredPayment = categoryProducts.filter(
|
||||
async (product) => {
|
||||
if (product.type_id !== ttoServiceTypeId) {
|
||||
return false;
|
||||
}
|
||||
if (product.metadata?.serviceIds) {
|
||||
const serviceIds: number[] = JSON.parse(
|
||||
product.metadata.serviceIds as string,
|
||||
);
|
||||
for (const serviceId of serviceIds) {
|
||||
const requiresPayment = await isPaymentRequiredForService(serviceId);
|
||||
if (requiresPayment) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
category: {
|
||||
color:
|
||||
@@ -69,7 +36,7 @@ async function categoryLoader({ handle }: { handle: string }) {
|
||||
handle: category?.handle || '',
|
||||
name: category?.name || '',
|
||||
countryCode,
|
||||
products: productsWithNoRequiredPayment,
|
||||
products: categoryProducts,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
import { cache } from 'react';
|
||||
|
||||
import { AccountWithParams } from '@/packages/features/accounts/src/types/accounts';
|
||||
import { getLogger } from '@/packages/shared/src/logger';
|
||||
import { getSupabaseServerClient } from '@/packages/supabase/src/clients/server-client';
|
||||
|
||||
import {
|
||||
AnalysisResponses,
|
||||
ILifeStyleResponse,
|
||||
PROMPT_NAME,
|
||||
} from '../../_components/ai/types';
|
||||
import { updateLifeStyle } from './ai-actions';
|
||||
|
||||
const failedResponse = {
|
||||
response: {
|
||||
lifestyle: [],
|
||||
summary: null,
|
||||
},
|
||||
dateCreated: new Date().toISOString(),
|
||||
};
|
||||
|
||||
async function lifeStyleLoader({
|
||||
account,
|
||||
analysisResponses,
|
||||
isDoctorView = false,
|
||||
aiResponseTimestamp,
|
||||
}: {
|
||||
account: AccountWithParams | null;
|
||||
analysisResponses?: AnalysisResponses;
|
||||
isDoctorView?: boolean;
|
||||
aiResponseTimestamp: string;
|
||||
}): Promise<{ response: ILifeStyleResponse; dateCreated: string }> {
|
||||
const logger = await getLogger();
|
||||
if (!account?.personal_code) {
|
||||
return failedResponse;
|
||||
}
|
||||
|
||||
const supabaseClient = getSupabaseServerClient();
|
||||
const query = supabaseClient
|
||||
.schema('medreport')
|
||||
.from('ai_responses')
|
||||
.select('response, latest_data_change')
|
||||
.eq('account_id', account.id)
|
||||
.eq('prompt_name', PROMPT_NAME.LIFE_STYLE);
|
||||
|
||||
if (isDoctorView) {
|
||||
logger.info(
|
||||
{ aiResponseTimestamp, accountId: account.id },
|
||||
'Attempting to receive life style row',
|
||||
);
|
||||
query.eq('latest_data_change', aiResponseTimestamp);
|
||||
} else {
|
||||
query
|
||||
.eq('is_visible_to_customer', true)
|
||||
.order('latest_data_change', { ascending: false, nullsFirst: false });
|
||||
}
|
||||
|
||||
const { data, error } = await query.limit(1).maybeSingle();
|
||||
|
||||
logger.info({ data: !!data }, 'Existing life style row');
|
||||
|
||||
if (error) {
|
||||
console.error('Error fetching AI response from DB: ', error);
|
||||
return failedResponse;
|
||||
}
|
||||
|
||||
if (data?.response) {
|
||||
return {
|
||||
response: JSON.parse(data.response as string),
|
||||
dateCreated: data.latest_data_change,
|
||||
};
|
||||
} else {
|
||||
const newLifeStyle = await updateLifeStyle({
|
||||
account,
|
||||
analysisResponses,
|
||||
isDoctorView,
|
||||
aiResponseTimestamp,
|
||||
});
|
||||
|
||||
return { response: newLifeStyle, dateCreated: aiResponseTimestamp };
|
||||
}
|
||||
}
|
||||
export const loadLifeStyle = cache(lifeStyleLoader);
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user