MED-105: create analysis results page
This commit is contained in:
@@ -14,7 +14,8 @@
|
||||
"./personal-account-settings": "./src/components/personal-account-settings/index.ts",
|
||||
"./components": "./src/components/index.ts",
|
||||
"./hooks/*": "./src/hooks/*.ts",
|
||||
"./api": "./src/server/api.ts"
|
||||
"./api": "./src/server/api.ts",
|
||||
"./types/*": "./src/types/*.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"nanoid": "^5.1.5"
|
||||
|
||||
@@ -2,6 +2,8 @@ import { SupabaseClient } from '@supabase/supabase-js';
|
||||
|
||||
import { Database } from '@kit/supabase/database';
|
||||
|
||||
import { UserAnalysis } from '../types/accounts';
|
||||
|
||||
/**
|
||||
* Class representing an API for interacting with user accounts.
|
||||
* @constructor
|
||||
@@ -117,6 +119,7 @@ class AccountsApi {
|
||||
*/
|
||||
async getSubscription(accountId: string) {
|
||||
const response = await this.client
|
||||
.schema('medreport')
|
||||
.from('subscriptions')
|
||||
.select('*, items: subscription_items !inner (*)')
|
||||
.eq('account_id', accountId)
|
||||
@@ -168,6 +171,51 @@ class AccountsApi {
|
||||
|
||||
return response.data?.customer_id;
|
||||
}
|
||||
|
||||
async getUserAnalysis(): Promise<UserAnalysis | null> {
|
||||
const authUser = await this.client.auth.getUser();
|
||||
const { data, error: userError } = authUser;
|
||||
|
||||
if (userError) {
|
||||
console.error('Failed to get user', userError);
|
||||
throw userError;
|
||||
}
|
||||
|
||||
const { user } = data;
|
||||
|
||||
const { data: analysisResponses } = await this.client
|
||||
.schema('medreport')
|
||||
.from('analysis_responses')
|
||||
.select('*')
|
||||
.eq('user_id', user.id);
|
||||
|
||||
if (!analysisResponses) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const analysisResponseIds = analysisResponses.map((r) => r.id);
|
||||
|
||||
const { data: analysisResponseElements } = await this.client
|
||||
.schema('medreport')
|
||||
.from('analysis_response_elements')
|
||||
.select('*')
|
||||
.in('analysis_response_id', analysisResponseIds);
|
||||
|
||||
if (!analysisResponseElements) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const elementMap = new Map(
|
||||
analysisResponseElements.map((e) => [e.analysis_response_id, e]),
|
||||
);
|
||||
|
||||
return analysisResponses
|
||||
.filter((r) => elementMap.has(r.id))
|
||||
.map((r) => ({
|
||||
...r,
|
||||
element: elementMap.get(r.id)!,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
export function createAccountsApi(client: SupabaseClient<Database>) {
|
||||
|
||||
6
packages/features/accounts/src/types/accounts.ts
Normal file
6
packages/features/accounts/src/types/accounts.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { Database } from '@kit/supabase/database';
|
||||
|
||||
export type UserAnalysis =
|
||||
(Database['medreport']['Tables']['analysis_responses']['Row'] & {
|
||||
element: Database['medreport']['Tables']['analysis_response_elements']['Row'];
|
||||
})[];
|
||||
@@ -1,14 +1,14 @@
|
||||
import Medusa from "@medusajs/js-sdk"
|
||||
import Medusa from "@medusajs/js-sdk";
|
||||
|
||||
// Defaults to standard port for Medusa server
|
||||
let MEDUSA_BACKEND_URL = "http://localhost:9000"
|
||||
let MEDUSA_BACKEND_URL = "http://localhost:9000";
|
||||
|
||||
if (process.env.MEDUSA_BACKEND_URL) {
|
||||
MEDUSA_BACKEND_URL = process.env.MEDUSA_BACKEND_URL
|
||||
MEDUSA_BACKEND_URL = process.env.MEDUSA_BACKEND_URL;
|
||||
}
|
||||
|
||||
console.log("MEDUSA_BACKEND_URL", MEDUSA_BACKEND_URL);
|
||||
export const sdk = new Medusa({
|
||||
baseUrl: MEDUSA_BACKEND_URL,
|
||||
debug: process.env.NODE_ENV === "development",
|
||||
publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
|
||||
})
|
||||
});
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -37,16 +37,12 @@ function PageWithSidebar(props: PageProps) {
|
||||
<div
|
||||
className={
|
||||
props.contentContainerClassName ??
|
||||
'mx-auto flex h-screen w-full flex-col overflow-y-auto bg-inherit'
|
||||
'mx-auto flex h-screen w-full flex-col bg-inherit'
|
||||
}
|
||||
>
|
||||
{MobileNavigation}
|
||||
|
||||
<div
|
||||
className={
|
||||
'bg-background flex flex-1 flex-col overflow-y-auto px-4 lg:px-0'
|
||||
}
|
||||
>
|
||||
<div className={'bg-background flex flex-1 flex-col px-4 lg:px-0'}>
|
||||
{Children}
|
||||
</div>
|
||||
</div>
|
||||
@@ -75,7 +71,7 @@ function PageWithHeader(props: PageProps) {
|
||||
const { Navigation, Children, MobileNavigation } = getSlotsFromPage(props);
|
||||
|
||||
return (
|
||||
<div className={cn('flex h-screen flex-1 flex-col z-900', props.className)}>
|
||||
<div className={cn('z-900 flex h-screen flex-1 flex-col', props.className)}>
|
||||
<div
|
||||
className={
|
||||
props.contentContainerClassName ?? 'flex flex-1 flex-col space-y-4'
|
||||
@@ -83,7 +79,7 @@ function PageWithHeader(props: PageProps) {
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
'bg-bg-background border-1 light:border-border dark:border-border dark:shadow-primary/10 flex h-15 items-center justify-between px-4 py-1 lg:justify-start lg:shadow-xs border-b',
|
||||
'bg-bg-background light:border-border dark:border-border dark:shadow-primary/10 flex h-15 items-center justify-between border-1 border-b px-4 py-1 lg:justify-start lg:shadow-xs',
|
||||
{
|
||||
'sticky top-0 z-1000 backdrop-blur-md': props.sticky ?? true,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user