2023-04-24 13:23:07 +00:00
|
|
|
import { FC } from "react";
|
2023-04-05 19:21:15 +00:00
|
|
|
|
|
|
|
// react-hook-form
|
|
|
|
import { Control, Controller, UseFormWatch } from "react-hook-form";
|
|
|
|
// hooks
|
|
|
|
import useProjects from "hooks/use-projects";
|
|
|
|
// components
|
|
|
|
import { SelectRepository, TFormValues, TIntegrationSteps } from "components/integration";
|
|
|
|
// ui
|
2023-04-24 13:23:07 +00:00
|
|
|
import { CustomSearchSelect, PrimaryButton, SecondaryButton, ToggleSwitch } from "components/ui";
|
2023-04-05 19:21:15 +00:00
|
|
|
// helpers
|
|
|
|
import { truncateText } from "helpers/string.helper";
|
2023-03-23 17:57:11 +00:00
|
|
|
// types
|
2023-04-18 05:24:45 +00:00
|
|
|
import { IWorkspaceIntegration } from "types";
|
2023-04-05 19:21:15 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
handleStepChange: (value: TIntegrationSteps) => void;
|
2023-04-18 05:24:45 +00:00
|
|
|
integration: IWorkspaceIntegration | false | undefined;
|
2023-04-05 19:21:15 +00:00
|
|
|
control: Control<TFormValues, any>;
|
|
|
|
watch: UseFormWatch<TFormValues>;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const GithubImportData: FC<Props> = ({ handleStepChange, integration, control, watch }) => {
|
|
|
|
const { projects } = useProjects();
|
2023-03-23 17:57:11 +00:00
|
|
|
|
2023-05-20 10:30:41 +00:00
|
|
|
const options = projects
|
|
|
|
? projects.map((project) => ({
|
|
|
|
value: project.id,
|
|
|
|
query: project.name,
|
|
|
|
content: <p>{truncateText(project.name, 25)}</p>,
|
|
|
|
}))
|
|
|
|
: undefined;
|
2023-03-23 17:57:11 +00:00
|
|
|
|
2023-04-05 19:21:15 +00:00
|
|
|
return (
|
|
|
|
<div className="mt-6">
|
|
|
|
<div className="space-y-8">
|
|
|
|
<div className="grid grid-cols-12 gap-4 sm:gap-16">
|
|
|
|
<div className="col-span-12 sm:col-span-8">
|
|
|
|
<h4 className="font-semibold">Select Repository</h4>
|
2023-04-24 07:50:41 +00:00
|
|
|
<p className="text-xs text-brand-secondary">
|
2023-04-05 19:21:15 +00:00
|
|
|
Select the repository that you want the issues to be imported from.
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div className="col-span-12 sm:col-span-4">
|
|
|
|
{integration && (
|
|
|
|
<Controller
|
|
|
|
control={control}
|
|
|
|
name="github"
|
|
|
|
render={({ field: { value, onChange } }) => (
|
|
|
|
<SelectRepository
|
|
|
|
integration={integration}
|
|
|
|
value={value ? value.id : null}
|
2023-04-24 07:50:41 +00:00
|
|
|
label={
|
|
|
|
value ? (
|
|
|
|
`${value.full_name}`
|
|
|
|
) : (
|
|
|
|
<span className="text-brand-secondary">Select Repository</span>
|
|
|
|
)
|
|
|
|
}
|
2023-04-05 19:21:15 +00:00
|
|
|
onChange={onChange}
|
|
|
|
characterLimit={50}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="grid grid-cols-12 gap-4 sm:gap-16">
|
|
|
|
<div className="col-span-12 sm:col-span-8">
|
|
|
|
<h4 className="font-semibold">Select Project</h4>
|
2023-04-24 07:50:41 +00:00
|
|
|
<p className="text-xs text-brand-secondary">
|
|
|
|
Select the project to import the issues to.
|
|
|
|
</p>
|
2023-04-05 19:21:15 +00:00
|
|
|
</div>
|
|
|
|
<div className="col-span-12 sm:col-span-4">
|
|
|
|
{projects && (
|
|
|
|
<Controller
|
|
|
|
control={control}
|
|
|
|
name="project"
|
|
|
|
render={({ field: { value, onChange } }) => (
|
|
|
|
<CustomSearchSelect
|
|
|
|
value={value}
|
2023-04-24 07:50:41 +00:00
|
|
|
label={
|
|
|
|
value ? (
|
|
|
|
projects.find((p) => p.id === value)?.name
|
|
|
|
) : (
|
|
|
|
<span className="text-brand-secondary">Select Project</span>
|
|
|
|
)
|
|
|
|
}
|
2023-04-05 19:21:15 +00:00
|
|
|
onChange={onChange}
|
|
|
|
options={options}
|
|
|
|
optionsClassName="w-full"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="grid grid-cols-12 gap-4 sm:gap-16">
|
|
|
|
<div className="col-span-12 sm:col-span-8">
|
|
|
|
<h4 className="font-semibold">Sync Issues</h4>
|
2023-04-24 07:50:41 +00:00
|
|
|
<p className="text-xs text-brand-secondary">
|
|
|
|
Set whether you want to sync the issues or not.
|
|
|
|
</p>
|
2023-04-05 19:21:15 +00:00
|
|
|
</div>
|
|
|
|
<div className="col-span-12 sm:col-span-4">
|
|
|
|
<Controller
|
|
|
|
control={control}
|
|
|
|
name="sync"
|
|
|
|
render={({ field: { value, onChange } }) => (
|
2023-04-24 13:23:07 +00:00
|
|
|
<ToggleSwitch value={value} onChange={() => onChange(!value)} />
|
2023-04-05 19:21:15 +00:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="mt-6 flex items-center justify-end gap-2">
|
|
|
|
<SecondaryButton onClick={() => handleStepChange("import-configure")}>Back</SecondaryButton>
|
|
|
|
<PrimaryButton
|
|
|
|
onClick={() => handleStepChange("repo-details")}
|
|
|
|
disabled={!watch("github") || !watch("project")}
|
|
|
|
>
|
|
|
|
Next
|
|
|
|
</PrimaryButton>
|
|
|
|
</div>
|
2023-03-23 17:57:11 +00:00
|
|
|
</div>
|
2023-04-05 19:21:15 +00:00
|
|
|
);
|
|
|
|
};
|