Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Bamboohr + woocomerce integration #631

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 4 additions & 119 deletions apps/magic-link/src/lib/ProviderModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
} from "@/components/ui/dialog"
import useCreateApiKeyConnection from '@/hooks/queries/useCreateApiKeyConnection';

interface IApiKeyFormData {
apikey: string;
[key : string]: string
}

interface IBasicAuthFormData {
[key : string]: string
Expand All @@ -48,7 +44,6 @@
}>({provider:'',category:''});
const [startFlow, setStartFlow] = useState<boolean>(false);
const [preStartFlow, setPreStartFlow] = useState<boolean>(false);
const [openApiKeyDialog,setOpenApiKeyDialog] = useState<boolean>(false);
const [openBasicAuthDialog,setOpenBasicAuthDialog] = useState<boolean>(false);
const [openDomainDialog, setOpenDomainDialog] = useState<boolean>(false);
const [projectId, setProjectId] = useState<string>("");
Expand Down Expand Up @@ -76,8 +71,6 @@
const {mutate : createApiKeyConnection} = useCreateApiKeyConnection();
const {data: magicLink} = useUniqueMagicLink(uniqueMagicLinkId);
const {data: connectorsForProject} = useProjectConnectors(isProjectIdReady ? projectId : null);

const {register,formState: {errors},handleSubmit,reset} = useForm<IApiKeyFormData>();
const {register: register2, formState: {errors: errors2}, handleSubmit: handleSubmit2, reset: reset2} = useForm<IBasicAuthFormData>();

useEffect(() => {
Expand Down Expand Up @@ -177,7 +170,7 @@
provider: ''
});
}
}, [startFlow, isReady]);

Check warning on line 173 in apps/magic-link/src/lib/ProviderModal.tsx

View workflow job for this annotation

GitHub Actions / Build and Test (18.x)

React Hook useEffect has a missing dependency: 'open'. Either include it or remove the dependency array



Expand All @@ -191,9 +184,7 @@

const handleStartFlow = () => {
const providerMetadata = CONNECTORS_METADATA[selectedProvider.category][selectedProvider.provider];
if (providerMetadata.authStrategy.strategy === AuthStrategy.api_key) {
setOpenApiKeyDialog(true);
} else if(providerMetadata.authStrategy.strategy === AuthStrategy.basic) {
if (providerMetadata.authStrategy.strategy === AuthStrategy.api_key || providerMetadata.authStrategy.strategy === AuthStrategy.basic) {
setOpenBasicAuthDialog(true);
} else if (providerMetadata?.options?.end_user_domain) {
setOpenDomainDialog(true);
Expand Down Expand Up @@ -237,60 +228,11 @@
});
}

const onCloseApiKeyDialog = (dialogState : boolean) => {
setOpenApiKeyDialog(dialogState);
reset();
}

const onCloseBasicAuthDialog = (dialogState : boolean) => {
setOpenBasicAuthDialog(dialogState);
reset2();
}


const onApiKeySubmit = (values: IApiKeyFormData) => {
// const extraFields = getValues()
onCloseApiKeyDialog(false);
setLoading({status: true, provider: selectedProvider?.provider!});
setPreStartFlow(false);

// Creating API Key Connection
createApiKeyConnection({
query : {
linkedUserId: magicLink?.id_linked_user as string,
projectId: projectId,
providerName: selectedProvider?.provider!,
vertical: selectedProvider?.category!
},
data: values
},
{
onSuccess: () => {
setSelectedProvider({
provider: '',
category: ''
});

setLoading({
status: false,
provider: ''
});
setOpenSuccessDialog(true);
},
onError: (error) => {
setErrorResponse({errorPresent:true,errorMessage: error.message});
setLoading({
status: false,
provider: ''
});
setSelectedProvider({
provider: '',
category: ''
});
}
});
}

