|
1 | | -import { FC } from "react"; |
| 1 | +import { FC, useState } from "react"; |
| 2 | + |
| 3 | +// react-hook-form |
| 4 | +import { Control, Controller, UseFormWatch } from "react-hook-form"; |
| 5 | +// hooks |
| 6 | +import useProjects from "hooks/use-projects"; |
| 7 | +// components |
| 8 | +import { SelectRepository, TFormValues, TIntegrationSteps } from "components/integration"; |
| 9 | +// ui |
| 10 | +import { CustomSearchSelect, PrimaryButton, SecondaryButton } from "components/ui"; |
| 11 | +// helpers |
| 12 | +import { truncateText } from "helpers/string.helper"; |
2 | 13 | // types |
3 | | -import { IIntegrationData } from "components/integration"; |
| 14 | +import { IWorkspaceIntegrations } from "types"; |
| 15 | + |
| 16 | +type Props = { |
| 17 | + handleStepChange: (value: TIntegrationSteps) => void; |
| 18 | + integration: IWorkspaceIntegrations | false | undefined; |
| 19 | + control: Control<TFormValues, any>; |
| 20 | + watch: UseFormWatch<TFormValues>; |
| 21 | +}; |
| 22 | + |
| 23 | +export const GithubImportData: FC<Props> = ({ handleStepChange, integration, control, watch }) => { |
| 24 | + const { projects } = useProjects(); |
4 | 25 |
|
5 | | -type Props = { state: IIntegrationData; handleState: (key: string, valve: any) => void }; |
| 26 | + const options = |
| 27 | + projects.map((project) => ({ |
| 28 | + value: project.id, |
| 29 | + query: project.name, |
| 30 | + content: <p>{truncateText(project.name, 25)}</p>, |
| 31 | + })) ?? []; |
6 | 32 |
|
7 | | -export const GithubImportData: FC<Props> = ({ state, handleState }) => ( |
8 | | - <div> |
9 | | - <div>Import Data</div> |
10 | | - <div className="mt-5 flex items-center justify-between"> |
11 | | - <button |
12 | | - type="button" |
13 | | - className={`rounded-sm bg-gray-300 px-3 py-1.5 text-sm transition-colors hover:bg-opacity-80`} |
14 | | - onClick={() => handleState("state", "import-configure")} |
15 | | - > |
16 | | - Back |
17 | | - </button> |
18 | | - <button |
19 | | - type="button" |
20 | | - className={`rounded-sm bg-theme px-3 py-1.5 text-sm text-white transition-colors hover:bg-opacity-80`} |
21 | | - onClick={() => handleState("state", "migrate-issues")} |
22 | | - > |
23 | | - Next |
24 | | - </button> |
| 33 | + return ( |
| 34 | + <div className="mt-6"> |
| 35 | + <div className="space-y-8"> |
| 36 | + <div className="grid grid-cols-12 gap-4 sm:gap-16"> |
| 37 | + <div className="col-span-12 sm:col-span-8"> |
| 38 | + <h4 className="font-semibold">Select Repository</h4> |
| 39 | + <p className="text-gray-500 text-xs"> |
| 40 | + Select the repository that you want the issues to be imported from. |
| 41 | + </p> |
| 42 | + </div> |
| 43 | + <div className="col-span-12 sm:col-span-4"> |
| 44 | + {integration && ( |
| 45 | + <Controller |
| 46 | + control={control} |
| 47 | + name="github" |
| 48 | + render={({ field: { value, onChange } }) => ( |
| 49 | + <SelectRepository |
| 50 | + integration={integration} |
| 51 | + value={value ? value.id : null} |
| 52 | + label={value ? `${value.full_name}` : "Select Repository"} |
| 53 | + onChange={onChange} |
| 54 | + characterLimit={50} |
| 55 | + /> |
| 56 | + )} |
| 57 | + /> |
| 58 | + )} |
| 59 | + </div> |
| 60 | + </div> |
| 61 | + <div className="grid grid-cols-12 gap-4 sm:gap-16"> |
| 62 | + <div className="col-span-12 sm:col-span-8"> |
| 63 | + <h4 className="font-semibold">Select Project</h4> |
| 64 | + <p className="text-gray-500 text-xs">Select the project to import the issues to.</p> |
| 65 | + </div> |
| 66 | + <div className="col-span-12 sm:col-span-4"> |
| 67 | + {projects && ( |
| 68 | + <Controller |
| 69 | + control={control} |
| 70 | + name="project" |
| 71 | + render={({ field: { value, onChange } }) => ( |
| 72 | + <CustomSearchSelect |
| 73 | + value={value} |
| 74 | + label={value ? projects.find((p) => p.id === value)?.name : "Select Project"} |
| 75 | + onChange={onChange} |
| 76 | + options={options} |
| 77 | + optionsClassName="w-full" |
| 78 | + /> |
| 79 | + )} |
| 80 | + /> |
| 81 | + )} |
| 82 | + </div> |
| 83 | + </div> |
| 84 | + <div className="grid grid-cols-12 gap-4 sm:gap-16"> |
| 85 | + <div className="col-span-12 sm:col-span-8"> |
| 86 | + <h4 className="font-semibold">Sync Issues</h4> |
| 87 | + <p className="text-gray-500 text-xs">Set whether you want to sync the issues or not.</p> |
| 88 | + </div> |
| 89 | + <div className="col-span-12 sm:col-span-4"> |
| 90 | + <Controller |
| 91 | + control={control} |
| 92 | + name="sync" |
| 93 | + render={({ field: { value, onChange } }) => ( |
| 94 | + <button |
| 95 | + type="button" |
| 96 | + className={`relative inline-flex h-3.5 w-6 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none ${ |
| 97 | + value ? "bg-green-500" : "bg-gray-200" |
| 98 | + }`} |
| 99 | + role="switch" |
| 100 | + aria-checked={value ? true : false} |
| 101 | + onClick={() => onChange(!value)} |
| 102 | + > |
| 103 | + <span className="sr-only">Show empty groups</span> |
| 104 | + <span |
| 105 | + aria-hidden="true" |
| 106 | + className={`inline-block h-2.5 w-2.5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out ${ |
| 107 | + value ? "translate-x-2.5" : "translate-x-0" |
| 108 | + }`} |
| 109 | + /> |
| 110 | + </button> |
| 111 | + )} |
| 112 | + /> |
| 113 | + </div> |
| 114 | + </div> |
| 115 | + </div> |
| 116 | + <div className="mt-6 flex items-center justify-end gap-2"> |
| 117 | + <SecondaryButton onClick={() => handleStepChange("import-configure")}>Back</SecondaryButton> |
| 118 | + <PrimaryButton |
| 119 | + onClick={() => handleStepChange("repo-details")} |
| 120 | + disabled={!watch("github") || !watch("project")} |
| 121 | + > |
| 122 | + Next |
| 123 | + </PrimaryButton> |
| 124 | + </div> |
25 | 125 | </div> |
26 | | - </div> |
27 | | -); |
| 126 | + ); |
| 127 | +}; |
0 commit comments