MED-103: add booking functionality
This commit is contained in:
@@ -1,8 +1,42 @@
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
|
import { Tables } from '@kit/supabase/database';
|
||||||
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
||||||
|
|
||||||
import type { ISearchLoadResponse } from '~/lib/types/connected-online';
|
import { logSyncResult } from '~/lib/services/audit.service';
|
||||||
|
import { SyncStatus } from '~/lib/types/audit';
|
||||||
|
import type {
|
||||||
|
ISearchLoadResponse,
|
||||||
|
P_JobTitleTranslation,
|
||||||
|
} from '~/lib/types/connected-online';
|
||||||
|
|
||||||
|
function createTranslationMap(translations: P_JobTitleTranslation[]) {
|
||||||
|
const result: Map<
|
||||||
|
number,
|
||||||
|
Map<number, { textEN: string; textRU: string; textET: string }>
|
||||||
|
> = new Map();
|
||||||
|
|
||||||
|
for (const translation of translations) {
|
||||||
|
const { ClinicID, TextET, TextEN, TextRU, SyncID } = translation;
|
||||||
|
|
||||||
|
if (!result.has(ClinicID)) {
|
||||||
|
result.set(ClinicID, new Map());
|
||||||
|
}
|
||||||
|
|
||||||
|
result.get(ClinicID)!.set(SyncID, {
|
||||||
|
textET: TextET,
|
||||||
|
textEN: TextEN,
|
||||||
|
textRU: TextRU,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSpokenLanguages(spokenLanguages?: string) {
|
||||||
|
if (!spokenLanguages || !spokenLanguages.length) return [];
|
||||||
|
return spokenLanguages.split(',');
|
||||||
|
}
|
||||||
|
|
||||||
export default async function syncConnectedOnline() {
|
export default async function syncConnectedOnline() {
|
||||||
const isProd = process.env.NODE_ENV === 'production';
|
const isProd = process.env.NODE_ENV === 'production';
|
||||||
@@ -16,14 +50,19 @@ export default async function syncConnectedOnline() {
|
|||||||
const supabase = getSupabaseServerAdminClient();
|
const supabase = getSupabaseServerAdminClient();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.post<{ d: string }>(`${baseUrl}/Search_Load`, {
|
const searchLoadResponse = await axios.post<{ d: string }>(
|
||||||
headers: {
|
`${baseUrl}/Search_Load`,
|
||||||
'Content-Type': 'application/json; charset=utf-8',
|
{
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json; charset=utf-8',
|
||||||
|
},
|
||||||
|
param: "{'Value':'|et|-1'}", // get all available services in Estonian
|
||||||
},
|
},
|
||||||
param: "{'Value':'|et|-1'}", // get all available services in Estonian
|
);
|
||||||
});
|
|
||||||
|
|
||||||
const responseData: ISearchLoadResponse = JSON.parse(response.data.d);
|
const responseData: ISearchLoadResponse = JSON.parse(
|
||||||
|
searchLoadResponse.data.d,
|
||||||
|
);
|
||||||
|
|
||||||
if (responseData?.ErrorCode !== 0) {
|
if (responseData?.ErrorCode !== 0) {
|
||||||
throw new Error('Failed to get Connected Online data');
|
throw new Error('Failed to get Connected Online data');
|
||||||
@@ -43,16 +82,35 @@ export default async function syncConnectedOnline() {
|
|||||||
|
|
||||||
let clinics;
|
let clinics;
|
||||||
let services;
|
let services;
|
||||||
|
let serviceProviders;
|
||||||
|
let jobTitleTranslations;
|
||||||
// Filter out "Dentas Demo OÜ" in prod or only sync "Dentas Demo OÜ" in any other environment
|
// Filter out "Dentas Demo OÜ" in prod or only sync "Dentas Demo OÜ" in any other environment
|
||||||
|
const isDemoClinic = (clinicId: number) => clinicId === 2;
|
||||||
if (isProd) {
|
if (isProd) {
|
||||||
clinics = responseData.Data.T_Lic.filter((clinic) => clinic.ID !== 2);
|
clinics = responseData.Data.T_Lic.filter(({ ID }) => !isDemoClinic(ID));
|
||||||
services = responseData.Data.T_Service.filter(
|
services = responseData.Data.T_Service.filter(
|
||||||
(service) => service.ClinicID !== 2,
|
({ ClinicID }) => !isDemoClinic(ClinicID),
|
||||||
|
);
|
||||||
|
serviceProviders = responseData.Data.T_Doctor.filter(
|
||||||
|
({ ClinicID }) => !isDemoClinic(ClinicID),
|
||||||
|
);
|
||||||
|
jobTitleTranslations = createTranslationMap(
|
||||||
|
responseData.Data.P_JobTitleTranslations.filter(
|
||||||
|
({ ClinicID }) => !isDemoClinic(ClinicID),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
clinics = responseData.Data.T_Lic.filter((clinic) => clinic.ID === 2);
|
clinics = responseData.Data.T_Lic.filter(({ ID }) => isDemoClinic(ID));
|
||||||
services = responseData.Data.T_Service.filter(
|
services = responseData.Data.T_Service.filter(({ ClinicID }) =>
|
||||||
(service) => service.ClinicID === 2,
|
isDemoClinic(ClinicID),
|
||||||
|
);
|
||||||
|
serviceProviders = responseData.Data.T_Doctor.filter(({ ClinicID }) =>
|
||||||
|
isDemoClinic(ClinicID),
|
||||||
|
);
|
||||||
|
jobTitleTranslations = createTranslationMap(
|
||||||
|
responseData.Data.P_JobTitleTranslations.filter(({ ClinicID }) =>
|
||||||
|
isDemoClinic(ClinicID),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,6 +122,8 @@ export default async function syncConnectedOnline() {
|
|||||||
name: clinic.Name,
|
name: clinic.Name,
|
||||||
personal_code_required: !!clinic.PersonalCodeRequired,
|
personal_code_required: !!clinic.PersonalCodeRequired,
|
||||||
phone_number: clinic.Phone || null,
|
phone_number: clinic.Phone || null,
|
||||||
|
key: clinic.Key,
|
||||||
|
address: clinic.Address,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -87,45 +147,133 @@ export default async function syncConnectedOnline() {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const mappedServiceProviders = serviceProviders.map((serviceProvider) => {
|
||||||
|
const jobTitleTranslation = serviceProvider.JobTitleID
|
||||||
|
? jobTitleTranslations
|
||||||
|
.get(serviceProvider.ClinicID)
|
||||||
|
?.get(serviceProvider.JobTitleID)
|
||||||
|
: null;
|
||||||
|
return {
|
||||||
|
id: serviceProvider.ID,
|
||||||
|
prefix: serviceProvider.Prefix,
|
||||||
|
name: serviceProvider.Name,
|
||||||
|
spoken_languages: getSpokenLanguages(serviceProvider.SpokenLanguages),
|
||||||
|
job_title_et: jobTitleTranslation?.textET,
|
||||||
|
job_title_en: jobTitleTranslation?.textEN,
|
||||||
|
job_title_ru: jobTitleTranslation?.textRU,
|
||||||
|
job_title_id: serviceProvider.JobTitleID,
|
||||||
|
is_deleted: !!serviceProvider.Deleted,
|
||||||
|
clinic_id: serviceProvider.ClinicID,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
const { error: providersError } = await supabase
|
const { error: providersError } = await supabase
|
||||||
.schema('medreport')
|
.schema('medreport')
|
||||||
.from('connected_online_providers')
|
.from('connected_online_providers')
|
||||||
.upsert(mappedClinics);
|
.upsert(mappedClinics);
|
||||||
|
|
||||||
|
if (providersError) {
|
||||||
|
return logSyncResult({
|
||||||
|
operation: 'CONNECTED_ONLINE_SYNC',
|
||||||
|
comment:
|
||||||
|
'Error saving connected online providers: ' +
|
||||||
|
JSON.stringify(providersError),
|
||||||
|
status: SyncStatus.Fail,
|
||||||
|
changed_by_role: 'service_role',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const { error: servicesError } = await supabase
|
const { error: servicesError } = await supabase
|
||||||
.schema('medreport')
|
.schema('medreport')
|
||||||
.from('connected_online_services')
|
.from('connected_online_services')
|
||||||
.upsert(mappedServices, { onConflict: 'id', ignoreDuplicates: false });
|
.upsert(mappedServices, {
|
||||||
|
onConflict: 'id',
|
||||||
|
ignoreDuplicates: false,
|
||||||
|
});
|
||||||
|
|
||||||
if (providersError || servicesError) {
|
if (servicesError) {
|
||||||
return supabase
|
return logSyncResult({
|
||||||
.schema('audit')
|
operation: 'CONNECTED_ONLINE_SYNC',
|
||||||
.from('sync_entries')
|
comment:
|
||||||
.insert({
|
'Error saving connected online services: ' +
|
||||||
operation: 'CONNECTED_ONLINE_SYNC',
|
JSON.stringify(servicesError),
|
||||||
comment: providersError
|
status: SyncStatus.Fail,
|
||||||
? 'Error saving providers: ' + JSON.stringify(providersError)
|
changed_by_role: 'service_role',
|
||||||
: 'Error saving services: ' + JSON.stringify(servicesError),
|
});
|
||||||
status: 'FAIL',
|
|
||||||
changed_by_role: 'service_role',
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await supabase.schema('audit').from('sync_entries').insert({
|
const { error: serviceProvidersError } = await supabase
|
||||||
|
.schema('medreport')
|
||||||
|
.from('connected_online_service_providers')
|
||||||
|
.upsert(mappedServiceProviders, {
|
||||||
|
onConflict: 'id',
|
||||||
|
ignoreDuplicates: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (serviceProvidersError) {
|
||||||
|
return logSyncResult({
|
||||||
|
operation: 'CONNECTED_ONLINE_SYNC',
|
||||||
|
comment:
|
||||||
|
'Error saving service providers: ' +
|
||||||
|
JSON.stringify(serviceProvidersError),
|
||||||
|
status: SyncStatus.Fail,
|
||||||
|
changed_by_role: 'service_role',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const mappedClinic of mappedClinics) {
|
||||||
|
const defaultLoadResponse = await axios.post<{ d: string }>(
|
||||||
|
`${baseUrl}/Default_Load`,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json; charset=utf-8',
|
||||||
|
},
|
||||||
|
param: `{'Value':'${mappedClinic.key}|et'}`,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const defaultLoadResponseData = JSON.parse(defaultLoadResponse.data.d);
|
||||||
|
|
||||||
|
if (defaultLoadResponseData?.ErrorCode !== 0) {
|
||||||
|
throw new Error('Failed to get Connected Online location data');
|
||||||
|
}
|
||||||
|
|
||||||
|
const clinicLocations: {
|
||||||
|
SyncID: number;
|
||||||
|
Address: string;
|
||||||
|
Name: string;
|
||||||
|
}[] = defaultLoadResponseData.Data.T_SelectableLocation;
|
||||||
|
|
||||||
|
if (clinicLocations?.length) {
|
||||||
|
const mappedLocations = clinicLocations.map(
|
||||||
|
({ SyncID, Address, Name }) => ({
|
||||||
|
address: Address,
|
||||||
|
clinic_id: mappedClinic.id,
|
||||||
|
sync_id: SyncID,
|
||||||
|
name: Name,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
await supabase
|
||||||
|
.schema('medreport')
|
||||||
|
.from('connected_online_locations')
|
||||||
|
.insert(mappedLocations)
|
||||||
|
.throwOnError();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await logSyncResult({
|
||||||
operation: 'CONNECTED_ONLINE_SYNC',
|
operation: 'CONNECTED_ONLINE_SYNC',
|
||||||
status: 'SUCCESS',
|
status: SyncStatus.Success,
|
||||||
changed_by_role: 'service_role',
|
changed_by_role: 'service_role',
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await supabase
|
await logSyncResult({
|
||||||
.schema('audit')
|
operation: 'CONNECTED_ONLINE_SYNC',
|
||||||
.from('sync_entries')
|
status: SyncStatus.Fail,
|
||||||
.insert({
|
comment: JSON.stringify(e),
|
||||||
operation: 'CONNECTED_ONLINE_SYNC',
|
changed_by_role: 'service_role',
|
||||||
status: 'FAIL',
|
});
|
||||||
comment: JSON.stringify(e),
|
|
||||||
changed_by_role: 'service_role',
|
|
||||||
});
|
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Failed to sync Connected Online data, error: ${JSON.stringify(e)}`,
|
`Failed to sync Connected Online data, error: ${JSON.stringify(e)}`,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -18,7 +18,11 @@ export const generateMetadata = async () => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
async function BookingHandlePage({ params }: { params: { handle: string } }) {
|
async function BookingHandlePage({
|
||||||
|
params,
|
||||||
|
}: {
|
||||||
|
params: Promise<{ handle: string }>;
|
||||||
|
}) {
|
||||||
const { handle } = await params;
|
const { handle } = await params;
|
||||||
const { category } = await loadCategory({ handle });
|
const { category } = await loadCategory({ handle });
|
||||||
|
|
||||||
|
|||||||
@@ -1,45 +1,61 @@
|
|||||||
'use server';
|
'use server';
|
||||||
|
|
||||||
|
import { MontonioOrderToken } from '@/app/home/(user)/_components/cart/types';
|
||||||
|
import { loadCurrentUserAccount } from '@/app/home/(user)/_lib/server/load-user-account';
|
||||||
|
import { placeOrder, retrieveCart } from '@lib/data/cart';
|
||||||
|
import { listProductTypes } from '@lib/data/products';
|
||||||
|
import type { StoreOrder } from '@medusajs/types';
|
||||||
import jwt from 'jsonwebtoken';
|
import jwt from 'jsonwebtoken';
|
||||||
import { z } from "zod";
|
import { z } from 'zod';
|
||||||
import { MontonioOrderToken } from "@/app/home/(user)/_components/cart/types";
|
|
||||||
import { loadCurrentUserAccount } from "@/app/home/(user)/_lib/server/load-user-account";
|
import type { AccountWithParams } from '@kit/accounts/api';
|
||||||
import { listProductTypes } from "@lib/data/products";
|
|
||||||
import { placeOrder, retrieveCart } from "@lib/data/cart";
|
|
||||||
import { createI18nServerInstance } from "~/lib/i18n/i18n.server";
|
|
||||||
import { createAnalysisOrder, getAnalysisOrder } from '~/lib/services/order.service';
|
|
||||||
import { getOrderedAnalysisIds, sendOrderToMedipost } from '~/lib/services/medipost.service';
|
|
||||||
import { createNotificationsApi } from '@kit/notifications/api';
|
import { createNotificationsApi } from '@kit/notifications/api';
|
||||||
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
||||||
import type { AccountWithParams } from '@kit/accounts/api';
|
|
||||||
import type { StoreOrder } from '@medusajs/types';
|
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
||||||
|
import {
|
||||||
|
bookAppointment,
|
||||||
|
getOrderedTtoServices,
|
||||||
|
} from '~/lib/services/connected-online.service';
|
||||||
|
import {
|
||||||
|
getOrderedAnalysisIds,
|
||||||
|
sendOrderToMedipost,
|
||||||
|
} from '~/lib/services/medipost.service';
|
||||||
|
import {
|
||||||
|
createAnalysisOrder,
|
||||||
|
getAnalysisOrder,
|
||||||
|
} from '~/lib/services/order.service';
|
||||||
|
|
||||||
|
import { FailureReason } from '../../../../../../lib/types/connected-online';
|
||||||
|
|
||||||
const ANALYSIS_PACKAGES_TYPE_HANDLE = 'analysis-packages';
|
const ANALYSIS_PACKAGES_TYPE_HANDLE = 'analysis-packages';
|
||||||
const ANALYSIS_TYPE_HANDLE = 'synlab-analysis';
|
const ANALYSIS_TYPE_HANDLE = 'synlab-analysis';
|
||||||
|
const TTO_SERVICE_TYPE_HANDLE = 'tto-service';
|
||||||
const MONTONIO_PAID_STATUS = 'PAID';
|
const MONTONIO_PAID_STATUS = 'PAID';
|
||||||
|
|
||||||
const env = () => z
|
const env = () =>
|
||||||
.object({
|
z
|
||||||
emailSender: z
|
.object({
|
||||||
.string({
|
emailSender: z
|
||||||
error: 'EMAIL_SENDER is required',
|
.string({
|
||||||
})
|
error: 'EMAIL_SENDER is required',
|
||||||
.min(1),
|
})
|
||||||
siteUrl: z
|
.min(1),
|
||||||
.string({
|
siteUrl: z
|
||||||
error: 'NEXT_PUBLIC_SITE_URL is required',
|
.string({
|
||||||
})
|
error: 'NEXT_PUBLIC_SITE_URL is required',
|
||||||
.min(1),
|
})
|
||||||
isEnabledDispatchOnMontonioCallback: z
|
.min(1),
|
||||||
.boolean({
|
isEnabledDispatchOnMontonioCallback: z.boolean({
|
||||||
error: 'MEDIPOST_ENABLE_DISPATCH_ON_MONTONIO_CALLBACK is required',
|
error: 'MEDIPOST_ENABLE_DISPATCH_ON_MONTONIO_CALLBACK is required',
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
.parse({
|
.parse({
|
||||||
emailSender: process.env.EMAIL_SENDER,
|
emailSender: process.env.EMAIL_SENDER,
|
||||||
siteUrl: process.env.NEXT_PUBLIC_SITE_URL!,
|
siteUrl: process.env.NEXT_PUBLIC_SITE_URL!,
|
||||||
isEnabledDispatchOnMontonioCallback: process.env.MEDIPOST_ENABLE_DISPATCH_ON_MONTONIO_CALLBACK === 'true',
|
isEnabledDispatchOnMontonioCallback:
|
||||||
});
|
process.env.MEDIPOST_ENABLE_DISPATCH_ON_MONTONIO_CALLBACK === 'true',
|
||||||
|
});
|
||||||
|
|
||||||
const sendEmail = async ({
|
const sendEmail = async ({
|
||||||
account,
|
account,
|
||||||
@@ -48,15 +64,17 @@ const sendEmail = async ({
|
|||||||
partnerLocationName,
|
partnerLocationName,
|
||||||
language,
|
language,
|
||||||
}: {
|
}: {
|
||||||
account: Pick<AccountWithParams, 'name' | 'id'>,
|
account: Pick<AccountWithParams, 'name' | 'id'>;
|
||||||
email: string,
|
email: string;
|
||||||
analysisPackageName: string,
|
analysisPackageName: string;
|
||||||
partnerLocationName: string,
|
partnerLocationName: string;
|
||||||
language: string,
|
language: string;
|
||||||
}) => {
|
}) => {
|
||||||
const client = getSupabaseServerAdminClient();
|
const client = getSupabaseServerAdminClient();
|
||||||
try {
|
try {
|
||||||
const { renderSynlabAnalysisPackageEmail } = await import('@kit/email-templates');
|
const { renderSynlabAnalysisPackageEmail } = await import(
|
||||||
|
'@kit/email-templates'
|
||||||
|
);
|
||||||
const { getMailer } = await import('@kit/mailers');
|
const { getMailer } = await import('@kit/mailers');
|
||||||
|
|
||||||
const mailer = await getMailer();
|
const mailer = await getMailer();
|
||||||
@@ -78,15 +96,14 @@ const sendEmail = async ({
|
|||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
throw new Error(`Failed to send email, message=${error}`);
|
throw new Error(`Failed to send email, message=${error}`);
|
||||||
});
|
});
|
||||||
await createNotificationsApi(client)
|
await createNotificationsApi(client).createNotification({
|
||||||
.createNotification({
|
account_id: account.id,
|
||||||
account_id: account.id,
|
body: html,
|
||||||
body: html,
|
});
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(`Failed to send email, message=${error}`);
|
throw new Error(`Failed to send email, message=${error}`);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
async function decodeOrderToken(orderToken: string) {
|
async function decodeOrderToken(orderToken: string) {
|
||||||
const secretKey = process.env.MONTONIO_SECRET_KEY as string;
|
const secretKey = process.env.MONTONIO_SECRET_KEY as string;
|
||||||
@@ -96,7 +113,7 @@ async function decodeOrderToken(orderToken: string) {
|
|||||||
}) as MontonioOrderToken;
|
}) as MontonioOrderToken;
|
||||||
|
|
||||||
if (decoded.paymentStatus !== MONTONIO_PAID_STATUS) {
|
if (decoded.paymentStatus !== MONTONIO_PAID_STATUS) {
|
||||||
throw new Error("Payment not successful");
|
throw new Error('Payment not successful');
|
||||||
}
|
}
|
||||||
|
|
||||||
return decoded;
|
return decoded;
|
||||||
@@ -105,38 +122,49 @@ async function decodeOrderToken(orderToken: string) {
|
|||||||
async function getCartByOrderToken(decoded: MontonioOrderToken) {
|
async function getCartByOrderToken(decoded: MontonioOrderToken) {
|
||||||
const [, , cartId] = decoded.merchantReferenceDisplay.split(':');
|
const [, , cartId] = decoded.merchantReferenceDisplay.split(':');
|
||||||
if (!cartId) {
|
if (!cartId) {
|
||||||
throw new Error("Cart ID not found");
|
throw new Error('Cart ID not found');
|
||||||
}
|
}
|
||||||
const cart = await retrieveCart(cartId);
|
const cart = await retrieveCart(cartId);
|
||||||
if (!cart) {
|
if (!cart) {
|
||||||
throw new Error("Cart not found");
|
throw new Error('Cart not found');
|
||||||
}
|
}
|
||||||
return cart;
|
return cart;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getOrderResultParameters(medusaOrder: StoreOrder) {
|
async function getOrderResultParameters(medusaOrder: StoreOrder) {
|
||||||
const { productTypes } = await listProductTypes();
|
const { productTypes } = await listProductTypes();
|
||||||
const analysisPackagesType = productTypes.find(({ metadata }) => metadata?.handle === ANALYSIS_PACKAGES_TYPE_HANDLE);
|
const analysisPackagesType = productTypes.find(
|
||||||
const analysisType = productTypes.find(({ metadata }) => metadata?.handle === ANALYSIS_TYPE_HANDLE);
|
({ metadata }) => metadata?.handle === ANALYSIS_PACKAGES_TYPE_HANDLE,
|
||||||
|
);
|
||||||
|
const analysisType = productTypes.find(
|
||||||
|
({ metadata }) => metadata?.handle === ANALYSIS_TYPE_HANDLE,
|
||||||
|
);
|
||||||
|
|
||||||
const analysisPackageOrderItem = medusaOrder.items?.find(({ product_type_id }) => product_type_id === analysisPackagesType?.id);
|
const analysisPackageOrderItem = medusaOrder.items?.find(
|
||||||
const analysisItems = medusaOrder.items?.filter(({ product_type_id }) => product_type_id === analysisType?.id);
|
({ product_type_id }) => product_type_id === analysisPackagesType?.id,
|
||||||
|
);
|
||||||
|
const analysisItems = medusaOrder.items?.filter(
|
||||||
|
({ product_type_id }) => product_type_id === analysisType?.id,
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
medusaOrderId: medusaOrder.id,
|
medusaOrderId: medusaOrder.id,
|
||||||
email: medusaOrder.email,
|
email: medusaOrder.email,
|
||||||
analysisPackageOrder: analysisPackageOrderItem
|
analysisPackageOrder: analysisPackageOrderItem
|
||||||
? {
|
? {
|
||||||
partnerLocationName: analysisPackageOrderItem?.metadata?.partner_location_name as string ?? '',
|
partnerLocationName:
|
||||||
analysisPackageName: analysisPackageOrderItem?.title ?? '',
|
(analysisPackageOrderItem?.metadata
|
||||||
}
|
?.partner_location_name as string) ?? '',
|
||||||
: null,
|
analysisPackageName: analysisPackageOrderItem?.title ?? '',
|
||||||
analysisItemsOrder: Array.isArray(analysisItems) && analysisItems.length > 0
|
}
|
||||||
? analysisItems.map(({ product }) => ({
|
|
||||||
analysisName: product?.title ?? '',
|
|
||||||
analysisId: product?.metadata?.analysisIdOriginal as string ?? '',
|
|
||||||
}))
|
|
||||||
: null,
|
: null,
|
||||||
|
analysisItemsOrder:
|
||||||
|
Array.isArray(analysisItems) && analysisItems.length > 0
|
||||||
|
? analysisItems.map(({ product }) => ({
|
||||||
|
analysisName: product?.title ?? '',
|
||||||
|
analysisId: (product?.metadata?.analysisIdOriginal as string) ?? '',
|
||||||
|
}))
|
||||||
|
: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,12 +173,12 @@ async function sendAnalysisPackageOrderEmail({
|
|||||||
email,
|
email,
|
||||||
analysisPackageOrder,
|
analysisPackageOrder,
|
||||||
}: {
|
}: {
|
||||||
account: AccountWithParams,
|
account: AccountWithParams;
|
||||||
email: string,
|
email: string;
|
||||||
analysisPackageOrder: {
|
analysisPackageOrder: {
|
||||||
partnerLocationName: string,
|
partnerLocationName: string;
|
||||||
analysisPackageName: string,
|
analysisPackageName: string;
|
||||||
},
|
};
|
||||||
}) {
|
}) {
|
||||||
const { language } = await createI18nServerInstance();
|
const { language } = await createI18nServerInstance();
|
||||||
const { analysisPackageName, partnerLocationName } = analysisPackageOrder;
|
const { analysisPackageName, partnerLocationName } = analysisPackageOrder;
|
||||||
@@ -163,60 +191,114 @@ async function sendAnalysisPackageOrderEmail({
|
|||||||
language,
|
language,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to send email", error);
|
console.error('Failed to send email', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function processMontonioCallback(orderToken: string) {
|
export async function processMontonioCallback(orderToken: string) {
|
||||||
const { account } = await loadCurrentUserAccount();
|
const { account } = await loadCurrentUserAccount();
|
||||||
if (!account) {
|
if (!account) {
|
||||||
throw new Error("Account not found in context");
|
throw new Error('Account not found in context');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const decoded = await decodeOrderToken(orderToken);
|
const decoded = await decodeOrderToken(orderToken);
|
||||||
const cart = await getCartByOrderToken(decoded);
|
const cart = await getCartByOrderToken(decoded);
|
||||||
|
|
||||||
const medusaOrder = await placeOrder(cart.id, { revalidateCacheTags: false });
|
const medusaOrder = await placeOrder(cart.id, {
|
||||||
const orderedAnalysisElements = await getOrderedAnalysisIds({ medusaOrder });
|
revalidateCacheTags: false,
|
||||||
|
});
|
||||||
|
const orderedAnalysisElements = await getOrderedAnalysisIds({
|
||||||
|
medusaOrder,
|
||||||
|
});
|
||||||
|
|
||||||
|
const orderContainsSynlabItems = !!orderedAnalysisElements?.length;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const existingAnalysisOrder = await getAnalysisOrder({ medusaOrderId: medusaOrder.id });
|
const existingAnalysisOrder = await getAnalysisOrder({
|
||||||
console.info(`Analysis order already exists for medusaOrderId=${medusaOrder.id}, orderId=${existingAnalysisOrder.id}`);
|
medusaOrderId: medusaOrder.id,
|
||||||
|
});
|
||||||
|
console.info(
|
||||||
|
`Analysis order already exists for medusaOrderId=${medusaOrder.id}, orderId=${existingAnalysisOrder.id}`,
|
||||||
|
);
|
||||||
return { success: true, orderId: existingAnalysisOrder.id };
|
return { success: true, orderId: existingAnalysisOrder.id };
|
||||||
} catch {
|
} catch {
|
||||||
// ignored
|
// ignored
|
||||||
}
|
}
|
||||||
|
|
||||||
const orderId = await createAnalysisOrder({ medusaOrder, orderedAnalysisElements });
|
let orderId;
|
||||||
|
if (orderContainsSynlabItems) {
|
||||||
|
orderId = await createAnalysisOrder({
|
||||||
|
medusaOrder,
|
||||||
|
orderedAnalysisElements,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const orderResult = await getOrderResultParameters(medusaOrder);
|
const orderResult = await getOrderResultParameters(medusaOrder);
|
||||||
|
|
||||||
const { medusaOrderId, email, analysisPackageOrder, analysisItemsOrder } = orderResult;
|
const { medusaOrderId, email, analysisPackageOrder, analysisItemsOrder } =
|
||||||
|
orderResult;
|
||||||
|
|
||||||
|
const orderedTtoServices = await getOrderedTtoServices({ medusaOrder });
|
||||||
|
let bookServiceResults: {
|
||||||
|
success: boolean;
|
||||||
|
reason?: FailureReason;
|
||||||
|
serviceId?: number;
|
||||||
|
}[] = [];
|
||||||
|
if (orderedTtoServices?.length) {
|
||||||
|
const bookingPromises = orderedTtoServices.map((service) =>
|
||||||
|
bookAppointment(
|
||||||
|
service.service_id,
|
||||||
|
service.clinic_id,
|
||||||
|
service.service_user_id,
|
||||||
|
service.sync_user_id,
|
||||||
|
service.start_time,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
bookServiceResults = await Promise.all(bookingPromises);
|
||||||
|
}
|
||||||
|
|
||||||
if (email) {
|
if (email) {
|
||||||
if (analysisPackageOrder) {
|
if (analysisPackageOrder) {
|
||||||
await sendAnalysisPackageOrderEmail({ account, email, analysisPackageOrder });
|
await sendAnalysisPackageOrderEmail({
|
||||||
|
account,
|
||||||
|
email,
|
||||||
|
analysisPackageOrder,
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
console.info(`Order has no analysis package, skipping email.`);
|
console.info(`Order has no analysis package, skipping email.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (analysisItemsOrder) {
|
if (analysisItemsOrder) {
|
||||||
// @TODO send email for separate analyses
|
// @TODO send email for separate analyses
|
||||||
console.warn(`Order has analysis items, but no email template exists yet`);
|
console.warn(
|
||||||
|
`Order has analysis items, but no email template exists yet`,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
console.info(`Order has no analysis items, skipping email.`);
|
console.info(`Order has no analysis items, skipping email.`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.error("Missing email to send order result email", orderResult);
|
console.error('Missing email to send order result email', orderResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (env().isEnabledDispatchOnMontonioCallback) {
|
if (env().isEnabledDispatchOnMontonioCallback && orderContainsSynlabItems) {
|
||||||
await sendOrderToMedipost({ medusaOrderId, orderedAnalysisElements });
|
await sendOrderToMedipost({ medusaOrderId, orderedAnalysisElements });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bookServiceResults.some(({ success }) => success === false)) {
|
||||||
|
const failedServiceBookings = bookServiceResults.filter(
|
||||||
|
({ success }) => success === false,
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
failedServiceBookings,
|
||||||
|
orderId,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return { success: true, orderId };
|
return { success: true, orderId };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to place order", error);
|
console.error('Failed to place order', error);
|
||||||
throw new Error(`Failed to place order, message=${error}`);
|
throw new Error(`Failed to place order, message=${error}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,8 +29,13 @@ export default function MontonioCallbackClient({ orderToken, error }: {
|
|||||||
setHasProcessed(true);
|
setHasProcessed(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { orderId } = await processMontonioCallback(orderToken);
|
const result = await processMontonioCallback(orderToken);
|
||||||
router.push(`/home/order/${orderId}/confirmed`);
|
if (result.success) {
|
||||||
|
return router.push(`/home/order/${result.orderId}/confirmed`);
|
||||||
|
}
|
||||||
|
if (result.failedServiceBookings?.length){
|
||||||
|
router.push(`/home/cart/montonio-callback/error?reasonFailed=${result.failedServiceBookings.map(({reason}) => reason).join(',')}`);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to place order", error);
|
console.error("Failed to place order", error);
|
||||||
router.push('/home/cart/montonio-callback/error');
|
router.push('/home/cart/montonio-callback/error');
|
||||||
|
|||||||
@@ -1,11 +1,17 @@
|
|||||||
|
import { use } from 'react';
|
||||||
|
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
|
|
||||||
import { PageBody, PageHeader } from '@/packages/ui/src/makerkit/page';
|
|
||||||
import { createI18nServerInstance } from '@/lib/i18n/i18n.server';
|
import { createI18nServerInstance } from '@/lib/i18n/i18n.server';
|
||||||
import { Trans } from '@kit/ui/trans';
|
import { PageBody, PageHeader } from '@/packages/ui/src/makerkit/page';
|
||||||
|
|
||||||
|
import { Button } from '@kit/ui/button';
|
||||||
import { Alert, AlertDescription } from '@kit/ui/shadcn/alert';
|
import { Alert, AlertDescription } from '@kit/ui/shadcn/alert';
|
||||||
import { AlertTitle } from '@kit/ui/shadcn/alert';
|
import { AlertTitle } from '@kit/ui/shadcn/alert';
|
||||||
import { Button } from '@kit/ui/button';
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
|
import { FailureReason } from '~/lib/types/connected-online';
|
||||||
|
import { toArray } from '~/lib/utils';
|
||||||
|
|
||||||
export async function generateMetadata() {
|
export async function generateMetadata() {
|
||||||
const { t } = await createI18nServerInstance();
|
const { t } = await createI18nServerInstance();
|
||||||
@@ -15,7 +21,15 @@ export async function generateMetadata() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function MontonioCheckoutCallbackErrorPage() {
|
export default async function MontonioCheckoutCallbackErrorPage({
|
||||||
|
searchParams,
|
||||||
|
}: {
|
||||||
|
searchParams: Promise<{ reasonFailed: string }>;
|
||||||
|
}) {
|
||||||
|
const params = await searchParams;
|
||||||
|
|
||||||
|
const failedBookingData: string[] = toArray(params.reasonFailed?.split(','));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={'flex h-full flex-1 flex-col'}>
|
<div className={'flex h-full flex-1 flex-col'}>
|
||||||
<PageHeader title={<Trans i18nKey="cart:montonioCallback.title" />} />
|
<PageHeader title={<Trans i18nKey="cart:montonioCallback.title" />} />
|
||||||
@@ -27,9 +41,15 @@ export default async function MontonioCheckoutCallbackErrorPage() {
|
|||||||
</AlertTitle>
|
</AlertTitle>
|
||||||
|
|
||||||
<AlertDescription>
|
<AlertDescription>
|
||||||
<p>
|
{failedBookingData.length ? (
|
||||||
|
failedBookingData.map((failureReason, index) => (
|
||||||
|
<p key={index}>
|
||||||
|
<Trans i18nKey={`checkout.error.${failureReason}`} />
|
||||||
|
</p>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
<Trans i18nKey={'checkout.error.description'} />
|
<Trans i18nKey={'checkout.error.description'} />
|
||||||
</p>
|
)}
|
||||||
</AlertDescription>
|
</AlertDescription>
|
||||||
</Alert>
|
</Alert>
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,18 @@
|
|||||||
import { createI18nServerInstance } from '@/lib/i18n/i18n.server';
|
|
||||||
import { PageBody, PageHeader } from '@/packages/ui/src/makerkit/page';
|
|
||||||
|
|
||||||
import { notFound } from 'next/navigation';
|
import { notFound } from 'next/navigation';
|
||||||
|
|
||||||
|
import { createI18nServerInstance } from '@/lib/i18n/i18n.server';
|
||||||
|
import { PageBody, PageHeader } from '@/packages/ui/src/makerkit/page';
|
||||||
import { retrieveCart } from '@lib/data/cart';
|
import { retrieveCart } from '@lib/data/cart';
|
||||||
import Cart from '../../_components/cart';
|
|
||||||
import { listProductTypes } from '@lib/data/products';
|
import { listProductTypes } from '@lib/data/products';
|
||||||
import CartTimer from '../../_components/cart/cart-timer';
|
|
||||||
import { Trans } from '@kit/ui/trans';
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
|
|
||||||
|
import { findProductTypeIdByHandle } from '~/lib/utils';
|
||||||
|
import Cart from '../../_components/cart';
|
||||||
|
import CartTimer from '../../_components/cart/cart-timer';
|
||||||
|
|
||||||
export async function generateMetadata() {
|
export async function generateMetadata() {
|
||||||
const { t } = await createI18nServerInstance();
|
const { t } = await createI18nServerInstance();
|
||||||
|
|
||||||
@@ -20,34 +23,62 @@ export async function generateMetadata() {
|
|||||||
|
|
||||||
async function CartPage() {
|
async function CartPage() {
|
||||||
const cart = await retrieveCart().catch((error) => {
|
const cart = await retrieveCart().catch((error) => {
|
||||||
console.error("Failed to retrieve cart", error);
|
console.error('Failed to retrieve cart', error);
|
||||||
return notFound();
|
return notFound();
|
||||||
});
|
});
|
||||||
|
|
||||||
const { productTypes } = await listProductTypes();
|
const { productTypes } = await listProductTypes();
|
||||||
const analysisPackagesType = productTypes.find(({ metadata }) => metadata?.handle === 'analysis-packages');
|
|
||||||
const synlabAnalysisType = productTypes.find(({ metadata }) => metadata?.handle === 'synlab-analysis');
|
|
||||||
const synlabAnalyses = analysisPackagesType && synlabAnalysisType && cart?.items
|
|
||||||
? cart.items.filter((item) => {
|
|
||||||
const productTypeId = item.product?.type_id;
|
|
||||||
if (!productTypeId) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return [analysisPackagesType.id, synlabAnalysisType.id].includes(productTypeId);
|
|
||||||
})
|
|
||||||
: [];
|
|
||||||
const ttoServiceItems = cart?.items?.filter((item) => !synlabAnalyses.some((analysis) => analysis.id === item.id)) ?? [];
|
|
||||||
|
|
||||||
const otherItemsSorted = ttoServiceItems.sort((a, b) => (a.updated_at ?? "") > (b.updated_at ?? "") ? -1 : 1);
|
const synlabAnalysisTypeId = findProductTypeIdByHandle(
|
||||||
|
productTypes,
|
||||||
|
'synlab-analysis',
|
||||||
|
);
|
||||||
|
const analysisPackagesTypeId = findProductTypeIdByHandle(
|
||||||
|
productTypes,
|
||||||
|
'analysis-packages',
|
||||||
|
);
|
||||||
|
const ttoServiceTypeId = findProductTypeIdByHandle(
|
||||||
|
productTypes,
|
||||||
|
'tto-service',
|
||||||
|
);
|
||||||
|
|
||||||
|
const synlabAnalyses =
|
||||||
|
analysisPackagesTypeId && synlabAnalysisTypeId && cart?.items
|
||||||
|
? cart.items.filter((item) => {
|
||||||
|
const productTypeId = item.product?.type_id;
|
||||||
|
if (!productTypeId) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return [analysisPackagesTypeId, synlabAnalysisTypeId].includes(
|
||||||
|
productTypeId,
|
||||||
|
);
|
||||||
|
})
|
||||||
|
: [];
|
||||||
|
const ttoServiceItems =
|
||||||
|
ttoServiceTypeId && cart?.items
|
||||||
|
? cart?.items?.filter((item) => {
|
||||||
|
const productTypeId = item.product?.type_id;
|
||||||
|
return productTypeId && productTypeId === ttoServiceTypeId;
|
||||||
|
})
|
||||||
|
: [];
|
||||||
|
|
||||||
|
const otherItemsSorted = ttoServiceItems.sort((a, b) =>
|
||||||
|
(a.updated_at ?? '') > (b.updated_at ?? '') ? -1 : 1,
|
||||||
|
);
|
||||||
const item = otherItemsSorted[0];
|
const item = otherItemsSorted[0];
|
||||||
const isTimerShown = ttoServiceItems.length > 0 && !!item && !!item.updated_at;
|
const isTimerShown =
|
||||||
|
ttoServiceItems.length > 0 && !!item && !!item.updated_at;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageBody>
|
<PageBody>
|
||||||
<PageHeader title={<Trans i18nKey="cart:title" />}>
|
<PageHeader title={<Trans i18nKey="cart:title" />}>
|
||||||
{isTimerShown && <CartTimer cartItem={item} />}
|
{isTimerShown && <CartTimer cartItem={item} />}
|
||||||
</PageHeader>
|
</PageHeader>
|
||||||
<Cart cart={cart} synlabAnalyses={synlabAnalyses} ttoServiceItems={ttoServiceItems} />
|
<Cart
|
||||||
|
cart={cart}
|
||||||
|
synlabAnalyses={synlabAnalyses}
|
||||||
|
ttoServiceItems={ttoServiceItems}
|
||||||
|
/>
|
||||||
</PageBody>
|
</PageBody>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
import { redirect } from 'next/navigation';
|
import { redirect } from 'next/navigation';
|
||||||
|
|
||||||
import { listOrders } from '~/medusa/lib/data/orders';
|
|
||||||
import { createI18nServerInstance } from '@/lib/i18n/i18n.server';
|
import { createI18nServerInstance } from '@/lib/i18n/i18n.server';
|
||||||
import { listProductTypes } from '@lib/data/products';
|
import { listProductTypes } from '@lib/data/products';
|
||||||
import { PageBody } from '@kit/ui/makerkit/page';
|
|
||||||
import { pathsConfig } from '@kit/shared/config';
|
|
||||||
|
|
||||||
import { Trans } from '@kit/ui/trans';
|
|
||||||
import { HomeLayoutPageHeader } from '../../_components/home-page-header';
|
|
||||||
import { getAnalysisOrders } from '~/lib/services/order.service';
|
|
||||||
import OrderBlock from '../../_components/orders/order-block';
|
|
||||||
import React from 'react';
|
|
||||||
import { Divider } from '@medusajs/ui';
|
import { Divider } from '@medusajs/ui';
|
||||||
|
|
||||||
|
import { pathsConfig } from '@kit/shared/config';
|
||||||
|
import { PageBody } from '@kit/ui/makerkit/page';
|
||||||
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
|
import { getAnalysisOrders, getTtoOrders } from '~/lib/services/order.service';
|
||||||
|
import { findProductTypeIdByHandle } from '~/lib/utils';
|
||||||
|
import { listOrders } from '~/medusa/lib/data/orders';
|
||||||
|
|
||||||
|
import { HomeLayoutPageHeader } from '../../_components/home-page-header';
|
||||||
|
import OrderBlock from '../../_components/orders/order-block';
|
||||||
|
|
||||||
export async function generateMetadata() {
|
export async function generateMetadata() {
|
||||||
const { t } = await createI18nServerInstance();
|
const { t } = await createI18nServerInstance();
|
||||||
@@ -25,13 +29,21 @@ export async function generateMetadata() {
|
|||||||
async function OrdersPage() {
|
async function OrdersPage() {
|
||||||
const medusaOrders = await listOrders();
|
const medusaOrders = await listOrders();
|
||||||
const analysisOrders = await getAnalysisOrders();
|
const analysisOrders = await getAnalysisOrders();
|
||||||
|
const ttoOrders = await getTtoOrders();
|
||||||
const { productTypes } = await listProductTypes();
|
const { productTypes } = await listProductTypes();
|
||||||
|
|
||||||
if (!medusaOrders || !productTypes) {
|
if (!medusaOrders || !productTypes || !ttoOrders) {
|
||||||
redirect(pathsConfig.auth.signIn);
|
redirect(pathsConfig.auth.signIn);
|
||||||
}
|
}
|
||||||
|
|
||||||
const analysisPackagesType = productTypes.find(({ metadata }) => metadata?.handle === 'analysis-packages')!;
|
const analysisPackagesTypeId = findProductTypeIdByHandle(
|
||||||
|
productTypes,
|
||||||
|
'analysis-package',
|
||||||
|
);
|
||||||
|
const ttoServiceTypeId = findProductTypeIdByHandle(
|
||||||
|
productTypes,
|
||||||
|
'tto-service',
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -40,26 +52,41 @@ async function OrdersPage() {
|
|||||||
description={<Trans i18nKey={'orders:description'} />}
|
description={<Trans i18nKey={'orders:description'} />}
|
||||||
/>
|
/>
|
||||||
<PageBody>
|
<PageBody>
|
||||||
{analysisOrders.map((analysisOrder) => {
|
{medusaOrders.map((medusaOrder) => {
|
||||||
const medusaOrder = medusaOrders.find(({ id }) => id === analysisOrder.medusa_order_id);
|
const analysisOrder = analysisOrders.find(
|
||||||
|
({ medusa_order_id }) => medusa_order_id === medusaOrder.id,
|
||||||
|
);
|
||||||
if (!medusaOrder) {
|
if (!medusaOrder) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const medusaOrderItems = medusaOrder.items || [];
|
const medusaOrderItems = medusaOrder.items || [];
|
||||||
const medusaOrderItemsAnalysisPackages = medusaOrderItems.filter((item) => item.product_type_id === analysisPackagesType?.id);
|
const medusaOrderItemsAnalysisPackages = medusaOrderItems.filter(
|
||||||
const medusaOrderItemsOther = medusaOrderItems.filter((item) => item.product_type_id !== analysisPackagesType?.id);
|
(item) => item.product_type_id === analysisPackagesTypeId,
|
||||||
|
);
|
||||||
|
const medusaOrderItemsTtoServices = medusaOrderItems.filter(
|
||||||
|
(item) => item.product_type_id === ttoServiceTypeId,
|
||||||
|
);
|
||||||
|
const medusaOrderItemsOther = medusaOrderItems.filter(
|
||||||
|
(item) =>
|
||||||
|
!item.product_type_id ||
|
||||||
|
![analysisPackagesTypeId, ttoServiceTypeId].includes(
|
||||||
|
item.product_type_id,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment key={analysisOrder.id}>
|
<React.Fragment key={medusaOrder.id}>
|
||||||
<Divider className="my-6" />
|
<Divider className="my-6" />
|
||||||
<OrderBlock
|
<OrderBlock
|
||||||
|
medusaOrderId={medusaOrder.id}
|
||||||
analysisOrder={analysisOrder}
|
analysisOrder={analysisOrder}
|
||||||
itemsAnalysisPackage={medusaOrderItemsAnalysisPackages}
|
itemsAnalysisPackage={medusaOrderItemsAnalysisPackages}
|
||||||
|
itemsTtoService={medusaOrderItemsTtoServices}
|
||||||
itemsOther={medusaOrderItemsOther}
|
itemsOther={medusaOrderItemsOther}
|
||||||
/>
|
/>
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
)
|
);
|
||||||
})}
|
})}
|
||||||
{analysisOrders.length === 0 && (
|
{analysisOrders.length === 0 && (
|
||||||
<h5 className="mt-6">
|
<h5 className="mt-6">
|
||||||
|
|||||||
@@ -1,28 +1,57 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import React from 'react';
|
import { isBefore, isSameDay } from 'date-fns';
|
||||||
|
import { uniq } from 'lodash';
|
||||||
|
|
||||||
import { Calendar } from '@kit/ui/shadcn/calendar';
|
import { Calendar } from '@kit/ui/shadcn/calendar';
|
||||||
import { Card } from '@kit/ui/shadcn/card';
|
import { Card } from '@kit/ui/shadcn/card';
|
||||||
|
|
||||||
import { ServiceCategory } from '../service-categories';
|
import { ServiceCategory } from '../service-categories';
|
||||||
import { BookingProvider } from './booking.provider';
|
import { BookingProvider, useBooking } from './booking.provider';
|
||||||
import LocationSelector from './location-selector';
|
import LocationSelector from './location-selector';
|
||||||
import ServiceSelector from './service-selector';
|
import ServiceSelector from './service-selector';
|
||||||
import TimeSlots from './time-slots';
|
import TimeSlots from './time-slots';
|
||||||
|
|
||||||
|
const BookingCalendar = () => {
|
||||||
|
const { selectedDate, setSelectedDate, isLoadingTimeSlots, timeSlots } =
|
||||||
|
useBooking();
|
||||||
|
const availableDates = uniq(timeSlots?.map((timeSlot) => timeSlot.StartTime));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card className="mb-4">
|
||||||
|
<Calendar
|
||||||
|
mode="single"
|
||||||
|
selected={selectedDate}
|
||||||
|
onSelect={setSelectedDate}
|
||||||
|
disabled={(date) => {
|
||||||
|
const today = new Date();
|
||||||
|
today.setHours(0, 0, 0, 0);
|
||||||
|
return (
|
||||||
|
isBefore(date, today) ||
|
||||||
|
!availableDates.some((dateWithBooking) =>
|
||||||
|
isSameDay(date, dateWithBooking),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
className="rounded-md border"
|
||||||
|
{...(isLoadingTimeSlots && {
|
||||||
|
className: 'rounded-md border opacity-50 pointer-events-none',
|
||||||
|
})}
|
||||||
|
/>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const BookingContainer = ({ category }: { category: ServiceCategory }) => {
|
const BookingContainer = ({ category }: { category: ServiceCategory }) => {
|
||||||
return (
|
return (
|
||||||
<BookingProvider category={category}>
|
<BookingProvider category={category}>
|
||||||
<div className="flex flex-row gap-6">
|
<div className="flex max-h-full flex-row gap-6">
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
<ServiceSelector products={category.products} />
|
<ServiceSelector products={category.products} />
|
||||||
<Card className="mb-4">
|
<BookingCalendar />
|
||||||
<Calendar />
|
<LocationSelector />
|
||||||
</Card>
|
|
||||||
{/* <LocationSelector /> */}
|
|
||||||
</div>
|
</div>
|
||||||
<TimeSlots />
|
<TimeSlots countryCode={category.countryCode} />
|
||||||
</div>
|
</div>
|
||||||
</BookingProvider>
|
</BookingProvider>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,16 +3,75 @@ import { createContext } from 'react';
|
|||||||
import { StoreProduct } from '@medusajs/types';
|
import { StoreProduct } from '@medusajs/types';
|
||||||
import { noop } from 'lodash';
|
import { noop } from 'lodash';
|
||||||
|
|
||||||
|
import { Tables } from '@kit/supabase/database';
|
||||||
|
|
||||||
|
export type Location = Tables<
|
||||||
|
{ schema: 'medreport' },
|
||||||
|
'connected_online_locations'
|
||||||
|
>;
|
||||||
|
|
||||||
|
export type TimeSlotResponse = {
|
||||||
|
timeSlots: TimeSlot[];
|
||||||
|
locations: Location[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type TimeSlot = {
|
||||||
|
ClinicID: number;
|
||||||
|
LocationID: number;
|
||||||
|
UserID: number;
|
||||||
|
SyncUserID: number;
|
||||||
|
ServiceID: number;
|
||||||
|
HKServiceID: number;
|
||||||
|
StartTime: Date;
|
||||||
|
EndTime: Date;
|
||||||
|
PayorCode: string;
|
||||||
|
serviceProvider?: ServiceProvider;
|
||||||
|
syncedService?: SyncedService;
|
||||||
|
} & { location?: Location };
|
||||||
|
|
||||||
|
export type ServiceProvider = {
|
||||||
|
name: string;
|
||||||
|
id: number;
|
||||||
|
jobTitleEn: string | null;
|
||||||
|
jobTitleEt: string | null;
|
||||||
|
jobTitleRu: string | null;
|
||||||
|
clinicId: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SyncedService = Tables<
|
||||||
|
{ schema: 'medreport' },
|
||||||
|
'connected_online_services'
|
||||||
|
> & {
|
||||||
|
providerClinic: ProviderClinic;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ProviderClinic = Tables<
|
||||||
|
{ schema: 'medreport' },
|
||||||
|
'connected_online_providers'
|
||||||
|
> & { locations: Location[] };
|
||||||
|
|
||||||
const BookingContext = createContext<{
|
const BookingContext = createContext<{
|
||||||
timeSlots: string[];
|
timeSlots: TimeSlot[] | null;
|
||||||
selectedService: StoreProduct | null;
|
selectedService: StoreProduct | null;
|
||||||
setSelectedService: (selectedService: any) => void;
|
locations: Location[] | null;
|
||||||
|
selectedLocationId: number | null;
|
||||||
|
selectedDate?: Date;
|
||||||
|
isLoadingTimeSlots?: boolean;
|
||||||
|
setSelectedService: (selectedService?: StoreProduct) => void;
|
||||||
|
setSelectedLocationId: (selectedLocationId: number | null) => void;
|
||||||
updateTimeSlots: (serviceId: number) => Promise<void>;
|
updateTimeSlots: (serviceId: number) => Promise<void>;
|
||||||
|
setSelectedDate: (selectedDate?: Date) => void;
|
||||||
}>({
|
}>({
|
||||||
timeSlots: [],
|
timeSlots: null,
|
||||||
selectedService: null,
|
selectedService: null,
|
||||||
|
locations: null,
|
||||||
|
selectedLocationId: null,
|
||||||
|
selectedDate: new Date(),
|
||||||
|
isLoadingTimeSlots: false,
|
||||||
setSelectedService: (_) => _,
|
setSelectedService: (_) => _,
|
||||||
|
setSelectedLocationId: (_) => _,
|
||||||
updateTimeSlots: async (_) => noop(),
|
updateTimeSlots: async (_) => noop(),
|
||||||
|
setSelectedDate: (_) => _,
|
||||||
});
|
});
|
||||||
|
|
||||||
export { BookingContext };
|
export { BookingContext };
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useContext, useEffect, useState } from 'react';
|
||||||
|
|
||||||
import { StoreProduct } from '@medusajs/types';
|
import { StoreProduct } from '@medusajs/types';
|
||||||
|
|
||||||
import { getAvailableAppointmentsForService } from '~/lib/services/connected-online.service';
|
import { getAvailableTimeSlotsForDisplay } from '~/lib/services/connected-online.service';
|
||||||
|
|
||||||
import { ServiceCategory } from '../service-categories';
|
import { ServiceCategory } from '../service-categories';
|
||||||
import { BookingContext } from './booking.context';
|
import { BookingContext, Location, TimeSlot } from './booking.context';
|
||||||
|
|
||||||
export function useBooking() {
|
export function useBooking() {
|
||||||
const context = React.useContext(BookingContext);
|
const context = useContext(BookingContext);
|
||||||
|
|
||||||
if (!context) {
|
if (!context) {
|
||||||
throw new Error('useBooking must be used within a BookingProvider.');
|
throw new Error('useBooking must be used within a BookingProvider.');
|
||||||
@@ -24,21 +24,54 @@ export const BookingProvider: React.FC<{
|
|||||||
const [selectedService, setSelectedService] = useState<StoreProduct | null>(
|
const [selectedService, setSelectedService] = useState<StoreProduct | null>(
|
||||||
category.products[0] || null,
|
category.products[0] || null,
|
||||||
);
|
);
|
||||||
const [timeSlots, setTimeSlots] = useState<string[]>([]);
|
const [selectedLocationId, setSelectedLocationId] = useState<number | null>(
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
const [selectedDate, setSelectedDate] = useState<Date>();
|
||||||
|
const [timeSlots, setTimeSlots] = useState<TimeSlot[] | null>(null);
|
||||||
|
const [locations, setLocations] = useState<Location[] | null>(null);
|
||||||
|
const [isLoadingTimeSlots, setIsLoadingTimeSlots] = useState<boolean>(false);
|
||||||
|
|
||||||
const updateTimeSlots = async (serviceId: number) => {
|
useEffect(() => {
|
||||||
const response = await getAvailableAppointmentsForService(serviceId);
|
let metadataServiceIds = [];
|
||||||
console.log('updateTimeSlots response', response);
|
try {
|
||||||
// Fetch time slots based on the selected service ID
|
metadataServiceIds = JSON.parse(
|
||||||
|
selectedService?.metadata?.serviceIds as string,
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (metadataServiceIds.length) {
|
||||||
|
updateTimeSlots(metadataServiceIds);
|
||||||
|
}
|
||||||
|
}, [selectedService?.metadata?.serviceIds, selectedLocationId]);
|
||||||
|
|
||||||
|
const updateTimeSlots = async (serviceIds: number[]) => {
|
||||||
|
setIsLoadingTimeSlots(true);
|
||||||
|
try {
|
||||||
|
const response = await getAvailableTimeSlotsForDisplay(serviceIds, selectedLocationId);
|
||||||
|
setTimeSlots(response.timeSlots);
|
||||||
|
setLocations(response.locations)
|
||||||
|
} catch (error) {
|
||||||
|
setTimeSlots(null);
|
||||||
|
} finally {
|
||||||
|
setIsLoadingTimeSlots(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BookingContext.Provider
|
<BookingContext.Provider
|
||||||
value={{
|
value={{
|
||||||
timeSlots,
|
timeSlots,
|
||||||
|
locations,
|
||||||
selectedService,
|
selectedService,
|
||||||
|
selectedLocationId,
|
||||||
|
setSelectedLocationId,
|
||||||
|
selectedDate,
|
||||||
|
isLoadingTimeSlots,
|
||||||
setSelectedService,
|
setSelectedService,
|
||||||
updateTimeSlots,
|
updateTimeSlots,
|
||||||
|
setSelectedDate,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
@@ -1,9 +1,60 @@
|
|||||||
import React from 'react';
|
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';
|
import { Card } from '@kit/ui/shadcn/card';
|
||||||
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
|
import { useBooking } from './booking.provider';
|
||||||
|
|
||||||
const LocationSelector = () => {
|
const LocationSelector = () => {
|
||||||
return <Card className="p-4">LocationSelector</Card>;
|
const { t } = useTranslation();
|
||||||
|
const {
|
||||||
|
selectedService,
|
||||||
|
selectedLocationId,
|
||||||
|
setSelectedLocationId,
|
||||||
|
locations,
|
||||||
|
} = useBooking();
|
||||||
|
|
||||||
|
const onLocationSelect = (locationId: number | string | null) => {
|
||||||
|
if (locationId === 'all') return setSelectedLocationId(null);
|
||||||
|
setSelectedLocationId(Number(locationId));
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card className="mb-4 p-4">
|
||||||
|
<h5 className="text-semibold mb-2">
|
||||||
|
<Trans i18nKey="booking:locations" />
|
||||||
|
</h5>
|
||||||
|
<div className="flex flex-col">
|
||||||
|
<RadioGroup
|
||||||
|
className="mb-2 flex flex-col"
|
||||||
|
onValueChange={(val) => onLocationSelect(val)}
|
||||||
|
>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<RadioGroupItem
|
||||||
|
value={'all'}
|
||||||
|
id={'all'}
|
||||||
|
checked={selectedLocationId === null}
|
||||||
|
/>
|
||||||
|
<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}
|
||||||
|
/>
|
||||||
|
<Label htmlFor={location.sync_id.toString()}>
|
||||||
|
{location.name}
|
||||||
|
</Label>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</RadioGroup>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default LocationSelector;
|
export default LocationSelector;
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import React, { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
|
||||||
import { StoreProduct } from '@medusajs/types';
|
import { StoreProduct } from '@medusajs/types';
|
||||||
import { ArrowUp, ChevronDown } from 'lucide-react';
|
import { ChevronDown } from 'lucide-react';
|
||||||
|
|
||||||
import { Button } from '@kit/ui/shadcn/button';
|
|
||||||
import { Card } from '@kit/ui/shadcn/card';
|
import { Card } from '@kit/ui/shadcn/card';
|
||||||
import { Label } from '@kit/ui/shadcn/label';
|
import { Label } from '@kit/ui/shadcn/label';
|
||||||
import {
|
import {
|
||||||
@@ -12,27 +11,26 @@ import {
|
|||||||
PopoverTrigger,
|
PopoverTrigger,
|
||||||
} from '@kit/ui/shadcn/popover';
|
} from '@kit/ui/shadcn/popover';
|
||||||
import { RadioGroup, RadioGroupItem } from '@kit/ui/shadcn/radio-group';
|
import { RadioGroup, RadioGroupItem } from '@kit/ui/shadcn/radio-group';
|
||||||
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
import { useBooking } from './booking.provider';
|
import { useBooking } from './booking.provider';
|
||||||
|
|
||||||
const ServiceSelector = ({ products }: { products: StoreProduct[] }) => {
|
const ServiceSelector = ({ products }: { products: StoreProduct[] }) => {
|
||||||
const { selectedService, setSelectedService, updateTimeSlots } = useBooking();
|
const { selectedService, setSelectedService } = useBooking();
|
||||||
const [collapsed, setCollapsed] = React.useState(false);
|
const [collapsed, setCollapsed] = useState(false);
|
||||||
const [firstFourProducts, setFirstFourProducts] = useState<StoreProduct[]>(
|
const [firstFourProducts] = useState<StoreProduct[]>(products.slice(0, 4));
|
||||||
products.slice(0, 4),
|
|
||||||
);
|
|
||||||
|
|
||||||
const onServiceSelect = async (productId: StoreProduct['id']) => {
|
const onServiceSelect = async (productId: StoreProduct['id']) => {
|
||||||
const product = products.find((p) => p.id === productId);
|
const product = products.find((p) => p.id === productId);
|
||||||
setSelectedService(product);
|
setSelectedService(product);
|
||||||
setCollapsed(false);
|
setCollapsed(false);
|
||||||
await updateTimeSlots((product!.metadata!.serviceId as number) || 0);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('selectedService', selectedService);
|
|
||||||
return (
|
return (
|
||||||
<Card className="mb-4 p-4">
|
<Card className="mb-4 p-4">
|
||||||
<h5 className="text-semibold mb-2">Teenused</h5>
|
<h5 className="text-semibold mb-2">
|
||||||
|
<Trans i18nKey="booking:services" />
|
||||||
|
</h5>
|
||||||
<Popover open={collapsed} onOpenChange={setCollapsed}>
|
<Popover open={collapsed} onOpenChange={setCollapsed}>
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
<RadioGroup
|
<RadioGroup
|
||||||
@@ -56,7 +54,9 @@ const ServiceSelector = ({ products }: { products: StoreProduct[] }) => {
|
|||||||
onClick={() => setCollapsed((_) => !_)}
|
onClick={() => setCollapsed((_) => !_)}
|
||||||
className="flex cursor-pointer items-center justify-between border-t py-1"
|
className="flex cursor-pointer items-center justify-between border-t py-1"
|
||||||
>
|
>
|
||||||
<span>Kuva kõik</span>
|
<span>
|
||||||
|
<Trans i18nKey="booking:showAll" />
|
||||||
|
</span>
|
||||||
<ChevronDown />
|
<ChevronDown />
|
||||||
</div>
|
</div>
|
||||||
</PopoverTrigger>
|
</PopoverTrigger>
|
||||||
|
|||||||
@@ -1,94 +1,257 @@
|
|||||||
import React from 'react';
|
import { useMemo, useState } from 'react';
|
||||||
|
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
|
||||||
import { formatCurrency } from '@/packages/shared/src/utils';
|
import { formatCurrency } from '@/packages/shared/src/utils';
|
||||||
import { format } from 'date-fns';
|
import { addHours, isAfter, isSameDay } from 'date-fns';
|
||||||
|
import { orderBy } from 'lodash';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
|
import { pathsConfig } from '@kit/shared/config';
|
||||||
|
import { formatDateAndTime } from '@kit/shared/utils';
|
||||||
import { Button } from '@kit/ui/shadcn/button';
|
import { Button } from '@kit/ui/shadcn/button';
|
||||||
import { Card } from '@kit/ui/shadcn/card';
|
import { Card } from '@kit/ui/shadcn/card';
|
||||||
|
import { toast } from '@kit/ui/sonner';
|
||||||
import { Trans } from '@kit/ui/trans';
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
import { cn } from '@kit/ui/utils';
|
||||||
|
|
||||||
import { AvailableAppointmentsResponse } from '~/lib/types/connected-online';
|
import { createInitialReservationAction } from '../../_lib/server/actions';
|
||||||
|
import { ServiceProvider, TimeSlot } from './booking.context';
|
||||||
|
import { useBooking } from './booking.provider';
|
||||||
|
|
||||||
const dummyData: AvailableAppointmentsResponse['Data']['T_Booking'] = [
|
const getServiceProviderTitle = (
|
||||||
{
|
currentLocale: string,
|
||||||
ServiceID: 1,
|
serviceProvider?: ServiceProvider,
|
||||||
StartTime: new Date('2024-10-10T10:00:00Z'),
|
) => {
|
||||||
EndTime: new Date('2024-10-10T11:00:00Z'),
|
if (!serviceProvider) return null;
|
||||||
HKServiceID: 0,
|
if (currentLocale === 'en') return serviceProvider.jobTitleEn;
|
||||||
ClinicID: '',
|
if (currentLocale === 'ru') return serviceProvider.jobTitleRu;
|
||||||
LocationID: 0,
|
|
||||||
UserID: 0,
|
return serviceProvider.jobTitleEt;
|
||||||
SyncUserID: 0,
|
};
|
||||||
PayorCode: '',
|
|
||||||
},
|
const PAGE_SIZE = 7;
|
||||||
{
|
|
||||||
ServiceID: 1,
|
const TimeSlots = ({ countryCode }: { countryCode: string }) => {
|
||||||
StartTime: new Date('2024-10-10T11:00:00Z'),
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
EndTime: new Date('2024-10-10T12:00:00Z'),
|
|
||||||
HKServiceID: 0,
|
const {
|
||||||
ClinicID: '',
|
t,
|
||||||
LocationID: 0,
|
i18n: { language: currentLocale },
|
||||||
UserID: 0,
|
} = useTranslation();
|
||||||
SyncUserID: 0,
|
|
||||||
PayorCode: '',
|
const booking = useBooking();
|
||||||
},
|
|
||||||
{
|
const router = useRouter();
|
||||||
ServiceID: 2,
|
|
||||||
StartTime: new Date('2024-10-10T12:00:00Z'),
|
const selectedDate = booking.selectedDate ?? new Date();
|
||||||
EndTime: new Date('2024-10-10T13:00:00Z'),
|
|
||||||
HKServiceID: 0,
|
const filteredBookings = useMemo(
|
||||||
ClinicID: '',
|
() =>
|
||||||
LocationID: 0,
|
orderBy(
|
||||||
UserID: 0,
|
booking?.timeSlots?.filter(({ StartTime }) => {
|
||||||
SyncUserID: 0,
|
const firstAvailableTimeToSelect = isSameDay(selectedDate, new Date())
|
||||||
PayorCode: '',
|
? addHours(new Date(), 0.5)
|
||||||
},
|
: selectedDate;
|
||||||
];
|
return isAfter(StartTime, firstAvailableTimeToSelect);
|
||||||
|
}) ?? [],
|
||||||
|
'StartTime',
|
||||||
|
'asc',
|
||||||
|
),
|
||||||
|
[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;
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleBookTime = async (timeSlot: TimeSlot, comments?: string) => {
|
||||||
|
const selectedService = booking.selectedService;
|
||||||
|
|
||||||
|
const selectedVariant = selectedService?.variants?.[0];
|
||||||
|
|
||||||
|
const syncedService = timeSlot.syncedService;
|
||||||
|
if (!syncedService || !selectedVariant) {
|
||||||
|
return toast.error(t('booking:serviceNotFound'));
|
||||||
|
}
|
||||||
|
|
||||||
|
const bookTimePromise = createInitialReservationAction(
|
||||||
|
selectedVariant,
|
||||||
|
countryCode,
|
||||||
|
Number(syncedService.id),
|
||||||
|
syncedService?.clinic_id,
|
||||||
|
timeSlot.UserID,
|
||||||
|
timeSlot.SyncUserID,
|
||||||
|
timeSlot.StartTime,
|
||||||
|
booking.selectedLocationId ? booking.selectedLocationId : null,
|
||||||
|
comments,
|
||||||
|
).then(() => {
|
||||||
|
router.push(pathsConfig.app.cart);
|
||||||
|
});
|
||||||
|
|
||||||
|
toast.promise(() => bookTimePromise, {
|
||||||
|
success: <Trans i18nKey={'booking:bookTimeSuccess'} />,
|
||||||
|
error: <Trans i18nKey={'booking:bookTimeError'} />,
|
||||||
|
loading: <Trans i18nKey={'booking:bookTimeLoading'} />,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const TimeSlots = () => {
|
|
||||||
return (
|
return (
|
||||||
<div className="flex w-full flex-col gap-2">
|
<div className="flex w-full flex-col gap-4">
|
||||||
{dummyData.map((data) => (
|
<div className="flex h-full w-full flex-col gap-2 overflow-auto">
|
||||||
<Card
|
{paginatedBookings.map((timeSlot, index) => {
|
||||||
className="flex justify-between p-4"
|
const isEHIF = timeSlot.HKServiceID > 0;
|
||||||
key={data.ServiceID + '-time-slot'}
|
const serviceProviderTitle = getServiceProviderTitle(
|
||||||
>
|
currentLocale,
|
||||||
<div>
|
timeSlot.serviceProvider,
|
||||||
<span>{format(data.StartTime.toString(), 'HH:mm')}</span>
|
);
|
||||||
<div className="flex">
|
const price =
|
||||||
<h5 className="after:mx-2 after:content-['·']">
|
booking.selectedService?.variants?.[0]?.calculated_price
|
||||||
Dr. Jüri Mardikas
|
?.calculated_amount;
|
||||||
</h5>
|
return (
|
||||||
<span className="after:mx-2 after:content-['·']">Kardioloog</span>
|
<Card className="flex justify-between p-4" key={index}>
|
||||||
<span>Tervisekassa aeg</span>
|
<div>
|
||||||
</div>
|
<span>{formatDateAndTime(timeSlot.StartTime.toString())}</span>
|
||||||
<div className="flex text-xs">
|
<div className="flex">
|
||||||
<span className="after:mx-2 after:content-['·']">
|
<h5
|
||||||
Ülemiste Tervisemaja 2
|
className={cn(
|
||||||
</span>
|
(serviceProviderTitle || isEHIF) &&
|
||||||
<span className="after:mx-2 after:content-['·']">
|
"after:mx-2 after:content-['·']",
|
||||||
Ülemiste füsioteraapiakliinik
|
)}
|
||||||
</span>
|
>
|
||||||
<span className="after:mx-2 after:content-['·']">
|
{timeSlot.serviceProvider?.name}
|
||||||
Sepapaja 2/1
|
</h5>
|
||||||
</span>
|
{serviceProviderTitle && (
|
||||||
<span>Tallinn</span>
|
<span
|
||||||
</div>
|
className={cn(isEHIF && "after:mx-2 after:content-['·']")}
|
||||||
|
>
|
||||||
|
{serviceProviderTitle}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
{isEHIF && <span>{t('booking:ehifBooking')}</span>}
|
||||||
|
</div>
|
||||||
|
<div className="flex text-xs">
|
||||||
|
{timeSlot.location?.address}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="flex-end flex items-center justify-center gap-2">
|
||||||
|
<span className="text-sm font-semibold">
|
||||||
|
{formatCurrency({
|
||||||
|
currencyCode: 'EUR',
|
||||||
|
locale: 'et-EE',
|
||||||
|
value: price ?? '',
|
||||||
|
})}
|
||||||
|
</span>
|
||||||
|
<Button onClick={() => handleBookTime(timeSlot)} size="sm">
|
||||||
|
<Trans i18nKey="common:book" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</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>
|
||||||
<div className="flex-end flex items-center justify-center gap-2">
|
)}
|
||||||
<span className="text-sm font-semibold">
|
</div>
|
||||||
{formatCurrency({
|
|
||||||
currencyCode: 'EUR',
|
{totalPages > 1 && (
|
||||||
locale: 'et-EE',
|
<div className="flex items-center justify-between">
|
||||||
value: 20,
|
<div className="text-muted-foreground text-sm">
|
||||||
})}
|
{t('common:pageOfPages', {
|
||||||
</span>
|
page: currentPage,
|
||||||
<Button>
|
total: totalPages,
|
||||||
<Trans i18nKey="Broneeri" />
|
})}
|
||||||
|
</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>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</div>
|
||||||
))}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -101,7 +101,6 @@ export default function OrderAnalysesCards({
|
|||||||
{title}
|
{title}
|
||||||
{description && (
|
{description && (
|
||||||
<>
|
<>
|
||||||
{' '}
|
|
||||||
<InfoTooltip
|
<InfoTooltip
|
||||||
content={
|
content={
|
||||||
<div className='flex flex-col gap-2'>
|
<div className='flex flex-col gap-2'>
|
||||||
|
|||||||
@@ -5,17 +5,19 @@ import OrderItemsTable from "./order-items-table";
|
|||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { Eye } from "lucide-react";
|
import { Eye } from "lucide-react";
|
||||||
|
|
||||||
export default function OrderBlock({ analysisOrder, itemsAnalysisPackage, itemsOther }: {
|
export default function OrderBlock({ analysisOrder, itemsAnalysisPackage, itemsTtoService, itemsOther, medusaOrderId }: {
|
||||||
analysisOrder: AnalysisOrder,
|
analysisOrder?: AnalysisOrder,
|
||||||
itemsAnalysisPackage: StoreOrderLineItem[],
|
itemsAnalysisPackage: StoreOrderLineItem[],
|
||||||
|
itemsTtoService: StoreOrderLineItem[],
|
||||||
itemsOther: StoreOrderLineItem[],
|
itemsOther: StoreOrderLineItem[],
|
||||||
|
medusaOrderId: string,
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
<h4>
|
<h4>
|
||||||
<Trans i18nKey="analysis-results:orderTitle" values={{ orderNumber: analysisOrder.medusa_order_id }} />
|
<Trans i18nKey="analysis-results:orderTitle" values={{ orderNumber: medusaOrderId }} />
|
||||||
</h4>
|
</h4>
|
||||||
<div className="flex gap-2">
|
{analysisOrder && <div className="flex gap-2">
|
||||||
<h5>
|
<h5>
|
||||||
<Trans i18nKey={`orders:status.${analysisOrder.status}`} />
|
<Trans i18nKey={`orders:status.${analysisOrder.status}`} />
|
||||||
</h5>
|
</h5>
|
||||||
@@ -26,9 +28,10 @@ export default function OrderBlock({ analysisOrder, itemsAnalysisPackage, itemsO
|
|||||||
<Eye />
|
<Eye />
|
||||||
</button>
|
</button>
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>}
|
||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
<OrderItemsTable items={itemsAnalysisPackage} title="orders:table.analysisPackage" analysisOrder={analysisOrder} />
|
{analysisOrder && <OrderItemsTable items={itemsAnalysisPackage} title="orders:table.analysisPackage" analysisOrder={analysisOrder} />}
|
||||||
|
{itemsTtoService && <OrderItemsTable items={itemsTtoService} title="orders:table.ttoService" type='ttoService' />}
|
||||||
<OrderItemsTable items={itemsOther} title="orders:table.otherOrders" analysisOrder={analysisOrder} />
|
<OrderItemsTable items={itemsOther} title="orders:table.otherOrders" analysisOrder={analysisOrder} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import { useRouter } from 'next/navigation';
|
|||||||
|
|
||||||
import { StoreOrderLineItem } from '@medusajs/types';
|
import { StoreOrderLineItem } from '@medusajs/types';
|
||||||
import { formatDate } from 'date-fns';
|
import { formatDate } from 'date-fns';
|
||||||
import { Eye } from 'lucide-react';
|
|
||||||
|
|
||||||
import { pathsConfig } from '@kit/shared/config';
|
import { pathsConfig } from '@kit/shared/config';
|
||||||
import { Button } from '@kit/ui/button';
|
import { Button } from '@kit/ui/button';
|
||||||
@@ -22,14 +21,18 @@ import { AnalysisOrder } from '~/lib/services/order.service';
|
|||||||
|
|
||||||
import { logAnalysisResultsNavigateAction } from './actions';
|
import { logAnalysisResultsNavigateAction } from './actions';
|
||||||
|
|
||||||
|
export type OrderItemType = 'analysisOrder' | 'ttoService';
|
||||||
|
|
||||||
export default function OrderItemsTable({
|
export default function OrderItemsTable({
|
||||||
items,
|
items,
|
||||||
title,
|
title,
|
||||||
analysisOrder,
|
analysisOrder,
|
||||||
|
type = 'analysisOrder',
|
||||||
}: {
|
}: {
|
||||||
items: StoreOrderLineItem[];
|
items: StoreOrderLineItem[];
|
||||||
title: string;
|
title: string;
|
||||||
analysisOrder: AnalysisOrder;
|
analysisOrder?: AnalysisOrder;
|
||||||
|
type?: OrderItemType;
|
||||||
}) {
|
}) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
@@ -37,9 +40,13 @@ export default function OrderItemsTable({
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isAnalysisOrder = type === 'analysisOrder';
|
||||||
|
|
||||||
const openAnalysisResults = async () => {
|
const openAnalysisResults = async () => {
|
||||||
await logAnalysisResultsNavigateAction(analysisOrder.medusa_order_id);
|
if (analysisOrder) {
|
||||||
router.push(`${pathsConfig.app.analysisResults}/${analysisOrder.id}`);
|
await logAnalysisResultsNavigateAction(analysisOrder.medusa_order_id);
|
||||||
|
router.push(`${pathsConfig.app.analysisResults}/${analysisOrder.id}`);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -52,10 +59,10 @@ export default function OrderItemsTable({
|
|||||||
<TableHead className="px-6">
|
<TableHead className="px-6">
|
||||||
<Trans i18nKey="orders:table.createdAt" />
|
<Trans i18nKey="orders:table.createdAt" />
|
||||||
</TableHead>
|
</TableHead>
|
||||||
<TableHead className="px-6">
|
<TableHead className={'px-6'}>
|
||||||
<Trans i18nKey="orders:table.status" />
|
<Trans i18nKey="orders:table.status" />
|
||||||
</TableHead>
|
</TableHead>
|
||||||
<TableHead className="px-6"></TableHead>
|
{isAnalysisOrder && <TableHead className="px-6"></TableHead>}
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
@@ -65,7 +72,7 @@ export default function OrderItemsTable({
|
|||||||
)
|
)
|
||||||
.map((orderItem) => (
|
.map((orderItem) => (
|
||||||
<TableRow className="w-full" key={orderItem.id}>
|
<TableRow className="w-full" key={orderItem.id}>
|
||||||
<TableCell className="text-left w-[100%] px-6">
|
<TableCell className="w-[100%] px-6 text-left">
|
||||||
<p className="txt-medium-plus text-ui-fg-base">
|
<p className="txt-medium-plus text-ui-fg-base">
|
||||||
{orderItem.product_title}
|
{orderItem.product_title}
|
||||||
</p>
|
</p>
|
||||||
@@ -76,14 +83,18 @@ export default function OrderItemsTable({
|
|||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
<TableCell className="min-w-[180px] px-6">
|
<TableCell className="min-w-[180px] px-6">
|
||||||
<Trans i18nKey={`orders:status.${analysisOrder.status}`} />
|
<Trans
|
||||||
|
i18nKey={`orders:status.${type}.${analysisOrder?.status ?? 'CONFIRMED'}`}
|
||||||
|
/>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
<TableCell className="px-6 text-right">
|
{isAnalysisOrder && (
|
||||||
<Button size="sm" onClick={openAnalysisResults}>
|
<TableCell className="px-6 text-right">
|
||||||
<Trans i18nKey="analysis-results:view" />
|
<Button size="sm" onClick={openAnalysisResults}>
|
||||||
</Button>
|
<Trans i18nKey="analysis-results:view" />
|
||||||
</TableCell>
|
</Button>
|
||||||
|
</TableCell>
|
||||||
|
)}
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ export interface ServiceCategory {
|
|||||||
color: string;
|
color: string;
|
||||||
description: string;
|
description: string;
|
||||||
products: StoreProduct[];
|
products: StoreProduct[];
|
||||||
|
countryCode: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ServiceCategories = ({
|
const ServiceCategories = ({
|
||||||
|
|||||||
65
app/home/(user)/_lib/server/actions.ts
Normal file
65
app/home/(user)/_lib/server/actions.ts
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
'use server';
|
||||||
|
|
||||||
|
import { StoreProductVariant } from '@medusajs/types';
|
||||||
|
|
||||||
|
import {
|
||||||
|
bookAppointment,
|
||||||
|
createInitialReservation,
|
||||||
|
} from '~/lib/services/connected-online.service';
|
||||||
|
import { handleAddToCart } from '~/lib/services/medusaCart.service';
|
||||||
|
|
||||||
|
import { updateLineItem } from '../../../../../packages/features/medusa-storefront/src/lib/data';
|
||||||
|
|
||||||
|
export async function bookTimeAction(
|
||||||
|
serviceId: number,
|
||||||
|
clinicId: number,
|
||||||
|
appointmentUserId: number,
|
||||||
|
syncUserId: number,
|
||||||
|
startTime: Date,
|
||||||
|
comments?: string,
|
||||||
|
) {
|
||||||
|
return bookAppointment(
|
||||||
|
serviceId,
|
||||||
|
clinicId,
|
||||||
|
appointmentUserId,
|
||||||
|
syncUserId,
|
||||||
|
startTime,
|
||||||
|
comments,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createInitialReservationAction(
|
||||||
|
selectedVariant: Pick<StoreProductVariant, 'id'>,
|
||||||
|
countryCode: string,
|
||||||
|
serviceId: number,
|
||||||
|
clinicId: number,
|
||||||
|
appointmentUserId: number,
|
||||||
|
syncUserId: number,
|
||||||
|
startTime: Date,
|
||||||
|
locationId: number | null,
|
||||||
|
comments?: string,
|
||||||
|
) {
|
||||||
|
const { addedItem } = await handleAddToCart({
|
||||||
|
selectedVariant,
|
||||||
|
countryCode,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (addedItem) {
|
||||||
|
const reservation = await createInitialReservation(
|
||||||
|
serviceId,
|
||||||
|
clinicId,
|
||||||
|
appointmentUserId,
|
||||||
|
syncUserId,
|
||||||
|
startTime,
|
||||||
|
addedItem.id,
|
||||||
|
locationId,
|
||||||
|
comments,
|
||||||
|
);
|
||||||
|
|
||||||
|
await updateLineItem({
|
||||||
|
lineId: addedItem.id,
|
||||||
|
quantity: addedItem.quantity,
|
||||||
|
metadata: { connectedOnlineReservationId: reservation.id },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -45,10 +45,6 @@ async function analysesLoader() {
|
|||||||
})
|
})
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
const serviceCategories = productCategories.filter(
|
|
||||||
({ parent_category }) => parent_category?.handle === 'tto-categories',
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
analyses:
|
analyses:
|
||||||
categoryProducts?.response.products
|
categoryProducts?.response.products
|
||||||
|
|||||||
@@ -1,20 +1,30 @@
|
|||||||
import { cache } from 'react';
|
import { cache } from 'react';
|
||||||
|
|
||||||
import { getProductCategories } from '@lib/data';
|
import { getProductCategories, listProducts } from '@lib/data';
|
||||||
|
|
||||||
import { ServiceCategory } from '../../_components/service-categories';
|
import { loadCountryCodes } from './load-analyses';
|
||||||
|
|
||||||
async function categoryLoader({
|
|
||||||
handle,
|
|
||||||
}: {
|
|
||||||
handle: string;
|
|
||||||
}): Promise<{ category: ServiceCategory | null }> {
|
|
||||||
const response = await getProductCategories({
|
|
||||||
handle,
|
|
||||||
fields: '*products, is_active, metadata',
|
|
||||||
});
|
|
||||||
|
|
||||||
|
async function categoryLoader({ handle }: { handle: string }) {
|
||||||
|
const [response, countryCodes] = await Promise.all([
|
||||||
|
getProductCategories({
|
||||||
|
handle,
|
||||||
|
limit: 1,
|
||||||
|
}),
|
||||||
|
loadCountryCodes(),
|
||||||
|
]);
|
||||||
const category = response.product_categories[0];
|
const category = response.product_categories[0];
|
||||||
|
const countryCode = countryCodes[0]!;
|
||||||
|
|
||||||
|
if (!response.product_categories?.[0]?.id) {
|
||||||
|
return { category: null };
|
||||||
|
}
|
||||||
|
|
||||||
|
const {
|
||||||
|
response: { products: categoryProducts },
|
||||||
|
} = await listProducts({
|
||||||
|
countryCode,
|
||||||
|
queryParams: { limit: 100, category_id: response.product_categories[0].id },
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
category: {
|
category: {
|
||||||
@@ -25,7 +35,8 @@ async function categoryLoader({
|
|||||||
description: category?.description || '',
|
description: category?.description || '',
|
||||||
handle: category?.handle || '',
|
handle: category?.handle || '',
|
||||||
name: category?.name || '',
|
name: category?.name || '',
|
||||||
products: category?.products || [],
|
countryCode,
|
||||||
|
products: categoryProducts,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,38 +10,36 @@ async function ttoServicesLoader() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const heroCategories = response.product_categories?.filter(
|
const heroCategories = response.product_categories?.filter(
|
||||||
({ parent_category, is_active, metadata }) =>
|
({ parent_category, metadata }) =>
|
||||||
parent_category?.handle === 'tto-categories' &&
|
parent_category?.handle === 'tto-categories' && metadata?.isHero,
|
||||||
is_active &&
|
|
||||||
metadata?.isHero,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const ttoCategories = response.product_categories?.filter(
|
const ttoCategories = response.product_categories?.filter(
|
||||||
({ parent_category, is_active, metadata }) =>
|
({ parent_category, metadata }) =>
|
||||||
parent_category?.handle === 'tto-categories' &&
|
parent_category?.handle === 'tto-categories' && !metadata?.isHero,
|
||||||
is_active &&
|
|
||||||
!metadata?.isHero,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
heroCategories:
|
heroCategories:
|
||||||
heroCategories.map<ServiceCategory>(
|
heroCategories.map<Omit<ServiceCategory, 'countryCode'>>(
|
||||||
({ name, handle, metadata, description }) => ({
|
({ name, handle, metadata, description, products }) => ({
|
||||||
name,
|
name,
|
||||||
handle,
|
handle,
|
||||||
color:
|
color:
|
||||||
typeof metadata?.color === 'string' ? metadata.color : 'primary',
|
typeof metadata?.color === 'string' ? metadata.color : 'primary',
|
||||||
description,
|
description,
|
||||||
|
products: products ?? [],
|
||||||
}),
|
}),
|
||||||
) ?? [],
|
) ?? [],
|
||||||
ttoCategories:
|
ttoCategories:
|
||||||
ttoCategories.map<ServiceCategory>(
|
ttoCategories.map<Omit<ServiceCategory, 'countryCode'>>(
|
||||||
({ name, handle, metadata, description }) => ({
|
({ name, handle, metadata, description, products }) => ({
|
||||||
name,
|
name,
|
||||||
handle,
|
handle,
|
||||||
color:
|
color:
|
||||||
typeof metadata?.color === 'string' ? metadata.color : 'primary',
|
typeof metadata?.color === 'string' ? metadata.color : 'primary',
|
||||||
description,
|
description,
|
||||||
|
products: products ?? [],
|
||||||
}),
|
}),
|
||||||
) ?? [],
|
) ?? [],
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
'use server'
|
'use server';
|
||||||
|
|
||||||
import { RequestStatus } from '@/lib/types/audit';
|
import { RequestStatus, SyncStatus } from '@/lib/types/audit';
|
||||||
import { ConnectedOnlineMethodName } from '@/lib/types/connected-online';
|
import { ConnectedOnlineMethodName } from '@/lib/types/connected-online';
|
||||||
import { ExternalApi } from '@/lib/types/external';
|
import { ExternalApi } from '@/lib/types/external';
|
||||||
import { MedipostAction } from '@/lib/types/medipost';
|
import { MedipostAction } from '@/lib/types/medipost';
|
||||||
import { getSupabaseServerAdminClient } from '@/packages/supabase/src/clients/server-admin-client';
|
import { getSupabaseServerAdminClient } from '@/packages/supabase/src/clients/server-admin-client';
|
||||||
import { getSupabaseServerClient } from '@/packages/supabase/src/clients/server-client';
|
|
||||||
|
|
||||||
export default async function logRequestResult(
|
export default async function logRequestResult(
|
||||||
/* personalCode: string, */ requestApi: keyof typeof ExternalApi,
|
requestApi: keyof typeof ExternalApi,
|
||||||
requestApiMethod: `${ConnectedOnlineMethodName}` | `${MedipostAction}`,
|
requestApiMethod: `${ConnectedOnlineMethodName}` | `${MedipostAction}`,
|
||||||
status: RequestStatus,
|
status: RequestStatus,
|
||||||
comment?: string,
|
comment?: string,
|
||||||
@@ -16,11 +16,10 @@ export default async function logRequestResult(
|
|||||||
serviceId?: number,
|
serviceId?: number,
|
||||||
serviceProviderId?: number,
|
serviceProviderId?: number,
|
||||||
) {
|
) {
|
||||||
const { error } = await getSupabaseServerClient()
|
const { error } = await getSupabaseServerAdminClient()
|
||||||
.schema('audit')
|
.schema('audit')
|
||||||
.from('request_entries')
|
.from('request_entries')
|
||||||
.insert({
|
.insert({
|
||||||
/* personal_code: personalCode, */
|
|
||||||
request_api: requestApi,
|
request_api: requestApi,
|
||||||
request_api_method: requestApiMethod,
|
request_api_method: requestApiMethod,
|
||||||
requested_start_date: startTime,
|
requested_start_date: startTime,
|
||||||
@@ -69,3 +68,29 @@ export async function getMedipostDispatchTries(medusaOrderId: string) {
|
|||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function logSyncResult({
|
||||||
|
operation,
|
||||||
|
comment,
|
||||||
|
status,
|
||||||
|
changed_by_role,
|
||||||
|
}: {
|
||||||
|
operation: string;
|
||||||
|
comment?: string;
|
||||||
|
status: SyncStatus;
|
||||||
|
changed_by_role: string;
|
||||||
|
}) {
|
||||||
|
const { error } = await getSupabaseServerAdminClient()
|
||||||
|
.schema('audit')
|
||||||
|
.from('sync_entries')
|
||||||
|
.insert({
|
||||||
|
operation,
|
||||||
|
comment,
|
||||||
|
status,
|
||||||
|
changed_by_role,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
throw new Error('Failed to insert log entry, error: ' + error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,19 +7,30 @@ import {
|
|||||||
BookTimeResponse,
|
BookTimeResponse,
|
||||||
ConfirmedLoadResponse,
|
ConfirmedLoadResponse,
|
||||||
ConnectedOnlineMethodName,
|
ConnectedOnlineMethodName,
|
||||||
|
FailureReason,
|
||||||
} from '@/lib/types/connected-online';
|
} from '@/lib/types/connected-online';
|
||||||
import { ExternalApi } from '@/lib/types/external';
|
import { ExternalApi } from '@/lib/types/external';
|
||||||
import { Tables } from '@/packages/supabase/src/database.types';
|
import { Tables } from '@/packages/supabase/src/database.types';
|
||||||
import { createClient } from '@/utils/supabase/server';
|
import { StoreOrder } from '@medusajs/types';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
import { uniq, uniqBy } from 'lodash';
|
||||||
|
|
||||||
|
import { renderBookTimeFailedEmail } from '@kit/email-templates';
|
||||||
|
import { getLogger } from '@kit/shared/logger';
|
||||||
|
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||||
|
|
||||||
|
import { TimeSlotResponse } from '../../app/home/(user)/_components/booking/booking.context';
|
||||||
|
import { sendEmailFromTemplate } from './mailer.service';
|
||||||
|
import { handleDeleteCartItem } from './medusaCart.service';
|
||||||
|
|
||||||
export async function getAvailableAppointmentsForService(
|
export async function getAvailableAppointmentsForService(
|
||||||
serviceId: number,
|
serviceId: number,
|
||||||
|
key: string,
|
||||||
|
locationId: number | null,
|
||||||
startTime?: Date,
|
startTime?: Date,
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
const showTimesFrom = startTime ? { StartTime: startTime } : {};
|
const start = startTime ? { StartTime: startTime } : {};
|
||||||
|
|
||||||
const response = await axios.post(
|
const response = await axios.post(
|
||||||
`${process.env.CONNECTED_ONLINE_URL!}/${ConnectedOnlineMethodName.GetAvailabilities}`,
|
`${process.env.CONNECTED_ONLINE_URL!}/${ConnectedOnlineMethodName.GetAvailabilities}`,
|
||||||
{
|
{
|
||||||
@@ -28,9 +39,11 @@ export async function getAvailableAppointmentsForService(
|
|||||||
},
|
},
|
||||||
param: JSON.stringify({
|
param: JSON.stringify({
|
||||||
ServiceID: serviceId,
|
ServiceID: serviceId,
|
||||||
Key: '7T624nlu',
|
Key: key,
|
||||||
Lang: 'et',
|
Lang: 'et',
|
||||||
...showTimesFrom,
|
MaxDays: 120,
|
||||||
|
LocationId: locationId ?? -1,
|
||||||
|
...start,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -51,12 +64,12 @@ export async function getAvailableAppointmentsForService(
|
|||||||
: `No booking times present in appointment availability response, service id: ${serviceId}, start time: ${startTime}`;
|
: `No booking times present in appointment availability response, service id: ${serviceId}, start time: ${startTime}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// await logRequestResult(
|
await logRequestResult(
|
||||||
// ExternalApi.ConnectedOnline,
|
ExternalApi.ConnectedOnline,
|
||||||
// ConnectedOnlineMethodName.GetAvailabilities,
|
ConnectedOnlineMethodName.GetAvailabilities,
|
||||||
// RequestStatus.Fail,
|
RequestStatus.Fail,
|
||||||
// comment,
|
comment,
|
||||||
// );
|
);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -80,157 +93,210 @@ export async function getAvailableAppointmentsForService(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function bookAppointment(
|
export async function bookAppointment(
|
||||||
serviceSyncId: number,
|
serviceId: number,
|
||||||
clinicId: number,
|
clinicId: number,
|
||||||
appointmentUserId: number,
|
appointmentUserId: number,
|
||||||
syncUserID: number,
|
syncUserID: number,
|
||||||
startTime: string,
|
startTime: string,
|
||||||
locationId = 0,
|
|
||||||
comments = '',
|
comments = '',
|
||||||
isEarlierTimeRequested = false,
|
|
||||||
earlierTimeRequestComment = '',
|
|
||||||
) {
|
) {
|
||||||
const supabase = await createClient();
|
const logger = await getLogger();
|
||||||
|
const supabase = getSupabaseServerClient();
|
||||||
|
|
||||||
|
let reason = FailureReason.BOOKING_FAILED;
|
||||||
try {
|
try {
|
||||||
const {
|
const {
|
||||||
data: { user },
|
data: { user },
|
||||||
} = await supabase.auth.getUser();
|
} = await supabase.auth.getUser();
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
`Booking time slot ${JSON.stringify({ serviceId, clinicId, startTime, userId: user?.id })}`,
|
||||||
|
);
|
||||||
|
|
||||||
if (!user?.id) {
|
if (!user?.id) {
|
||||||
throw new Error('User not authenticated');
|
throw new Error('User not authenticated');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const formattedStartTime = startTime.replace('T', ' ');
|
||||||
|
|
||||||
const [
|
const [
|
||||||
{ data: dbClinic, error: clinicError },
|
{ data: dbClinic, error: clinicError },
|
||||||
{ data: dbService, error: serviceError },
|
{ data: dbService, error: serviceError },
|
||||||
|
{ data: account, error: accountError },
|
||||||
|
{ data: dbReservation, error: dbReservationError },
|
||||||
] = await Promise.all([
|
] = await Promise.all([
|
||||||
supabase
|
supabase
|
||||||
.schema('medreport')
|
.schema('medreport')
|
||||||
.from('connected_online_providers')
|
.from('connected_online_providers')
|
||||||
.select('*')
|
.select('*')
|
||||||
.eq('id', clinicId)
|
.eq('id', clinicId)
|
||||||
.limit(1),
|
.single(),
|
||||||
supabase
|
supabase
|
||||||
.schema('medreport')
|
.schema('medreport')
|
||||||
.from('connected_online_services')
|
.from('connected_online_services')
|
||||||
.select('*')
|
.select('*')
|
||||||
.eq('sync_id', serviceSyncId)
|
.eq('id', serviceId)
|
||||||
.eq('clinic_id', clinicId)
|
.eq('clinic_id', clinicId)
|
||||||
.limit(1),
|
.single(),
|
||||||
|
supabase
|
||||||
|
.schema('medreport')
|
||||||
|
.from('accounts')
|
||||||
|
.select('name, last_name, personal_code, phone, email')
|
||||||
|
.eq('is_personal_account', true)
|
||||||
|
.eq('primary_owner_user_id', user.id)
|
||||||
|
.single(),
|
||||||
|
supabase
|
||||||
|
.schema('medreport')
|
||||||
|
.from('connected_online_reservation')
|
||||||
|
.select('id')
|
||||||
|
.eq('clinic_id', clinicId)
|
||||||
|
.eq('service_id', serviceId)
|
||||||
|
.eq('start_time', formattedStartTime)
|
||||||
|
.eq('user_id', user.id)
|
||||||
|
.eq('status', 'PENDING')
|
||||||
|
.single(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (!dbClinic?.length || !dbService?.length) {
|
if (!dbClinic || !dbService) {
|
||||||
return logRequestResult(
|
const errorMessage = dbClinic
|
||||||
ExternalApi.ConnectedOnline,
|
? `Could not find clinic with id ${clinicId}, error: ${JSON.stringify(clinicError)}`
|
||||||
ConnectedOnlineMethodName.BookTime,
|
: `Could not find service with sync id ${serviceId} and clinic id ${clinicId}, error: ${JSON.stringify(serviceError)}`;
|
||||||
RequestStatus.Fail,
|
logger.error(errorMessage);
|
||||||
dbClinic?.length
|
|
||||||
? `Could not find clinic with id ${clinicId}, error: ${JSON.stringify(clinicError)}`
|
throw new Error(errorMessage);
|
||||||
: `Could not find service with sync id ${serviceSyncId} and clinic id ${clinicId}, error: ${JSON.stringify(serviceError)}`,
|
}
|
||||||
startTime,
|
|
||||||
serviceSyncId,
|
if (clinicError || serviceError || accountError) {
|
||||||
clinicId,
|
const stringifiedErrors = JSON.stringify({
|
||||||
);
|
clinicError,
|
||||||
|
serviceError,
|
||||||
|
accountError,
|
||||||
|
});
|
||||||
|
const errorMessage = `Failed to book time, error: ${stringifiedErrors}`;
|
||||||
|
logger.error(errorMessage);
|
||||||
|
|
||||||
|
throw new Error(errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!dbReservation) {
|
||||||
|
const errorMessage = `No reservation found in db with data ${JSON.stringify({ clinicId, serviceId, startTime, userId: user.id })}, got error ${JSON.stringify(dbReservationError)}`;
|
||||||
|
logger.error(errorMessage);
|
||||||
|
|
||||||
|
throw new Error(errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
const clinic: Tables<
|
const clinic: Tables<
|
||||||
{ schema: 'medreport' },
|
{ schema: 'medreport' },
|
||||||
'connected_online_providers'
|
'connected_online_providers'
|
||||||
> = dbClinic![0];
|
> = dbClinic;
|
||||||
const service: Tables<
|
const service: Tables<
|
||||||
{ schema: 'medreport' },
|
{ schema: 'medreport' },
|
||||||
'connected_online_services'
|
'connected_online_services'
|
||||||
> = dbService![0];
|
> = dbService;
|
||||||
|
|
||||||
// TODO the dummy data needs to be replaced with real values once they're present on the user/account
|
const connectedOnlineBookingResponse = await axios.post(
|
||||||
const response = await axios.post(
|
|
||||||
`${process.env.CONNECTED_ONLINE_URL!}/${ConnectedOnlineMethodName.BookTime}`,
|
`${process.env.CONNECTED_ONLINE_URL!}/${ConnectedOnlineMethodName.BookTime}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json; charset=utf-8',
|
'Content-Type': 'application/json; charset=utf-8',
|
||||||
},
|
},
|
||||||
param: JSON.stringify({
|
param: JSON.stringify({
|
||||||
EarlierTime: isEarlierTimeRequested, // once we have the e-shop functionality we can let the user select if she would like to be offered earlier time slots if they become available
|
|
||||||
EarlierTimeComment: earlierTimeRequestComment,
|
|
||||||
ClinicID: clinic.id,
|
ClinicID: clinic.id,
|
||||||
ServiceID: service.id,
|
ServiceID: service.id,
|
||||||
ClinicServiceID: service.sync_id,
|
ClinicServiceID: service.sync_id,
|
||||||
UserID: appointmentUserId,
|
UserID: appointmentUserId,
|
||||||
SyncUserID: syncUserID,
|
SyncUserID: syncUserID,
|
||||||
StartTime: startTime,
|
StartTime: startTime,
|
||||||
FirstName: 'Test',
|
FirstName: account.name,
|
||||||
LastName: 'User',
|
LastName: account.last_name,
|
||||||
PersonalCode: '4',
|
PersonalCode: account.personal_code,
|
||||||
Email: user.email,
|
Email: account.email ?? user.email,
|
||||||
Phone: 'phone',
|
Phone: account.phone,
|
||||||
Comments: comments,
|
Comments: comments,
|
||||||
Location: locationId,
|
|
||||||
FreeCode: '',
|
|
||||||
AddToBasket: false,
|
AddToBasket: false,
|
||||||
Key: '7T624nlu',
|
Key: dbClinic.key,
|
||||||
Lang: 'et', // update when integrated into app, if needed
|
Lang: 'et',
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const responseData: BookTimeResponse = JSON.parse(response.data.d);
|
const connectedOnlineBookingResponseData: BookTimeResponse = JSON.parse(
|
||||||
|
connectedOnlineBookingResponse.data.d,
|
||||||
|
);
|
||||||
|
|
||||||
if (responseData?.ErrorCode !== 0 || !responseData.Value) {
|
const errorCode = connectedOnlineBookingResponseData?.ErrorCode;
|
||||||
return logRequestResult(
|
if (errorCode !== 0 || !connectedOnlineBookingResponseData.Value) {
|
||||||
ExternalApi.ConnectedOnline,
|
const errorMessage = `Received invalid result from external api, error: ${JSON.stringify(connectedOnlineBookingResponseData)}`;
|
||||||
ConnectedOnlineMethodName.BookTime,
|
logger.error(errorMessage);
|
||||||
RequestStatus.Fail,
|
if (process.env.SUPPORT_EMAIL) {
|
||||||
JSON.stringify(responseData),
|
await sendEmailFromTemplate(
|
||||||
startTime,
|
renderBookTimeFailedEmail,
|
||||||
service.id,
|
{ reservationId: dbReservation.id, error: errorMessage },
|
||||||
clinicId,
|
process.env.SUPPORT_EMAIL,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
await supabase
|
||||||
|
.schema('medreport')
|
||||||
|
.from('connected_online_reservation')
|
||||||
|
.update({
|
||||||
|
status: 'REJECTED',
|
||||||
|
})
|
||||||
|
.eq('id', dbReservation.id)
|
||||||
|
.throwOnError();
|
||||||
|
|
||||||
|
if (errorCode === 1) {
|
||||||
|
reason = FailureReason.TIME_SLOT_UNAVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
const responseParts = connectedOnlineBookingResponseData.Value.split(',');
|
||||||
|
|
||||||
|
const { data: updatedReservation, error } = await supabase
|
||||||
|
.schema('medreport')
|
||||||
|
.from('connected_online_reservation')
|
||||||
|
.update({
|
||||||
|
booking_code: responseParts[1],
|
||||||
|
requires_payment: !!responseParts[0],
|
||||||
|
status: 'CONFIRMED',
|
||||||
|
})
|
||||||
|
.eq('id', dbReservation.id)
|
||||||
|
.select('id')
|
||||||
|
.single();
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
throw new Error(
|
||||||
|
JSON.stringify({ connectedOnlineBookingResponseData, error }),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const responseParts = responseData.Value.split(',');
|
logger.info(
|
||||||
|
'Booked time, updated reservation with id ' + updatedReservation?.id,
|
||||||
const { error } = await supabase
|
);
|
||||||
.schema('medreport')
|
|
||||||
.from('connected_online_reservation')
|
|
||||||
.insert({
|
|
||||||
booking_code: responseParts[1],
|
|
||||||
clinic_id: clinic.id,
|
|
||||||
comments,
|
|
||||||
lang: 'et', // change later, if needed
|
|
||||||
service_id: service.id,
|
|
||||||
service_user_id: appointmentUserId,
|
|
||||||
start_time: startTime,
|
|
||||||
sync_user_id: syncUserID,
|
|
||||||
requires_payment: !!responseParts[0],
|
|
||||||
user_id: user.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
await logRequestResult(
|
await logRequestResult(
|
||||||
ExternalApi.ConnectedOnline,
|
ExternalApi.ConnectedOnline,
|
||||||
ConnectedOnlineMethodName.BookTime,
|
ConnectedOnlineMethodName.BookTime,
|
||||||
RequestStatus.Success,
|
RequestStatus.Success,
|
||||||
JSON.stringify(responseData),
|
JSON.stringify(connectedOnlineBookingResponseData),
|
||||||
startTime,
|
startTime.toString(),
|
||||||
service.id,
|
service.id,
|
||||||
clinicId,
|
clinicId,
|
||||||
);
|
);
|
||||||
|
return { success: true };
|
||||||
if (error) {
|
|
||||||
throw new Error(error.message);
|
|
||||||
}
|
|
||||||
|
|
||||||
return responseData.Value;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return logRequestResult(
|
logger.error(`Failed to book time, error: ${JSON.stringify(error)}`);
|
||||||
|
await logRequestResult(
|
||||||
ExternalApi.ConnectedOnline,
|
ExternalApi.ConnectedOnline,
|
||||||
ConnectedOnlineMethodName.BookTime,
|
ConnectedOnlineMethodName.BookTime,
|
||||||
RequestStatus.Fail,
|
RequestStatus.Fail,
|
||||||
JSON.stringify(error),
|
JSON.stringify(error),
|
||||||
startTime,
|
startTime.toString(),
|
||||||
serviceSyncId,
|
serviceId,
|
||||||
clinicId,
|
clinicId,
|
||||||
);
|
);
|
||||||
|
return { success: false, reason };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,8 +336,182 @@ export async function getConfirmedService(reservationCode: string) {
|
|||||||
ExternalApi.ConnectedOnline,
|
ExternalApi.ConnectedOnline,
|
||||||
ConnectedOnlineMethodName.ConfirmedLoad,
|
ConnectedOnlineMethodName.ConfirmedLoad,
|
||||||
RequestStatus.Fail,
|
RequestStatus.Fail,
|
||||||
JSON.stringify(error),
|
error?.toString(),
|
||||||
);
|
);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getAvailableTimeSlotsForDisplay(
|
||||||
|
serviceIds: number[],
|
||||||
|
locationId: number | null,
|
||||||
|
date?: Date,
|
||||||
|
): Promise<TimeSlotResponse> {
|
||||||
|
const supabase = getSupabaseServerClient();
|
||||||
|
|
||||||
|
const { data: syncedServices } = await supabase
|
||||||
|
.schema('medreport')
|
||||||
|
.from('connected_online_services')
|
||||||
|
.select(
|
||||||
|
'*, providerClinic:clinic_id(*,locations:connected_online_locations(*))',
|
||||||
|
)
|
||||||
|
.in('id', serviceIds)
|
||||||
|
.throwOnError();
|
||||||
|
|
||||||
|
const timeSlotPromises = [];
|
||||||
|
for (const syncedService of syncedServices) {
|
||||||
|
const timeSlotsPromise = getAvailableAppointmentsForService(
|
||||||
|
syncedService.id,
|
||||||
|
syncedService.providerClinic.key,
|
||||||
|
locationId,
|
||||||
|
date,
|
||||||
|
);
|
||||||
|
timeSlotPromises.push(timeSlotsPromise);
|
||||||
|
}
|
||||||
|
|
||||||
|
const timeSlots = await Promise.all(timeSlotPromises);
|
||||||
|
|
||||||
|
const mappedTimeSlots = [];
|
||||||
|
for (const timeSlotGroup of timeSlots) {
|
||||||
|
const { data: serviceProviders } = await supabase
|
||||||
|
.schema('medreport')
|
||||||
|
.from('connected_online_service_providers')
|
||||||
|
.select(
|
||||||
|
'name, id, jobTitleEn: job_title_en, jobTitleEt: job_title_et, jobTitleRu: job_title_ru, clinicId: clinic_id',
|
||||||
|
)
|
||||||
|
.in(
|
||||||
|
'clinic_id',
|
||||||
|
uniq(timeSlotGroup?.T_Booking.map(({ ClinicID }) => ClinicID)),
|
||||||
|
)
|
||||||
|
.throwOnError();
|
||||||
|
|
||||||
|
const timeSlots =
|
||||||
|
timeSlotGroup?.T_Booking?.map((item) => {
|
||||||
|
return {
|
||||||
|
...item,
|
||||||
|
serviceProvider: serviceProviders.find(
|
||||||
|
({ id }) => id === item.UserID,
|
||||||
|
),
|
||||||
|
syncedService: syncedServices.find(
|
||||||
|
(syncedService) => syncedService.sync_id === item.ServiceID,
|
||||||
|
),
|
||||||
|
location: syncedServices
|
||||||
|
.find(
|
||||||
|
({ providerClinic }) =>
|
||||||
|
providerClinic.id === Number(item.ClinicID),
|
||||||
|
)
|
||||||
|
?.providerClinic?.locations?.find(
|
||||||
|
(location) => location.sync_id === item.LocationID,
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}) ?? [];
|
||||||
|
mappedTimeSlots.push(...timeSlots);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
timeSlots: mappedTimeSlots,
|
||||||
|
locations: uniqBy(
|
||||||
|
syncedServices.flatMap(({ providerClinic }) => providerClinic.locations),
|
||||||
|
'id',
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createInitialReservation(
|
||||||
|
serviceId: number,
|
||||||
|
clinicId: number,
|
||||||
|
appointmentUserId: number,
|
||||||
|
syncUserID: number,
|
||||||
|
startTime: Date,
|
||||||
|
medusaLineItemId: string,
|
||||||
|
locationId?: number | null,
|
||||||
|
comments = '',
|
||||||
|
) {
|
||||||
|
const logger = await getLogger();
|
||||||
|
const supabase = getSupabaseServerClient();
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: { user },
|
||||||
|
} = await supabase.auth.getUser();
|
||||||
|
|
||||||
|
const userId = user?.id;
|
||||||
|
|
||||||
|
if (!userId) {
|
||||||
|
throw new Error('User not authenticated');
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
'Creating reservation' +
|
||||||
|
JSON.stringify({ serviceId, clinicId, startTime, userId }),
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { data: createdReservation } = await supabase
|
||||||
|
.schema('medreport')
|
||||||
|
.from('connected_online_reservation')
|
||||||
|
.insert({
|
||||||
|
clinic_id: clinicId,
|
||||||
|
comments,
|
||||||
|
lang: 'et',
|
||||||
|
service_id: serviceId,
|
||||||
|
service_user_id: appointmentUserId,
|
||||||
|
start_time: startTime.toString(),
|
||||||
|
sync_user_id: syncUserID,
|
||||||
|
user_id: userId,
|
||||||
|
status: 'PENDING',
|
||||||
|
medusa_cart_line_item_id: medusaLineItemId,
|
||||||
|
location_sync_id: locationId,
|
||||||
|
})
|
||||||
|
.select('id')
|
||||||
|
.single()
|
||||||
|
.throwOnError();
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
`Created reservation ${JSON.stringify({ createdReservation, userId })}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
return createdReservation;
|
||||||
|
} catch (e) {
|
||||||
|
logger.error(
|
||||||
|
`Failed to create initial reservation ${JSON.stringify({ serviceId, clinicId, startTime })} ${e}`,
|
||||||
|
);
|
||||||
|
await handleDeleteCartItem({ lineId: medusaLineItemId });
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function cancelReservation(medusaLineItemId: string) {
|
||||||
|
const supabase = getSupabaseServerClient();
|
||||||
|
|
||||||
|
return supabase
|
||||||
|
.schema('medreport')
|
||||||
|
.from('connected_online_reservation')
|
||||||
|
.update({
|
||||||
|
status: 'CANCELLED',
|
||||||
|
})
|
||||||
|
.eq('medusa_cart_line_item_id', medusaLineItemId)
|
||||||
|
.throwOnError();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getOrderedTtoServices({
|
||||||
|
medusaOrder,
|
||||||
|
}: {
|
||||||
|
medusaOrder: StoreOrder;
|
||||||
|
}) {
|
||||||
|
const supabase = getSupabaseServerClient();
|
||||||
|
|
||||||
|
const ttoReservationIds: number[] =
|
||||||
|
medusaOrder.items
|
||||||
|
?.filter(({ metadata }) => !!metadata?.connectedOnlineReservationId)
|
||||||
|
.map(({ metadata }) => Number(metadata!.connectedOnlineReservationId)) ??
|
||||||
|
[];
|
||||||
|
|
||||||
|
const { data: orderedTtoServices } = await supabase
|
||||||
|
.schema('medreport')
|
||||||
|
.from('connected_online_reservation')
|
||||||
|
.select('*')
|
||||||
|
.in('id', ttoReservationIds)
|
||||||
|
.throwOnError();
|
||||||
|
|
||||||
|
return orderedTtoServices;
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { z } from 'zod';
|
|||||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||||
|
|
||||||
import { requireUserInServerComponent } from '../server/require-user-in-server-component';
|
import { requireUserInServerComponent } from '../server/require-user-in-server-component';
|
||||||
|
import { cancelReservation } from './connected-online.service';
|
||||||
|
|
||||||
const env = () =>
|
const env = () =>
|
||||||
z
|
z
|
||||||
@@ -26,8 +27,10 @@ const env = () =>
|
|||||||
.min(1),
|
.min(1),
|
||||||
})
|
})
|
||||||
.parse({
|
.parse({
|
||||||
medusaBackendPublicUrl: process.env.MEDUSA_BACKEND_PUBLIC_URL!,
|
medusaBackendPublicUrl:
|
||||||
siteUrl: process.env.NEXT_PUBLIC_SITE_URL!,
|
'http://weebhook.site:3000' /* process.env.MEDUSA_BACKEND_PUBLIC_URL! */,
|
||||||
|
siteUrl:
|
||||||
|
'http://weebhook.site:3000' /* process.env.NEXT_PUBLIC_SITE_URL! */,
|
||||||
});
|
});
|
||||||
|
|
||||||
export async function handleAddToCart({
|
export async function handleAddToCart({
|
||||||
@@ -44,7 +47,7 @@ export async function handleAddToCart({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const quantity = 1;
|
const quantity = 1;
|
||||||
const cart = await addToCart({
|
const { newCart, addedItem } = await addToCart({
|
||||||
variantId: selectedVariant.id,
|
variantId: selectedVariant.id,
|
||||||
quantity,
|
quantity,
|
||||||
countryCode,
|
countryCode,
|
||||||
@@ -54,18 +57,19 @@ export async function handleAddToCart({
|
|||||||
variant_id: selectedVariant.id,
|
variant_id: selectedVariant.id,
|
||||||
operation: 'ADD_TO_CART',
|
operation: 'ADD_TO_CART',
|
||||||
account_id: account.id,
|
account_id: account.id,
|
||||||
cart_id: cart.id,
|
cart_id: newCart.id,
|
||||||
changed_by: user.id,
|
changed_by: user.id,
|
||||||
});
|
});
|
||||||
if (error) {
|
if (error) {
|
||||||
throw new Error('Error logging cart entry: ' + error.message);
|
throw new Error('Error logging cart entry: ' + error.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cart;
|
return { cart: newCart, addedItem };
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handleDeleteCartItem({ lineId }: { lineId: string }) {
|
export async function handleDeleteCartItem({ lineId }: { lineId: string }) {
|
||||||
await deleteLineItem(lineId);
|
await deleteLineItem(lineId);
|
||||||
|
await cancelReservation(lineId);
|
||||||
|
|
||||||
const supabase = getSupabaseServerClient();
|
const supabase = getSupabaseServerClient();
|
||||||
const cartId = await getCartId();
|
const cartId = await getCartId();
|
||||||
|
|||||||
@@ -152,3 +152,29 @@ export async function getAnalysisOrdersAdmin({
|
|||||||
const orders = await query.order('created_at', { ascending: false }).throwOnError();
|
const orders = await query.order('created_at', { ascending: false }).throwOnError();
|
||||||
return orders.data;
|
return orders.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getTtoOrders({
|
||||||
|
orderStatus,
|
||||||
|
}: {
|
||||||
|
orderStatus?: Tables<{ schema: 'medreport' }, 'connected_online_reservation'>['status'];
|
||||||
|
} = {}) {
|
||||||
|
const client = getSupabaseServerClient();
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: { user },
|
||||||
|
} = await client.auth.getUser();
|
||||||
|
if (!user) {
|
||||||
|
throw new Error('Unauthorized');
|
||||||
|
}
|
||||||
|
|
||||||
|
const query = client
|
||||||
|
.schema('medreport')
|
||||||
|
.from('connected_online_reservation')
|
||||||
|
.select('*')
|
||||||
|
.eq("user_id", user.id)
|
||||||
|
if (orderStatus) {
|
||||||
|
query.eq('status', orderStatus);
|
||||||
|
}
|
||||||
|
const orders = await query.order('created_at', { ascending: false }).throwOnError();
|
||||||
|
return orders.data;
|
||||||
|
}
|
||||||
@@ -10,13 +10,15 @@ export type BookTimeResponse = z.infer<typeof BookTimeResponseSchema>;
|
|||||||
|
|
||||||
export enum ConnectedOnlineMethodName {
|
export enum ConnectedOnlineMethodName {
|
||||||
SearchLoad = 'Search_Load',
|
SearchLoad = 'Search_Load',
|
||||||
|
DefaultLoad = 'Default_Load',
|
||||||
|
ConfirmedCancel = 'Confirmed_Cancel',
|
||||||
GetAvailabilities = 'GetAvailabilities',
|
GetAvailabilities = 'GetAvailabilities',
|
||||||
BookTime = 'BookTime',
|
BookTime = 'BookTime',
|
||||||
ConfirmedLoad = 'Confirmed_Load',
|
ConfirmedLoad = 'Confirmed_Load',
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AvailableAppointmentTBookingSchema = z.object({
|
export const AvailableAppointmentTBookingSchema = z.object({
|
||||||
ClinicID: z.string(),
|
ClinicID: z.number(),
|
||||||
LocationID: z.number(),
|
LocationID: z.number(),
|
||||||
UserID: z.number(),
|
UserID: z.number(),
|
||||||
SyncUserID: z.number(),
|
SyncUserID: z.number(),
|
||||||
@@ -225,6 +227,18 @@ export const ConfirmedLoadResponseSchema = z.object({
|
|||||||
});
|
});
|
||||||
export type ConfirmedLoadResponse = z.infer<typeof ConfirmedLoadResponseSchema>;
|
export type ConfirmedLoadResponse = z.infer<typeof ConfirmedLoadResponseSchema>;
|
||||||
|
|
||||||
|
export type P_JobTitleTranslation = {
|
||||||
|
ID: number;
|
||||||
|
SyncID: number;
|
||||||
|
TextEN: string;
|
||||||
|
TextET: string;
|
||||||
|
TextFI: string;
|
||||||
|
TextRU: string;
|
||||||
|
TextLT: string;
|
||||||
|
ClinicID: number;
|
||||||
|
Deleted: number;
|
||||||
|
};
|
||||||
|
|
||||||
export interface ISearchLoadResponse {
|
export interface ISearchLoadResponse {
|
||||||
Value: string;
|
Value: string;
|
||||||
Data: {
|
Data: {
|
||||||
@@ -232,9 +246,11 @@ export interface ISearchLoadResponse {
|
|||||||
ID: number;
|
ID: number;
|
||||||
Name: string;
|
Name: string;
|
||||||
OnlineCanSelectWorker: boolean;
|
OnlineCanSelectWorker: boolean;
|
||||||
|
Address: string;
|
||||||
Email: string | null;
|
Email: string | null;
|
||||||
PersonalCodeRequired: boolean;
|
PersonalCodeRequired: boolean;
|
||||||
Phone: string | null;
|
Phone: string | null;
|
||||||
|
Key: string;
|
||||||
}[];
|
}[];
|
||||||
T_Service: {
|
T_Service: {
|
||||||
ID: number;
|
ID: number;
|
||||||
@@ -253,7 +269,14 @@ export interface ISearchLoadResponse {
|
|||||||
RequiresPayment: boolean;
|
RequiresPayment: boolean;
|
||||||
SyncID: string;
|
SyncID: string;
|
||||||
}[];
|
}[];
|
||||||
|
T_Doctor: TDoctor[];
|
||||||
|
P_JobTitleTranslations: P_JobTitleTranslation[];
|
||||||
};
|
};
|
||||||
ErrorCode: number;
|
ErrorCode: number;
|
||||||
ErrorMessage: string;
|
ErrorMessage: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum FailureReason {
|
||||||
|
BOOKING_FAILED = 'BOOKING_FAILED',
|
||||||
|
TIME_SLOT_UNAVAILABLE = 'TIME_SLOT_UNAVAILABLE',
|
||||||
|
}
|
||||||
|
|||||||
11
lib/utils.ts
11
lib/utils.ts
@@ -20,7 +20,7 @@ export function toTitleCase(str?: string) {
|
|||||||
?.toLowerCase()
|
?.toLowerCase()
|
||||||
.replace(/[^-'’\s]+/g, (match) =>
|
.replace(/[^-'’\s]+/g, (match) =>
|
||||||
match.replace(/^./, (first) => first.toUpperCase()),
|
match.replace(/^./, (first) => first.toUpperCase()),
|
||||||
) ?? ""
|
) ?? ''
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,6 +145,13 @@ export default class PersonalCode {
|
|||||||
gender,
|
gender,
|
||||||
dob: parsed.getBirthday(),
|
dob: parsed.getBirthday(),
|
||||||
age: parsed.getAge(),
|
age: parsed.getAge(),
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const findProductTypeIdByHandle = (
|
||||||
|
productTypes: { metadata?: Record<string, unknown> | null; id: string }[],
|
||||||
|
handle: string,
|
||||||
|
) => {
|
||||||
|
return productTypes.find(({ metadata }) => metadata?.handle === handle)?.id;
|
||||||
|
};
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
import {
|
||||||
|
Body,
|
||||||
|
Head,
|
||||||
|
Html,
|
||||||
|
Preview,
|
||||||
|
Tailwind,
|
||||||
|
Text,
|
||||||
|
render,
|
||||||
|
} from '@react-email/components';
|
||||||
|
|
||||||
|
import { BodyStyle } from '../components/body-style';
|
||||||
|
import { EmailContent } from '../components/content';
|
||||||
|
import { EmailHeader } from '../components/header';
|
||||||
|
import { EmailHeading } from '../components/heading';
|
||||||
|
import { EmailWrapper } from '../components/wrapper';
|
||||||
|
|
||||||
|
export async function renderBookTimeFailedEmail({
|
||||||
|
reservationId,
|
||||||
|
error,
|
||||||
|
}: {
|
||||||
|
reservationId: number;
|
||||||
|
error: string;
|
||||||
|
}) {
|
||||||
|
const subject = 'Aja broneerimine ei õnnestunud';
|
||||||
|
|
||||||
|
const html = await render(
|
||||||
|
<Html>
|
||||||
|
<Head>
|
||||||
|
<BodyStyle />
|
||||||
|
</Head>
|
||||||
|
|
||||||
|
<Preview>{subject}</Preview>
|
||||||
|
|
||||||
|
<Tailwind>
|
||||||
|
<Body>
|
||||||
|
<EmailWrapper>
|
||||||
|
<EmailContent>
|
||||||
|
<EmailHeader>
|
||||||
|
<EmailHeading>{subject}</EmailHeading>
|
||||||
|
</EmailHeader>
|
||||||
|
<Text className="text-[16px] leading-[24px] text-[#242424]">
|
||||||
|
Tere
|
||||||
|
</Text>
|
||||||
|
|
||||||
|
<Text>
|
||||||
|
Broneeringu {reservationId} Connected Online'i saatmine ei
|
||||||
|
õnnestunud, kliendile tuleb teha tagasimakse.
|
||||||
|
</Text>
|
||||||
|
<Text>Saadud error: {error}</Text>
|
||||||
|
</EmailContent>
|
||||||
|
</EmailWrapper>
|
||||||
|
</Body>
|
||||||
|
</Tailwind>
|
||||||
|
</Html>,
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
html,
|
||||||
|
subject,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -10,3 +10,4 @@ export * from './emails/all-results-received.email';
|
|||||||
export * from './emails/order-processing.email';
|
export * from './emails/order-processing.email';
|
||||||
export * from './emails/patient-first-results-received.email';
|
export * from './emails/patient-first-results-received.email';
|
||||||
export * from './emails/patient-full-results-received.email';
|
export * from './emails/patient-full-results-received.email';
|
||||||
|
export * from './emails/book-time-failed.email'
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
import { getRegion } from "./regions";
|
import { getRegion } from "./regions";
|
||||||
import { sdk } from "@lib/config";
|
import { sdk } from "@lib/config";
|
||||||
import { retrieveOrder } from "./orders";
|
import { retrieveOrder } from "./orders";
|
||||||
|
import { completeTtoCart } from "../../../../../../lib/services/connected-online.service";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a cart by its ID. If no ID is provided, it will use the cart ID from the cookies.
|
* Retrieves a cart by its ID. If no ID is provided, it will use the cart ID from the cookies.
|
||||||
@@ -89,7 +90,10 @@ export async function getOrSetCart(countryCode: string) {
|
|||||||
|
|
||||||
export async function updateCart(
|
export async function updateCart(
|
||||||
{ id, ...data }: HttpTypes.StoreUpdateCart & { id?: string },
|
{ id, ...data }: HttpTypes.StoreUpdateCart & { id?: string },
|
||||||
{ onSuccess, onError }: { onSuccess: () => void, onError: () => void } = { onSuccess: () => {}, onError: () => {} },
|
{ onSuccess, onError }: { onSuccess: () => void; onError: () => void } = {
|
||||||
|
onSuccess: () => {},
|
||||||
|
onError: () => {},
|
||||||
|
}
|
||||||
) {
|
) {
|
||||||
const cartId = id || (await getCartId());
|
const cartId = id || (await getCartId());
|
||||||
|
|
||||||
@@ -163,7 +167,12 @@ export async function addToCart({
|
|||||||
})
|
})
|
||||||
.catch(medusaError);
|
.catch(medusaError);
|
||||||
|
|
||||||
return cart;
|
const newCart = await getOrSetCart(countryCode);
|
||||||
|
const addedItem = newCart.items?.filter(
|
||||||
|
(item) => !cart.items?.some((oldCartItem) => oldCartItem.id === item.id)
|
||||||
|
)?.[0];
|
||||||
|
|
||||||
|
return { newCart, addedItem };
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateLineItem({
|
export async function updateLineItem({
|
||||||
@@ -268,7 +277,10 @@ export async function initiatePaymentSession(
|
|||||||
|
|
||||||
export async function applyPromotions(
|
export async function applyPromotions(
|
||||||
codes: string[],
|
codes: string[],
|
||||||
{ onSuccess, onError }: { onSuccess: () => void, onError: () => void } = { onSuccess: () => {}, onError: () => {} },
|
{ onSuccess, onError }: { onSuccess: () => void; onError: () => void } = {
|
||||||
|
onSuccess: () => {},
|
||||||
|
onError: () => {},
|
||||||
|
}
|
||||||
) {
|
) {
|
||||||
const cartId = await getCartId();
|
const cartId = await getCartId();
|
||||||
|
|
||||||
@@ -410,7 +422,10 @@ export async function setAddresses(currentState: unknown, formData: FormData) {
|
|||||||
* @param cartId - optional - The ID of the cart to place an order for.
|
* @param cartId - optional - The ID of the cart to place an order for.
|
||||||
* @returns The cart object if the order was successful, or null if not.
|
* @returns The cart object if the order was successful, or null if not.
|
||||||
*/
|
*/
|
||||||
export async function placeOrder(cartId?: string, options: { revalidateCacheTags: boolean } = { revalidateCacheTags: true }) {
|
export async function placeOrder(
|
||||||
|
cartId?: string,
|
||||||
|
options: { revalidateCacheTags: boolean } = { revalidateCacheTags: true }
|
||||||
|
) {
|
||||||
const id = cartId || (await getCartId());
|
const id = cartId || (await getCartId());
|
||||||
|
|
||||||
if (!id) {
|
if (!id) {
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ export const listCategories = async (query?: Record<string, any>) => {
|
|||||||
...query,
|
...query,
|
||||||
},
|
},
|
||||||
next,
|
next,
|
||||||
cache: "force-cache",
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.then(({ product_categories }) => product_categories);
|
.then(({ product_categories }) => product_categories);
|
||||||
@@ -56,7 +55,6 @@ export const getProductCategories = async ({
|
|||||||
limit,
|
limit,
|
||||||
},
|
},
|
||||||
next,
|
next,
|
||||||
//cache: "force-cache",
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import { cookies } from 'next/headers';
|
|||||||
|
|
||||||
import { createServerClient } from '@supabase/ssr';
|
import { createServerClient } from '@supabase/ssr';
|
||||||
|
|
||||||
import { Database } from '../database.types';
|
|
||||||
import { getSupabaseClientKeys } from '../get-supabase-client-keys';
|
import { getSupabaseClientKeys } from '../get-supabase-client-keys';
|
||||||
|
import { Database } from '../database.types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name getSupabaseServerClient
|
* @name getSupabaseServerClient
|
||||||
|
|||||||
@@ -198,6 +198,7 @@ export type Database = {
|
|||||||
action: string
|
action: string
|
||||||
changed_by: string
|
changed_by: string
|
||||||
created_at: string
|
created_at: string
|
||||||
|
extra_data: Json | null
|
||||||
id: number
|
id: number
|
||||||
}
|
}
|
||||||
Insert: {
|
Insert: {
|
||||||
@@ -205,6 +206,7 @@ export type Database = {
|
|||||||
action: string
|
action: string
|
||||||
changed_by: string
|
changed_by: string
|
||||||
created_at?: string
|
created_at?: string
|
||||||
|
extra_data?: Json | null
|
||||||
id?: number
|
id?: number
|
||||||
}
|
}
|
||||||
Update: {
|
Update: {
|
||||||
@@ -212,6 +214,7 @@ export type Database = {
|
|||||||
action?: string
|
action?: string
|
||||||
changed_by?: string
|
changed_by?: string
|
||||||
created_at?: string
|
created_at?: string
|
||||||
|
extra_data?: Json | null
|
||||||
id?: number
|
id?: number
|
||||||
}
|
}
|
||||||
Relationships: []
|
Relationships: []
|
||||||
@@ -221,7 +224,6 @@ export type Database = {
|
|||||||
comment: string | null
|
comment: string | null
|
||||||
created_at: string
|
created_at: string
|
||||||
id: number
|
id: number
|
||||||
personal_code: number | null
|
|
||||||
request_api: string
|
request_api: string
|
||||||
request_api_method: string
|
request_api_method: string
|
||||||
requested_end_date: string | null
|
requested_end_date: string | null
|
||||||
@@ -229,12 +231,12 @@ export type Database = {
|
|||||||
service_id: number | null
|
service_id: number | null
|
||||||
service_provider_id: number | null
|
service_provider_id: number | null
|
||||||
status: Database["audit"]["Enums"]["request_status"]
|
status: Database["audit"]["Enums"]["request_status"]
|
||||||
|
user_id: string | null
|
||||||
}
|
}
|
||||||
Insert: {
|
Insert: {
|
||||||
comment?: string | null
|
comment?: string | null
|
||||||
created_at?: string
|
created_at?: string
|
||||||
id?: number
|
id?: number
|
||||||
personal_code?: number | null
|
|
||||||
request_api: string
|
request_api: string
|
||||||
request_api_method: string
|
request_api_method: string
|
||||||
requested_end_date?: string | null
|
requested_end_date?: string | null
|
||||||
@@ -242,12 +244,12 @@ export type Database = {
|
|||||||
service_id?: number | null
|
service_id?: number | null
|
||||||
service_provider_id?: number | null
|
service_provider_id?: number | null
|
||||||
status: Database["audit"]["Enums"]["request_status"]
|
status: Database["audit"]["Enums"]["request_status"]
|
||||||
|
user_id?: string | null
|
||||||
}
|
}
|
||||||
Update: {
|
Update: {
|
||||||
comment?: string | null
|
comment?: string | null
|
||||||
created_at?: string
|
created_at?: string
|
||||||
id?: number
|
id?: number
|
||||||
personal_code?: number | null
|
|
||||||
request_api?: string
|
request_api?: string
|
||||||
request_api_method?: string
|
request_api_method?: string
|
||||||
requested_end_date?: string | null
|
requested_end_date?: string | null
|
||||||
@@ -255,6 +257,7 @@ export type Database = {
|
|||||||
service_id?: number | null
|
service_id?: number | null
|
||||||
service_provider_id?: number | null
|
service_provider_id?: number | null
|
||||||
status?: Database["audit"]["Enums"]["request_status"]
|
status?: Database["audit"]["Enums"]["request_status"]
|
||||||
|
user_id?: string | null
|
||||||
}
|
}
|
||||||
Relationships: []
|
Relationships: []
|
||||||
}
|
}
|
||||||
@@ -990,32 +993,76 @@ export type Database = {
|
|||||||
}
|
}
|
||||||
Relationships: []
|
Relationships: []
|
||||||
}
|
}
|
||||||
|
connected_online_locations: {
|
||||||
|
Row: {
|
||||||
|
address: string | null
|
||||||
|
clinic_id: number
|
||||||
|
created_at: string
|
||||||
|
id: number
|
||||||
|
name: string
|
||||||
|
sync_id: number
|
||||||
|
updated_at: string | null
|
||||||
|
}
|
||||||
|
Insert: {
|
||||||
|
address?: string | null
|
||||||
|
clinic_id: number
|
||||||
|
created_at?: string
|
||||||
|
id?: number
|
||||||
|
name: string
|
||||||
|
sync_id: number
|
||||||
|
updated_at?: string | null
|
||||||
|
}
|
||||||
|
Update: {
|
||||||
|
address?: string | null
|
||||||
|
clinic_id?: number
|
||||||
|
created_at?: string
|
||||||
|
id?: number
|
||||||
|
name?: string
|
||||||
|
sync_id?: number
|
||||||
|
updated_at?: string | null
|
||||||
|
}
|
||||||
|
Relationships: [
|
||||||
|
{
|
||||||
|
foreignKeyName: "connected_online_locations_clinic_id_fkey"
|
||||||
|
columns: ["clinic_id"]
|
||||||
|
isOneToOne: false
|
||||||
|
referencedRelation: "connected_online_providers"
|
||||||
|
referencedColumns: ["id"]
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
connected_online_providers: {
|
connected_online_providers: {
|
||||||
Row: {
|
Row: {
|
||||||
|
address: string
|
||||||
can_select_worker: boolean
|
can_select_worker: boolean
|
||||||
created_at: string
|
created_at: string
|
||||||
email: string | null
|
email: string | null
|
||||||
id: number
|
id: number
|
||||||
|
key: string
|
||||||
name: string
|
name: string
|
||||||
personal_code_required: boolean
|
personal_code_required: boolean
|
||||||
phone_number: string | null
|
phone_number: string | null
|
||||||
updated_at: string | null
|
updated_at: string | null
|
||||||
}
|
}
|
||||||
Insert: {
|
Insert: {
|
||||||
|
address?: string
|
||||||
can_select_worker: boolean
|
can_select_worker: boolean
|
||||||
created_at?: string
|
created_at?: string
|
||||||
email?: string | null
|
email?: string | null
|
||||||
id: number
|
id: number
|
||||||
|
key: string
|
||||||
name: string
|
name: string
|
||||||
personal_code_required: boolean
|
personal_code_required: boolean
|
||||||
phone_number?: string | null
|
phone_number?: string | null
|
||||||
updated_at?: string | null
|
updated_at?: string | null
|
||||||
}
|
}
|
||||||
Update: {
|
Update: {
|
||||||
|
address?: string
|
||||||
can_select_worker?: boolean
|
can_select_worker?: boolean
|
||||||
created_at?: string
|
created_at?: string
|
||||||
email?: string | null
|
email?: string | null
|
||||||
id?: number
|
id?: number
|
||||||
|
key?: string
|
||||||
name?: string
|
name?: string
|
||||||
personal_code_required?: boolean
|
personal_code_required?: boolean
|
||||||
phone_number?: string | null
|
phone_number?: string | null
|
||||||
@@ -1025,55 +1072,117 @@ export type Database = {
|
|||||||
}
|
}
|
||||||
connected_online_reservation: {
|
connected_online_reservation: {
|
||||||
Row: {
|
Row: {
|
||||||
booking_code: string
|
booking_code: string | null
|
||||||
clinic_id: number
|
clinic_id: number
|
||||||
comments: string | null
|
comments: string | null
|
||||||
created_at: string
|
created_at: string
|
||||||
discount_code: string | null
|
discount_code: string | null
|
||||||
id: number
|
id: number
|
||||||
lang: string
|
lang: string
|
||||||
requires_payment: boolean
|
location_sync_id: number | null
|
||||||
|
medusa_cart_line_item_id: string | null
|
||||||
|
requires_payment: boolean | null
|
||||||
service_id: number
|
service_id: number
|
||||||
service_user_id: number | null
|
service_user_id: number
|
||||||
start_time: string
|
start_time: string
|
||||||
|
status: Database["medreport"]["Enums"]["connected_online_order_status"]
|
||||||
sync_user_id: number
|
sync_user_id: number
|
||||||
updated_at: string | null
|
updated_at: string | null
|
||||||
user_id: string
|
user_id: string
|
||||||
}
|
}
|
||||||
Insert: {
|
Insert: {
|
||||||
booking_code: string
|
booking_code?: string | null
|
||||||
clinic_id: number
|
clinic_id: number
|
||||||
comments?: string | null
|
comments?: string | null
|
||||||
created_at?: string
|
created_at?: string
|
||||||
discount_code?: string | null
|
discount_code?: string | null
|
||||||
id?: number
|
id?: number
|
||||||
lang: string
|
lang: string
|
||||||
requires_payment: boolean
|
location_sync_id?: number | null
|
||||||
|
medusa_cart_line_item_id?: string | null
|
||||||
|
requires_payment?: boolean | null
|
||||||
service_id: number
|
service_id: number
|
||||||
service_user_id?: number | null
|
service_user_id: number
|
||||||
start_time: string
|
start_time: string
|
||||||
|
status: Database["medreport"]["Enums"]["connected_online_order_status"]
|
||||||
sync_user_id: number
|
sync_user_id: number
|
||||||
updated_at?: string | null
|
updated_at?: string | null
|
||||||
user_id: string
|
user_id: string
|
||||||
}
|
}
|
||||||
Update: {
|
Update: {
|
||||||
booking_code?: string
|
booking_code?: string | null
|
||||||
clinic_id?: number
|
clinic_id?: number
|
||||||
comments?: string | null
|
comments?: string | null
|
||||||
created_at?: string
|
created_at?: string
|
||||||
discount_code?: string | null
|
discount_code?: string | null
|
||||||
id?: number
|
id?: number
|
||||||
lang?: string
|
lang?: string
|
||||||
requires_payment?: boolean
|
location_sync_id?: number | null
|
||||||
|
medusa_cart_line_item_id?: string | null
|
||||||
|
requires_payment?: boolean | null
|
||||||
service_id?: number
|
service_id?: number
|
||||||
service_user_id?: number | null
|
service_user_id?: number
|
||||||
start_time?: string
|
start_time?: string
|
||||||
|
status?: Database["medreport"]["Enums"]["connected_online_order_status"]
|
||||||
sync_user_id?: number
|
sync_user_id?: number
|
||||||
updated_at?: string | null
|
updated_at?: string | null
|
||||||
user_id?: string
|
user_id?: string
|
||||||
}
|
}
|
||||||
Relationships: []
|
Relationships: []
|
||||||
}
|
}
|
||||||
|
connected_online_service_providers: {
|
||||||
|
Row: {
|
||||||
|
clinic_id: number
|
||||||
|
created_at: string
|
||||||
|
id: number
|
||||||
|
is_deleted: boolean | null
|
||||||
|
job_title_en: string | null
|
||||||
|
job_title_et: string | null
|
||||||
|
job_title_id: number | null
|
||||||
|
job_title_ru: string | null
|
||||||
|
name: string
|
||||||
|
prefix: string | null
|
||||||
|
spoken_languages: string[] | null
|
||||||
|
updated_at: string | null
|
||||||
|
}
|
||||||
|
Insert: {
|
||||||
|
clinic_id: number
|
||||||
|
created_at?: string
|
||||||
|
id: number
|
||||||
|
is_deleted?: boolean | null
|
||||||
|
job_title_en?: string | null
|
||||||
|
job_title_et?: string | null
|
||||||
|
job_title_id?: number | null
|
||||||
|
job_title_ru?: string | null
|
||||||
|
name: string
|
||||||
|
prefix?: string | null
|
||||||
|
spoken_languages?: string[] | null
|
||||||
|
updated_at?: string | null
|
||||||
|
}
|
||||||
|
Update: {
|
||||||
|
clinic_id?: number
|
||||||
|
created_at?: string
|
||||||
|
id?: number
|
||||||
|
is_deleted?: boolean | null
|
||||||
|
job_title_en?: string | null
|
||||||
|
job_title_et?: string | null
|
||||||
|
job_title_id?: number | null
|
||||||
|
job_title_ru?: string | null
|
||||||
|
name?: string
|
||||||
|
prefix?: string | null
|
||||||
|
spoken_languages?: string[] | null
|
||||||
|
updated_at?: string | null
|
||||||
|
}
|
||||||
|
Relationships: [
|
||||||
|
{
|
||||||
|
foreignKeyName: "connected_online_service_providers_clinic_id_fkey"
|
||||||
|
columns: ["clinic_id"]
|
||||||
|
isOneToOne: false
|
||||||
|
referencedRelation: "connected_online_providers"
|
||||||
|
referencedColumns: ["id"]
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
connected_online_services: {
|
connected_online_services: {
|
||||||
Row: {
|
Row: {
|
||||||
clinic_id: number
|
clinic_id: number
|
||||||
@@ -1091,7 +1200,7 @@ export type Database = {
|
|||||||
price: number
|
price: number
|
||||||
price_periods: string | null
|
price_periods: string | null
|
||||||
requires_payment: boolean
|
requires_payment: boolean
|
||||||
sync_id: string
|
sync_id: number
|
||||||
updated_at: string | null
|
updated_at: string | null
|
||||||
}
|
}
|
||||||
Insert: {
|
Insert: {
|
||||||
@@ -1110,7 +1219,7 @@ export type Database = {
|
|||||||
price: number
|
price: number
|
||||||
price_periods?: string | null
|
price_periods?: string | null
|
||||||
requires_payment: boolean
|
requires_payment: boolean
|
||||||
sync_id: string
|
sync_id: number
|
||||||
updated_at?: string | null
|
updated_at?: string | null
|
||||||
}
|
}
|
||||||
Update: {
|
Update: {
|
||||||
@@ -1129,7 +1238,7 @@ export type Database = {
|
|||||||
price?: number
|
price?: number
|
||||||
price_periods?: string | null
|
price_periods?: string | null
|
||||||
requires_payment?: boolean
|
requires_payment?: boolean
|
||||||
sync_id?: string
|
sync_id?: number
|
||||||
updated_at?: string | null
|
updated_at?: string | null
|
||||||
}
|
}
|
||||||
Relationships: [
|
Relationships: [
|
||||||
@@ -1150,7 +1259,7 @@ export type Database = {
|
|||||||
doctor_user_id: string | null
|
doctor_user_id: string | null
|
||||||
id: number
|
id: number
|
||||||
status: Database["medreport"]["Enums"]["analysis_feedback_status"]
|
status: Database["medreport"]["Enums"]["analysis_feedback_status"]
|
||||||
updated_at: string
|
updated_at: string | null
|
||||||
updated_by: string | null
|
updated_by: string | null
|
||||||
user_id: string
|
user_id: string
|
||||||
value: string | null
|
value: string | null
|
||||||
@@ -1162,7 +1271,7 @@ export type Database = {
|
|||||||
doctor_user_id?: string | null
|
doctor_user_id?: string | null
|
||||||
id?: number
|
id?: number
|
||||||
status?: Database["medreport"]["Enums"]["analysis_feedback_status"]
|
status?: Database["medreport"]["Enums"]["analysis_feedback_status"]
|
||||||
updated_at?: string
|
updated_at?: string | null
|
||||||
updated_by?: string | null
|
updated_by?: string | null
|
||||||
user_id: string
|
user_id: string
|
||||||
value?: string | null
|
value?: string | null
|
||||||
@@ -1174,7 +1283,7 @@ export type Database = {
|
|||||||
doctor_user_id?: string | null
|
doctor_user_id?: string | null
|
||||||
id?: number
|
id?: number
|
||||||
status?: Database["medreport"]["Enums"]["analysis_feedback_status"]
|
status?: Database["medreport"]["Enums"]["analysis_feedback_status"]
|
||||||
updated_at?: string
|
updated_at?: string | null
|
||||||
updated_by?: string | null
|
updated_by?: string | null
|
||||||
user_id?: string
|
user_id?: string
|
||||||
value?: string | null
|
value?: string | null
|
||||||
@@ -1259,23 +1368,36 @@ export type Database = {
|
|||||||
}
|
}
|
||||||
medipost_actions: {
|
medipost_actions: {
|
||||||
Row: {
|
Row: {
|
||||||
created_at: string
|
|
||||||
id: number
|
|
||||||
action: string
|
action: string
|
||||||
xml: string
|
created_at: string | null
|
||||||
has_analysis_results: boolean
|
has_analysis_results: boolean
|
||||||
medusa_order_id: string
|
|
||||||
response_xml: string
|
|
||||||
has_error: boolean
|
has_error: boolean
|
||||||
|
id: string
|
||||||
|
medusa_order_id: string | null
|
||||||
|
response_xml: string | null
|
||||||
|
xml: string | null
|
||||||
}
|
}
|
||||||
Insert: {
|
Insert: {
|
||||||
action: string
|
action: string
|
||||||
xml: string
|
created_at?: string | null
|
||||||
has_analysis_results: boolean
|
has_analysis_results?: boolean
|
||||||
medusa_order_id: string
|
has_error?: boolean
|
||||||
response_xml: string
|
id?: string
|
||||||
has_error: boolean
|
medusa_order_id?: string | null
|
||||||
|
response_xml?: string | null
|
||||||
|
xml?: string | null
|
||||||
}
|
}
|
||||||
|
Update: {
|
||||||
|
action?: string
|
||||||
|
created_at?: string | null
|
||||||
|
has_analysis_results?: boolean
|
||||||
|
has_error?: boolean
|
||||||
|
id?: string
|
||||||
|
medusa_order_id?: string | null
|
||||||
|
response_xml?: string | null
|
||||||
|
xml?: string | null
|
||||||
|
}
|
||||||
|
Relationships: []
|
||||||
}
|
}
|
||||||
medreport_product_groups: {
|
medreport_product_groups: {
|
||||||
Row: {
|
Row: {
|
||||||
@@ -1944,6 +2066,13 @@ export type Database = {
|
|||||||
personal_code: string
|
personal_code: string
|
||||||
}[]
|
}[]
|
||||||
}
|
}
|
||||||
|
get_latest_medipost_dispatch_state_for_order: {
|
||||||
|
Args: { medusa_order_id: string }
|
||||||
|
Returns: {
|
||||||
|
action_date: string
|
||||||
|
has_success: boolean
|
||||||
|
}[]
|
||||||
|
}
|
||||||
get_medipost_dispatch_tries: {
|
get_medipost_dispatch_tries: {
|
||||||
Args: { p_medusa_order_id: string }
|
Args: { p_medusa_order_id: string }
|
||||||
Returns: number
|
Returns: number
|
||||||
@@ -2036,9 +2165,9 @@ export type Database = {
|
|||||||
Args: { account_id: string; user_id: string }
|
Args: { account_id: string; user_id: string }
|
||||||
Returns: boolean
|
Returns: boolean
|
||||||
}
|
}
|
||||||
medipost_retry_dispatch: {
|
order_has_medipost_dispatch_error: {
|
||||||
Args: { order_id: string }
|
Args: { medusa_order_id: string }
|
||||||
Returns: Json
|
Returns: boolean
|
||||||
}
|
}
|
||||||
revoke_nonce: {
|
revoke_nonce: {
|
||||||
Args: { p_id: string; p_reason?: string }
|
Args: { p_id: string; p_reason?: string }
|
||||||
@@ -2065,16 +2194,26 @@ export type Database = {
|
|||||||
Returns: undefined
|
Returns: undefined
|
||||||
}
|
}
|
||||||
update_account: {
|
update_account: {
|
||||||
Args: {
|
Args:
|
||||||
p_city: string
|
| {
|
||||||
p_has_consent_personal_data: boolean
|
p_city: string
|
||||||
p_last_name: string
|
p_email: string
|
||||||
p_name: string
|
p_has_consent_personal_data: boolean
|
||||||
p_personal_code: string
|
p_last_name: string
|
||||||
p_phone: string
|
p_name: string
|
||||||
p_uid: string
|
p_personal_code: string
|
||||||
p_email: string
|
p_phone: string
|
||||||
}
|
p_uid: string
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
p_city: string
|
||||||
|
p_has_consent_personal_data: boolean
|
||||||
|
p_last_name: string
|
||||||
|
p_name: string
|
||||||
|
p_personal_code: string
|
||||||
|
p_phone: string
|
||||||
|
p_uid: string
|
||||||
|
}
|
||||||
Returns: undefined
|
Returns: undefined
|
||||||
}
|
}
|
||||||
update_analysis_order_status: {
|
update_analysis_order_status: {
|
||||||
@@ -2182,6 +2321,11 @@ export type Database = {
|
|||||||
| "invites.manage"
|
| "invites.manage"
|
||||||
application_role: "user" | "doctor" | "super_admin"
|
application_role: "user" | "doctor" | "super_admin"
|
||||||
billing_provider: "stripe" | "lemon-squeezy" | "paddle" | "montonio"
|
billing_provider: "stripe" | "lemon-squeezy" | "paddle" | "montonio"
|
||||||
|
connected_online_order_status:
|
||||||
|
| "PENDING"
|
||||||
|
| "CONFIRMED"
|
||||||
|
| "REJECTED"
|
||||||
|
| "CANCELLED"
|
||||||
locale: "en" | "et" | "ru"
|
locale: "en" | "et" | "ru"
|
||||||
notification_channel: "in_app" | "email"
|
notification_channel: "in_app" | "email"
|
||||||
notification_type: "info" | "warning" | "error"
|
notification_type: "info" | "warning" | "error"
|
||||||
@@ -8099,6 +8243,12 @@ export const Constants = {
|
|||||||
],
|
],
|
||||||
application_role: ["user", "doctor", "super_admin"],
|
application_role: ["user", "doctor", "super_admin"],
|
||||||
billing_provider: ["stripe", "lemon-squeezy", "paddle", "montonio"],
|
billing_provider: ["stripe", "lemon-squeezy", "paddle", "montonio"],
|
||||||
|
connected_online_order_status: [
|
||||||
|
"PENDING",
|
||||||
|
"CONFIRMED",
|
||||||
|
"REJECTED",
|
||||||
|
"CANCELLED",
|
||||||
|
],
|
||||||
locale: ["en", "et", "ru"],
|
locale: ["en", "et", "ru"],
|
||||||
notification_channel: ["in_app", "email"],
|
notification_channel: ["in_app", "email"],
|
||||||
notification_type: ["info", "warning", "error"],
|
notification_type: ["info", "warning", "error"],
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ function Calendar({
|
|||||||
head_cell:
|
head_cell:
|
||||||
'text-muted-foreground rounded-md w-9 font-normal text-[0.8rem]',
|
'text-muted-foreground rounded-md w-9 font-normal text-[0.8rem]',
|
||||||
row: 'flex w-full mt-2',
|
row: 'flex w-full mt-2',
|
||||||
cell: 'text-center text-sm p-0 relative [&:has([aria-selected])]:bg-accent first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md focus-within:relative focus-within:z-20',
|
cell: 'text-center text-sm p-0 relative [&:has([aria-selected])]:bg-accent first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-md focus-within:relative focus-within:z-20',
|
||||||
day: cn(
|
day: cn(
|
||||||
buttonVariants({ variant: 'ghost' }),
|
buttonVariants({ variant: 'ghost' }),
|
||||||
'h-9 w-9 p-0 font-normal aria-selected:opacity-100',
|
'h-9 w-9 p-0 font-normal aria-selected:opacity-100',
|
||||||
|
|||||||
@@ -4,5 +4,7 @@
|
|||||||
"analysisPackages": {
|
"analysisPackages": {
|
||||||
"title": "Analysis packages",
|
"title": "Analysis packages",
|
||||||
"description": "Get to know the personal analysis packages and order"
|
"description": "Get to know the personal analysis packages and order"
|
||||||
}
|
},
|
||||||
|
"noCategories": "List of services not found, try again later",
|
||||||
|
"noResults": "No availabilities found for selected dates"
|
||||||
}
|
}
|
||||||
@@ -5,5 +5,13 @@
|
|||||||
"title": "Analüüside paketid",
|
"title": "Analüüside paketid",
|
||||||
"description": "Tutvu personaalsete analüüsi pakettidega ja telli"
|
"description": "Tutvu personaalsete analüüsi pakettidega ja telli"
|
||||||
},
|
},
|
||||||
"noCategories": "Teenuste loetelu ei leitud, proovi hiljem uuesti"
|
"noCategories": "Teenuste loetelu ei leitud, proovi hiljem uuesti",
|
||||||
}
|
"noResults": "Valitud kuupäevadel ei ole vabu aegu",
|
||||||
|
"services": "Teenused",
|
||||||
|
"locations": "Asutused",
|
||||||
|
"showAll": "Kuva kõik",
|
||||||
|
"showAllLocations": "Näita kõiki asutusi",
|
||||||
|
"bookTimeSuccess": "Aeg valitud",
|
||||||
|
"bookTimeError": "Aega ei õnnestunud valida",
|
||||||
|
"bookTimeLoading": "Aega valitakse..."
|
||||||
|
}
|
||||||
@@ -14,7 +14,9 @@
|
|||||||
"goToDashboard": "Jätkan",
|
"goToDashboard": "Jätkan",
|
||||||
"error": {
|
"error": {
|
||||||
"title": "Midagi läks valesti",
|
"title": "Midagi läks valesti",
|
||||||
"description": "Palun proovi hiljem uuesti."
|
"description": "Palun proovi hiljem uuesti.",
|
||||||
|
"BOOKING_FAILED": "Teenuse tõrge, proovi hiljem uuesti.",
|
||||||
|
"TIME_SLOT_UNAVAILABLE": "Valitud aeg ei ole saadaval."
|
||||||
},
|
},
|
||||||
"timeLeft": "Aega jäänud {{timeLeft}}",
|
"timeLeft": "Aega jäänud {{timeLeft}}",
|
||||||
"timeoutTitle": "Broneering aegus",
|
"timeoutTitle": "Broneering aegus",
|
||||||
|
|||||||
@@ -147,5 +147,6 @@
|
|||||||
"language": "Keel",
|
"language": "Keel",
|
||||||
"yes": "Jah",
|
"yes": "Jah",
|
||||||
"no": "Ei",
|
"no": "Ei",
|
||||||
"preferNotToAnswer": "Eelistan mitte vastata"
|
"preferNotToAnswer": "Eelistan mitte vastata",
|
||||||
|
"book": "Broneeri"
|
||||||
}
|
}
|
||||||
@@ -4,17 +4,33 @@
|
|||||||
"noOrders": "Tellimusi ei leitud",
|
"noOrders": "Tellimusi ei leitud",
|
||||||
"table": {
|
"table": {
|
||||||
"analysisPackage": "Analüüsi pakett",
|
"analysisPackage": "Analüüsi pakett",
|
||||||
|
"ttoService": "Broneering",
|
||||||
"otherOrders": "Tellimus",
|
"otherOrders": "Tellimus",
|
||||||
"createdAt": "Tellitud",
|
"createdAt": "Tellitud",
|
||||||
"status": "Olek"
|
"status": "Olek"
|
||||||
},
|
},
|
||||||
"status": {
|
"status": {
|
||||||
"QUEUED": "Esitatud",
|
"QUEUED": "Esitatud",
|
||||||
"PROCESSING": "Synlabile edastatud",
|
"PROCESSING": "Edastatud",
|
||||||
"PARTIAL_ANALYSIS_RESPONSE": "Osalised tulemused",
|
"PARTIAL_ANALYSIS_RESPONSE": "Osalised tulemused",
|
||||||
"FULL_ANALYSIS_RESPONSE": "Kõik tulemused käes, ootab arsti kokkuvõtet",
|
"FULL_ANALYSIS_RESPONSE": "Kõik tulemused käes",
|
||||||
"COMPLETED": "Kinnitatud",
|
"COMPLETED": "Kinnitatud",
|
||||||
"REJECTED": "Tagastatud",
|
"REJECTED": "Tagastatud",
|
||||||
"CANCELLED": "Tühistatud"
|
"CANCELLED": "Tühistatud",
|
||||||
|
"analysisOrder": {
|
||||||
|
"QUEUED": "Esitatud",
|
||||||
|
"PROCESSING": "Synlabile edastatud",
|
||||||
|
"PARTIAL_ANALYSIS_RESPONSE": "Osalised tulemused",
|
||||||
|
"FULL_ANALYSIS_RESPONSE": "Kõik tulemused käes, ootab arsti kokkuvõtet",
|
||||||
|
"COMPLETED": "Kinnitatud",
|
||||||
|
"REJECTED": "Tagastatud",
|
||||||
|
"CANCELLED": "Tühistatud"
|
||||||
|
},
|
||||||
|
"ttoService": {
|
||||||
|
"PENDING": "Alustatud",
|
||||||
|
"CONFIRMED": "Kinnitatud",
|
||||||
|
"REJECTED": "Tagasi lükatud",
|
||||||
|
"CANCELLED": "Tühistatud"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,5 +5,6 @@
|
|||||||
"title": "Пакеты анализов",
|
"title": "Пакеты анализов",
|
||||||
"description": "Ознакомьтесь с персональными пакетами анализов и закажите"
|
"description": "Ознакомьтесь с персональными пакетами анализов и закажите"
|
||||||
},
|
},
|
||||||
"noCategories": "Список услуг не найден, попробуйте позже"
|
"noCategories": "Список услуг не найден, попробуйте позже",
|
||||||
}
|
"noResults": "Для выбранных дат доступных вариантов не найдено"
|
||||||
|
}
|
||||||
11
supabase/migrations/20250908092531_add_clinic_key.sql
Normal file
11
supabase/migrations/20250908092531_add_clinic_key.sql
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
ALTER TABLE medreport.connected_online_providers ADD COLUMN key text not null DEFAULT ''; -- avoid conflict with already existing data, will be filled on next sync
|
||||||
|
ALTER TABLE medreport.connected_online_providers
|
||||||
|
ALTER key DROP DEFAULT;
|
||||||
|
|
||||||
|
ALTER TABLE medreport.connected_online_providers ADD COLUMN address text not null DEFAULT '';
|
||||||
|
ALTER TABLE medreport.connected_online_providers
|
||||||
|
ALTER key DROP DEFAULT;
|
||||||
|
|
||||||
|
ALTER TABLE medreport.connected_online_services
|
||||||
|
ALTER COLUMN sync_id TYPE bigint
|
||||||
|
USING sync_id::bigint;
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
create table "medreport"."connected_online_service_providers" (
|
||||||
|
"id" bigint not null primary key,
|
||||||
|
"name" text not null,
|
||||||
|
"spoken_languages" text[],
|
||||||
|
"prefix" text,
|
||||||
|
"job_title_et" text,
|
||||||
|
"job_title_en" text,
|
||||||
|
"job_title_ru" text,
|
||||||
|
"clinic_id" bigint not null REFERENCES medreport.connected_online_providers(id),
|
||||||
|
"job_title_id" bigint,
|
||||||
|
"is_deleted" boolean,
|
||||||
|
"created_at" timestamp with time zone not null default now(),
|
||||||
|
"updated_at" timestamp without time zone default now()
|
||||||
|
);
|
||||||
|
|
||||||
|
ALTER TABLE audit.request_entries
|
||||||
|
DROP COLUMN personal_code;
|
||||||
|
|
||||||
|
ALTER TABLE audit.request_entries ADD COLUMN user_id uuid default auth.uid() references auth.users(id);
|
||||||
|
|
||||||
|
create policy "insert_own"
|
||||||
|
on "audit"."request_entries"
|
||||||
|
as permissive
|
||||||
|
for insert
|
||||||
|
to authenticated
|
||||||
|
with check ((( SELECT auth.uid() AS uid) = user_id));
|
||||||
|
|
||||||
|
alter table "medreport"."connected_online_service_providers" enable row level security;
|
||||||
|
|
||||||
|
create policy "service_role_all"
|
||||||
|
on "medreport"."connected_online_service_providers"
|
||||||
|
as permissive
|
||||||
|
for all
|
||||||
|
to service_role
|
||||||
|
using (true);
|
||||||
|
|
||||||
|
|
||||||
|
grant delete on table "medreport"."connected_online_service_providers" to "service_role";
|
||||||
|
|
||||||
|
grant insert on table "medreport"."connected_online_service_providers" to "service_role";
|
||||||
|
|
||||||
|
grant references on table "medreport"."connected_online_service_providers" to "service_role";
|
||||||
|
|
||||||
|
grant select on table "medreport"."connected_online_service_providers" to "service_role";
|
||||||
|
|
||||||
|
grant trigger on table "medreport"."connected_online_service_providers" to "service_role";
|
||||||
|
|
||||||
|
grant truncate on table "medreport"."connected_online_service_providers" to "service_role";
|
||||||
|
|
||||||
|
grant update on table "medreport"."connected_online_service_providers" to "service_role";
|
||||||
|
|
||||||
|
grant select on table "medreport"."connected_online_service_providers" to "authenticated";
|
||||||
|
|
||||||
|
|
||||||
|
create policy "authenticated_select"
|
||||||
|
on "medreport"."connected_online_service_providers"
|
||||||
|
as permissive
|
||||||
|
for select
|
||||||
|
to authenticated
|
||||||
|
using (true);
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
ALTER TABLE medreport.connected_online_reservation
|
||||||
|
ADD COLUMN medusa_cart_line_item_id TEXT references public.cart_line_item(id);
|
||||||
|
|
||||||
|
ALTER TABLE medreport.connected_online_reservation
|
||||||
|
ADD COLUMN location_sync_id bigint;
|
||||||
|
|
||||||
|
create type medreport.connected_online_order_status as enum ('PENDING', 'CONFIRMED', 'REJECTED', 'CANCELLED');
|
||||||
|
|
||||||
|
ALTER TABLE medreport.connected_online_reservation
|
||||||
|
ADD COLUMN status medreport.connected_online_order_status not null;
|
||||||
|
|
||||||
|
ALTER TABLE medreport.connected_online_reservation ALTER COLUMN booking_code DROP NOT NULL;
|
||||||
|
ALTER TABLE medreport.connected_online_reservation ALTER COLUMN requires_payment DROP NOT NULL;
|
||||||
|
ALTER TABLE medreport.connected_online_reservation ALTER COLUMN service_user_id SET NOT NULL;
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
create table "medreport"."connected_online_locations" (
|
||||||
|
"id" bigint generated by default as identity not null,
|
||||||
|
"sync_id" bigint not null,
|
||||||
|
"name" text not null,
|
||||||
|
"address" text,
|
||||||
|
"clinic_id" bigint not null REFERENCES medreport.connected_online_providers(id),
|
||||||
|
"created_at" timestamp with time zone not null default now(),
|
||||||
|
"updated_at" timestamp without time zone default now()
|
||||||
|
);
|
||||||
|
|
||||||
|
alter table "medreport"."connected_online_locations" enable row level security;
|
||||||
|
|
||||||
|
create policy "service_role_all"
|
||||||
|
on "medreport"."connected_online_locations"
|
||||||
|
as permissive
|
||||||
|
for all
|
||||||
|
to service_role
|
||||||
|
using (true);
|
||||||
|
|
||||||
|
|
||||||
|
grant delete on table "medreport"."connected_online_locations" to "service_role";
|
||||||
|
|
||||||
|
grant insert on table "medreport"."connected_online_locations" to "service_role";
|
||||||
|
|
||||||
|
grant references on table "medreport"."connected_online_locations" to "service_role";
|
||||||
|
|
||||||
|
grant select on table "medreport"."connected_online_locations" to "service_role";
|
||||||
|
|
||||||
|
grant trigger on table "medreport"."connected_online_locations" to "service_role";
|
||||||
|
|
||||||
|
grant truncate on table "medreport"."connected_online_locations" to "service_role";
|
||||||
|
|
||||||
|
grant update on table "medreport"."connected_online_locations" to "service_role";
|
||||||
|
|
||||||
|
grant select on table "medreport"."connected_online_locations" to "authenticated";
|
||||||
|
|
||||||
|
|
||||||
|
create policy "authenticated_select"
|
||||||
|
on "medreport"."connected_online_locations"
|
||||||
|
as permissive
|
||||||
|
for select
|
||||||
|
to authenticated
|
||||||
|
using (true);
|
||||||
Reference in New Issue
Block a user