const onBasicAuthSubmit = (values: IBasicAuthFormData) => {
onCloseBasicAuthDialog(false);
setLoading({status: true, provider: selectedProvider?.provider!});
Expand Down Expand Up @@ -402,63 +344,6 @@
</CardFooter>
</Card>

{/* Dialog for apikey input */}
<Dialog open={openApiKeyDialog} onOpenChange={onCloseApiKeyDialog}>
<DialogContent>
<DialogHeader>
<DialogTitle>Enter a API key</DialogTitle>
</DialogHeader>
{/* <Form {...form}> */}
<form onSubmit={handleSubmit(onApiKeySubmit)}>
<div className="grid gap-4 py-4">
<div className="grid gap-2">
<Label className={errors.apikey ? 'text-destructive' : ''}>Enter your API key for {selectedProvider?.provider.substring(0,1).toUpperCase()}{selectedProvider?.provider.substring(1)}</Label>
<Input
className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
placeholder="Your api key"
{...register('apikey',{
required: 'Api Key must be at least 2 characters',
minLength: {
value:2,
message: 'Api Key must be at least 2 characters'
}

})}
/>
<div>{errors.apikey && (<p className='text-sm font-medium text-destructive'>{errors.apikey.message}</p>)}</div>
{/* </div> */}
{selectedProvider.provider!=='' && selectedProvider.category!=='' && CONNECTORS_METADATA[selectedProvider.category][selectedProvider.provider].authStrategy.properties?.map((fieldName : string) =>
(
<>
<Label className={errors[fieldName] ? 'text-destructive' : ''}>Enter your {fieldName} for {selectedProvider?.provider}</Label>
<Input
type='text'
placeholder={`Your ${fieldName}`}
className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
{...register(fieldName,{
required: `${fieldName} must be at least 2 characters`,
minLength:{
value:2,
message: `${fieldName} must be at least 2 characters`,
}
})}
/>
{errors[fieldName] && (<p className='text-sm font-medium text-destructive'>{errors[fieldName]?.message}</p>)}
</>
))}
</div>
</div>
<DialogFooter>
<Button variant='outline' type="reset" size="sm" className="h-7 gap-1" onClick={() => onCloseApiKeyDialog(false)}>Cancel</Button>
<Button type='submit' size="sm" className="h-7 gap-1">
Continue
</Button>
</DialogFooter>
</form>
{/* </Form> */}
</DialogContent>
</Dialog>

{/* Dialog for basic auth input */}
<Dialog open={openBasicAuthDialog} onOpenChange={onCloseBasicAuthDialog}>
<DialogContent>
Expand All @@ -472,7 +357,7 @@
{selectedProvider.provider!=='' && selectedProvider.category!=='' && CONNECTORS_METADATA[selectedProvider.category][selectedProvider.provider].authStrategy.properties?.map((fieldName : string) =>
(
<>
<Label className={errors2[fieldName] ? 'text-destructive' : ''}>Enter your API Key for {selectedProvider?.provider.substring(0,1).toUpperCase()}{selectedProvider?.provider.substring(1)}</Label>
<Label className={errors2[fieldName] ? 'text-destructive' : ''}>Enter your {fieldName} for {selectedProvider?.provider.substring(0,1).toUpperCase()}{selectedProvider?.provider.substring(1)}</Label>
<Input
type='text'
placeholder={`Your ${fieldName}`}
Expand Down Expand Up @@ -510,7 +395,7 @@
<form onSubmit={(e) => { e.preventDefault(); onDomainSubmit(); }}>
<div className="grid gap-4 py-4">
<div className="grid gap-2">
<Label className={errors.end_user_domain ? 'text-destructive' : ''}>
<Label className={errors2.end_user_domain ? 'text-destructive' : ''}>
Enter your domain for {`${selectedProvider?.provider.substring(0,1).toUpperCase()}${selectedProvider?.provider.substring(1)}`}
{domainFormats[selectedProvider?.provider.toLowerCase()] && (
<span className="text-sm text-gray-500"> (e.g., {domainFormats[selectedProvider?.provider.toLowerCase()]})</span>
Expand All @@ -521,7 +406,7 @@
placeholder="Your domain"
onChange={(e) => setEndUserDomain(e.target.value)}
/>
<div>{errors.end_user_domain && (<p className='text-sm font-medium text-destructive'>{errors.end_user_domain.message}</p>)}</div>
<div>{errors2.end_user_domain && (<p className='text-sm font-medium text-destructive'>{errors2.end_user_domain.message}</p>)}</div>
</div>
</div>
<DialogFooter>
Expand Down
19 changes: 9 additions & 10 deletions packages/api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ model crm_contacts {
model crm_deals {
id_crm_deal String @id(map: "pk_crm_deal") @db.Uuid
name String
description String
description String?
amount BigInt
created_at DateTime @db.Timestamp(6)
modified_at DateTime @db.Timestamp(6)
Expand Down Expand Up @@ -503,6 +503,7 @@ model tcg_collections {
remote_platform String?
collection_type String?
parent_collection String? @db.Uuid
id_tcg_ticket String? @db.Uuid
created_at DateTime @db.Timestamp(6)
modified_at DateTime @db.Timestamp(6)
id_linked_user String @db.Uuid
Expand All @@ -517,14 +518,14 @@ model tcg_comments {
is_private Boolean?
remote_id String?
remote_platform String?
created_at DateTime? @db.Timestamp(6)
modified_at DateTime? @db.Timestamp(6)
creator_type String?
id_tcg_attachment String[]
id_tcg_ticket String? @db.Uuid
id_tcg_contact String? @db.Uuid
id_tcg_user String? @db.Uuid
id_linked_user String? @db.Uuid
created_at DateTime? @db.Timestamp(6)
modified_at DateTime? @db.Timestamp(6)
id_connection String @db.Uuid
tcg_attachments tcg_attachments[]
tcg_tickets tcg_tickets? @relation(fields: [id_tcg_ticket], references: [id_tcg_ticket], onDelete: NoAction, onUpdate: NoAction, map: "fk_40_1")
Expand Down Expand Up @@ -595,14 +596,14 @@ model tcg_tickets {
collections String[]
completed_at DateTime? @db.Timestamp(6)
priority String?
created_at DateTime @db.Timestamp(6)
modified_at DateTime @db.Timestamp(6)
assigned_to String[]
remote_id String?
remote_platform String?
creator_type String?
id_tcg_user String? @db.Uuid
id_linked_user String @db.Uuid
id_linked_user String? @db.Uuid
created_at DateTime @db.Timestamp(6)
modified_at DateTime @db.Timestamp(6)
id_connection String @db.Uuid
tcg_attachments tcg_attachments[]
tcg_comments tcg_comments[]
Expand All @@ -619,10 +620,10 @@ model tcg_users {
remote_id String?
remote_platform String?
teams String[]
created_at DateTime? @db.Timestamp(6)
modified_at DateTime? @db.Timestamp(6)
id_linked_user String? @db.Uuid
id_connection String @db.Uuid
created_at DateTime? @db.Timestamp(6)
modified_at DateTime? @db.Timestamp(6)
tcg_comments tcg_comments[]
}

Expand Down Expand Up @@ -677,7 +678,6 @@ model connector_sets {
crm_zendesk Boolean?
crm_close Boolean?
fs_box Boolean?
tcg_github Boolean?
projects projects[]
}

Expand Down Expand Up @@ -1640,7 +1640,6 @@ model acc_vendor_credits {
accounting_period String? @db.Uuid
}


model ecom_customers {
id_ecom_customer String @id(map: "pk_ecom_customers") @db.Uuid
remote_id String?
Expand Down
5 changes: 2 additions & 3 deletions packages/api/src/@core/connections/@utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ export type OAuthCallbackParams = {
export type APIKeyCallbackParams = {
projectId: string;
linkedUserId: string;
apikey: string;
body_data?: { [key: string]: any };
body?: { [key: string]: any };
};

export type BasicAuthCallbackParams = Omit<APIKeyCallbackParams, 'apikey'>;
export type BasicAuthCallbackParams = APIKeyCallbackParams;

// Define the discriminated union type for callback parameters
export type CallbackParams =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class AshbyConnectionService extends AbstractBaseConnectionService {

async handleCallback(opts: BasicAuthCallbackParams) {
try {
const { linkedUserId, projectId, body_data } = opts;
const { linkedUserId, projectId, body } = opts;
const isNotUnique = await this.prisma.connections.findFirst({
where: {
id_linked_user: linkedUserId,
Expand All @@ -93,7 +93,7 @@ export class AshbyConnectionService extends AbstractBaseConnectionService {
id_connection: isNotUnique.id_connection,
},
data: {
access_token: this.cryptoService.encrypt(body_data.username),
access_token: this.cryptoService.encrypt(body.username),
account_url: CONNECTORS_METADATA['ats']['ashby'].urls
.apiUrl as string,
status: 'valid',
Expand All @@ -110,7 +110,7 @@ export class AshbyConnectionService extends AbstractBaseConnectionService {
token_type: 'basic',
account_url: CONNECTORS_METADATA['ats']['ashby'].urls
.apiUrl as string,
access_token: this.cryptoService.encrypt(body_data.username),
access_token: this.cryptoService.encrypt(body.username),
status: 'valid',
created_at: new Date(),
projects: {
Expand Down
Loading
Loading