2023-04-19 10:10:31 +00:00
|
|
|
import { FC } from "react";
|
|
|
|
|
|
|
|
// next
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
2023-08-09 12:19:25 +00:00
|
|
|
// swr
|
|
|
|
import useSWR from "swr";
|
|
|
|
|
2023-04-19 10:10:31 +00:00
|
|
|
// react-hook-form
|
|
|
|
import { useFormContext, useFieldArray, Controller } from "react-hook-form";
|
|
|
|
|
2023-08-09 12:19:25 +00:00
|
|
|
// fetch keys
|
|
|
|
import { WORKSPACE_MEMBERS_WITH_EMAIL } from "constants/fetch-keys";
|
|
|
|
|
|
|
|
// services
|
|
|
|
import workspaceService from "services/workspace.service";
|
2023-04-19 10:10:31 +00:00
|
|
|
|
|
|
|
// components
|
|
|
|
import { ToggleSwitch, Input, CustomSelect, CustomSearchSelect, Avatar } from "components/ui";
|
|
|
|
|
|
|
|
import { IJiraImporterForm } from "types";
|
|
|
|
|
|
|
|
export const JiraImportUsers: FC = () => {
|
|
|
|
const {
|
|
|
|
control,
|
|
|
|
watch,
|
|
|
|
register,
|
|
|
|
formState: { errors },
|
|
|
|
} = useFormContext<IJiraImporterForm>();
|
|
|
|
|
|
|
|
const { fields } = useFieldArray({
|
|
|
|
control,
|
|
|
|
name: "data.users",
|
|
|
|
});
|
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug } = router.query;
|
|
|
|
|
2023-08-09 12:19:25 +00:00
|
|
|
const { data: members } = useSWR(
|
|
|
|
workspaceSlug ? WORKSPACE_MEMBERS_WITH_EMAIL(workspaceSlug?.toString() ?? "") : null,
|
|
|
|
workspaceSlug
|
|
|
|
? () => workspaceService.workspaceMembersWithEmail(workspaceSlug?.toString() ?? "")
|
|
|
|
: null
|
|
|
|
);
|
2023-04-19 10:10:31 +00:00
|
|
|
|
2023-05-20 10:30:41 +00:00
|
|
|
const options = members?.map((member) => ({
|
|
|
|
value: member.member.email,
|
2023-08-08 07:31:43 +00:00
|
|
|
query: member.member.display_name ?? "",
|
2023-05-20 10:30:41 +00:00
|
|
|
content: (
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
<Avatar user={member.member} />
|
2023-08-08 07:31:43 +00:00
|
|
|
{member.member.display_name}
|
2023-05-20 10:30:41 +00:00
|
|
|
</div>
|
|
|
|
),
|
|
|
|
}));
|
2023-04-19 10:10:31 +00:00
|
|
|
|
|
|
|
return (
|
2023-07-17 10:58:23 +00:00
|
|
|
<div className="h-full w-full space-y-10 divide-y-2 divide-custom-border-200 overflow-y-auto">
|
2023-04-19 10:10:31 +00:00
|
|
|
<div className="grid grid-cols-1 gap-10 md:grid-cols-2">
|
|
|
|
<div className="col-span-1">
|
2023-04-24 07:50:41 +00:00
|
|
|
<h3 className="font-semibold">Users</h3>
|
2023-07-10 07:17:00 +00:00
|
|
|
<p className="text-sm text-custom-text-200">
|
2023-04-24 07:50:41 +00:00
|
|
|
Update, invite or choose not to invite assignee
|
|
|
|
</p>
|
2023-04-19 10:10:31 +00:00
|
|
|
</div>
|
|
|
|
<div className="col-span-1">
|
|
|
|
<Controller
|
|
|
|
control={control}
|
|
|
|
name="data.invite_users"
|
|
|
|
render={({ field: { value, onChange } }) => (
|
|
|
|
<ToggleSwitch onChange={onChange} value={value} />
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{watch("data.invite_users") && (
|
|
|
|
<div className="pt-6">
|
|
|
|
<div className="grid grid-cols-3 gap-3">
|
2023-07-10 07:17:00 +00:00
|
|
|
<div className="col-span-1 text-sm text-custom-text-200">Name</div>
|
|
|
|
<div className="col-span-1 text-sm text-custom-text-200">Import as</div>
|
2023-04-19 10:10:31 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="mt-5 space-y-3">
|
|
|
|
{fields.map((user, index) => (
|
|
|
|
<div className="grid grid-cols-3 gap-3" key={`${user.email}-${user.username}`}>
|
|
|
|
<div className="col-span-1">
|
|
|
|
<p>{user.username}</p>
|
|
|
|
</div>
|
|
|
|
<div className="col-span-1">
|
|
|
|
<Controller
|
|
|
|
control={control}
|
|
|
|
name={`data.users.${index}.import`}
|
|
|
|
render={({ field: { value, onChange } }) => (
|
|
|
|
<CustomSelect
|
|
|
|
input
|
|
|
|
value={value}
|
|
|
|
onChange={onChange}
|
|
|
|
width="w-full"
|
|
|
|
label={
|
|
|
|
<span className="capitalize">
|
|
|
|
{Boolean(value) ? value : ("Ignore" as any)}
|
|
|
|
</span>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<CustomSelect.Option value="invite">Invite by email</CustomSelect.Option>
|
|
|
|
<CustomSelect.Option value="map">Map to existing</CustomSelect.Option>
|
|
|
|
<CustomSelect.Option value={false}>Do not import</CustomSelect.Option>
|
|
|
|
</CustomSelect>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="col-span-1">
|
|
|
|
{watch(`data.users.${index}.import`) === "invite" && (
|
|
|
|
<Input
|
|
|
|
id={`data.users.${index}.email`}
|
|
|
|
name={`data.users.${index}.email`}
|
|
|
|
type="text"
|
|
|
|
register={register}
|
|
|
|
validations={{
|
|
|
|
required: "This field is required",
|
|
|
|
}}
|
|
|
|
error={errors?.data?.users?.[index]?.email}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{watch(`data.users.${index}.import`) === "map" && (
|
|
|
|
<Controller
|
|
|
|
control={control}
|
|
|
|
name={`data.users.${index}.email`}
|
|
|
|
render={({ field: { value, onChange } }) => (
|
|
|
|
<CustomSearchSelect
|
|
|
|
value={value}
|
|
|
|
input
|
|
|
|
label={value !== "" ? value : "Select user from project"}
|
|
|
|
options={options}
|
|
|
|
onChange={onChange}
|
|
|
|
optionsClassName="w-full"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|