@@ -30,43 +30,44 @@ import { eq, getTableColumns, sql, and } from "drizzle-orm";
3030import { db } from "@/database/db" ;
3131import { ConfigTable , SlackInstallationTable } from "@/database/schema.sql" ;
3232import { useQuery } from "@tanstack/react-query" ;
33+ import { trpc } from "@/lib/trpc" ;
3334
34- const feeds = createServerFn ( { method : "GET" } )
35- . validator ( z . object ( { teamId : z . string ( ) } ) )
36- . handler ( async ( { data } ) => {
37- // const { userId } = await getAuth(getWebRequest());
38- // const clerk = await clerkClient({
39- // secretKey: Resource.ClerkSecretKey.value,
40- // });
41- // const accessTokens = (await clerk.users.getUserOauthAccessToken(userId!, "oauth_slack")).data;
42- // const token = accessTokens[0].token || "";
43- // const userInfo = await client.openid.connect.userInfo({
44- // token,
45- // });
46- const teamConfigs = await db
47- . select ( { ...getTableColumns ( ConfigTable ) , teamId : SlackInstallationTable . teamId } )
48- . from ( ConfigTable )
49- . innerJoin ( SlackInstallationTable , eq ( ConfigTable . installationId , SlackInstallationTable . id ) )
50- . where ( eq ( SlackInstallationTable . teamId , data . teamId ) ) ;
51- const products = await getFeeds ( ) ;
52- const services = await products . reduce (
53- async ( acc , product ) => {
54- const services = await product . getServices ( ) ;
55- return {
56- ...( await acc ) ,
57- [ product . name ] : services ,
58- } ;
59- } ,
60- Promise . resolve ( { } as Record < string , IService [ ] > ) ,
61- ) ;
62- const productsWithServices = products . map ( ( product ) => ( {
63- name : product . name ,
64- displayName : product . displayName ,
65- logo : product . logo ,
66- services : services [ product . name ] ,
67- } ) ) ;
68- return { products : productsWithServices , teamConfigs } ;
69- } ) ;
35+ // const feeds = createServerFn({ method: "GET" })
36+ // .validator(z.object({ teamId: z.string() }))
37+ // .handler(async ({ data }) => {
38+ // // const { userId } = await getAuth(getWebRequest());
39+ // // const clerk = await clerkClient({
40+ // // secretKey: Resource.ClerkSecretKey.value,
41+ // // });
42+ // // const accessTokens = (await clerk.users.getUserOauthAccessToken(userId!, "oauth_slack")).data;
43+ // // const token = accessTokens[0].token || "";
44+ // // const userInfo = await client.openid.connect.userInfo({
45+ // // token,
46+ // // });
47+ // const teamConfigs = await db
48+ // .select({ ...getTableColumns(ConfigTable), teamId: SlackInstallationTable.teamId })
49+ // .from(ConfigTable)
50+ // .innerJoin(SlackInstallationTable, eq(ConfigTable.installationId, SlackInstallationTable.id))
51+ // .where(eq(SlackInstallationTable.teamId, data.teamId));
52+ // const products = await getFeeds();
53+ // const services = await products.reduce(
54+ // async (acc, product) => {
55+ // const services = await product.getServices();
56+ // return {
57+ // ...(await acc),
58+ // [product.name]: services,
59+ // };
60+ // },
61+ // Promise.resolve({} as Record<string, IService[]>),
62+ // );
63+ // const productsWithServices = products.map((product) => ({
64+ // name: product.name,
65+ // displayName: product.displayName,
66+ // logo: product.logo,
67+ // services: services[product.name],
68+ // }));
69+ // return { products: productsWithServices, teamConfigs };
70+ // });
7071
7172const toggleService = createServerFn ( { method : "POST" } )
7273 . validator ( z . object ( { product : z . string ( ) , service : z . string ( ) , installationId : z . number ( ) } ) )
@@ -104,7 +105,7 @@ const toggleService = createServerFn({ method: "POST" })
104105
105106export const Route = createFileRoute ( "/_authed/config" ) ( {
106107 component : ConfigComponent ,
107- loader : ( { context } ) => feeds ( { data : { teamId : context . teamId } } ) ,
108+ loader : ( { context } ) => ( { teamId : context . teamId } ) ,
108109} ) ;
109110
110111// This would typically come from your API
@@ -137,7 +138,9 @@ export const Route = createFileRoute("/_authed/config")({
137138// ];
138139
139140function ConfigComponent ( ) {
140- const { products, teamConfigs } = Route . useLoaderData ( ) ;
141+ // const { products, teamConfigs } = Route.useLoaderData();
142+ const { teamId } = Route . useLoaderData ( ) ;
143+ const configQuery = trpc . getFeedsAndConfigs . useQuery ( { teamId } ) ;
141144 const [ expandedProducts , setExpandedProducts ] = useState < Set < string > > ( new Set ( ) ) ;
142145 const [ enabledServices , setEnabledServices ] = useState < Set < string > > ( new Set ( ) ) ;
143146 const [ searchQuery , setSearchQuery ] = useState ( "" ) ;
@@ -155,13 +158,13 @@ function ConfigComponent() {
155158
156159 const toggleService = ( productId : string , serviceId : string ) => {
157160 const productKey = `${ productId } -${ serviceId } ` ;
158- const newEnabled = new Set ( enabledProducts ) ;
159- if ( newEnabled . has ( productKey ) ) {
160- newEnabled . delete ( productKey ) ;
161- } else {
162- newEnabled . add ( productKey ) ;
163- }
164- setEnabledProducts ( newEnabled ) ;
161+ // const newEnabled = new Set(enabledProducts);
162+ // if (newEnabled.has(productKey)) {
163+ // newEnabled.delete(productKey);
164+ // } else {
165+ // newEnabled.add(productKey);
166+ // }
167+ // setEnabledProducts(newEnabled);
165168 } ;
166169
167170 const getIconForProduct = ( productId : string , serviceId : string ) => {
@@ -195,6 +198,7 @@ function ConfigComponent() {
195198 return < Cloud className = "h-5 w-5" /> ;
196199 } ;
197200
201+ const products = useMemo ( ( ) => configQuery . data ?. products || [ ] , [ configQuery . data ] ) ;
198202 const filteredProducts = useMemo (
199203 ( ) =>
200204 products . filter (
0 commit comments