Skip to content

Commit

Permalink
🐛 Fix mapping bug
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed May 6, 2024
1 parent 76edcda commit c3a2c05
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { useForm } from "react-hook-form"
import * as z from "zod"
import { usePostHog } from 'posthog-js/react'
import config from "@/lib/config"
import { CRM_PROVIDERS } from "@panora/shared"


const defineFormSchema = z.object({
Expand Down Expand Up @@ -110,7 +111,8 @@ export function FModal({ onClose }: {onClose: () => void}) {
const { mutate: mutateDefineField } = useDefineFieldMutation();
const { mutate: mutateMapField } = useMapFieldMutation();
const { data: linkedUsers } = useLinkedUsers();
const { data: sourceCustomFields, error, isLoading } = useProviderProperties(linkedUserId,sourceProvider);
// TODO: HANDLE VERTICAL AND PROVIDERS FOR CUSTOM MAPPINGS
const { data: sourceCustomFields, error, isLoading } = useProviderProperties(linkedUserId,sourceProvider, "crm");

const posthog = usePostHog()

Expand Down Expand Up @@ -330,12 +332,12 @@ export function FModal({ onClose }: {onClose: () => void}) {
<SelectValue placeholder="Select a provider" />
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectItem value="hubspot">Hubspot</SelectItem>
<SelectItem value="zendesk">Zendesk</SelectItem>
<SelectItem value="slack">Slack</SelectItem>
<SelectItem value="asana">Asana</SelectItem>
<SelectItem value="zoho">Zoho</SelectItem>
<SelectGroup>
{
CRM_PROVIDERS.map((provider) =>
<SelectItem value={provider} key={provider}>{provider}</SelectItem>
)
}
</SelectGroup>
</SelectContent>
</Select>
Expand Down
6 changes: 3 additions & 3 deletions apps/client-ts/src/hooks/useProviderProperties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import config from '@/lib/config';
import { useQuery } from '@tanstack/react-query';
import Cookies from 'js-cookie';

const useProviderProperties = (linkedUserId: string, providerId: string) => {
const useProviderProperties = (linkedUserId: string, providerId: string, vertical: string) => {
return useQuery({
queryKey: ['providerProperties', linkedUserId, providerId],
queryKey: ['providerProperties', linkedUserId, providerId, vertical],
queryFn: async () => {
const response = await fetch(`${config.API_URL}/field-mappings/properties?linkedUserId=${linkedUserId}&providerId=${providerId}`,
const response = await fetch(`${config.API_URL}/field-mappings/properties?linkedUserId=${linkedUserId}&providerId=${providerId}&vertical=${vertical}`,
{
method: 'GET',
headers: {
Expand Down
15 changes: 14 additions & 1 deletion packages/api/src/@core/field-mapping/field-mapping.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ export class FieldMappingService {
vertical: string,
) {
try {
this.logger.log(
'data to test is => ' +
JSON.stringify({
providerId,
vertical,
}),
);
const connection = await this.prisma.connections.findFirst({
where: {
id_linked_user: linkedUserId,
Expand All @@ -139,8 +146,13 @@ export class FieldMappingService {
if (!provider.urls.apiUrl || !provider.urls.customPropertiesUrl)
throw new Error('proivder urls are invalid');

this.logger.log(
'url for properties is ' +
provider.urls.apiUrl +
provider.urls.customPropertiesUrl,
);
const resp = await axios.get(
provider.urls.apiUrl + provider.urls.customPropertiesUrl,
'https://api.hubapi.com/properties/v1/contacts/properties', // todo : provider.urls.apiUrl + provider.urls.customPropertiesUrl,
{
headers: {
'Content-Type': 'application/json',
Expand All @@ -150,6 +162,7 @@ export class FieldMappingService {
},
},
);
this.logger.log('properties are ' + JSON.stringify(resp.data));
return {
data: resp.data,
message: `${providerId} contact properties retrieved`,
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const providersConfig: ProvidersConfig = {
docsUrl: 'https://developers.hubspot.com/docs/api/crm/understanding-the-crm',
authBaseUrl: 'https://app-eu1.hubspot.com/oauth/authorize',
apiUrl: 'https://api.hubapi.com/crm/v3',
customPropertiesUrl: '/properties/v1/contacts/properties',
customPropertiesUrl: '/properties/contacts',
},
logoPath: 'https://assets-global.website-files.com/6421a177cdeeaf3c6791b745/64d61202dd99e63d40d446f6_hubspot%20logo.png',
description: 'Sync & Create contacts, deals, companies, notes, engagements, stages, tasks and users',
Expand Down

0 comments on commit c3a2c05

Please sign in to comment.