chore: update module dropdowns (#396)

This commit is contained in:
Aaryan Khandelwal 2023-03-07 22:56:22 +05:30 committed by GitHub
parent afe2b029c0
commit cc498096f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 117 additions and 66 deletions

View File

@ -96,7 +96,7 @@ export const AddComment: React.FC = () => {
setValue("comment_json", jsonValue); setValue("comment_json", jsonValue);
setValue("comment_html", htmlValue); setValue("comment_html", htmlValue);
}} }}
placeholder="Enter Your comment..." // placeholder="Enter Your comment..."
/> />
)} )}
/> />

View File

@ -114,8 +114,20 @@ export const ModuleForm: React.FC<Props> = ({ handleFormSubmit, handleClose, sta
</div> </div>
<div className="flex flex-wrap items-center gap-2"> <div className="flex flex-wrap items-center gap-2">
<ModuleStatusSelect control={control} error={errors.status} /> <ModuleStatusSelect control={control} error={errors.status} />
<ModuleLeadSelect control={control} /> <Controller
<ModuleMembersSelect control={control} /> control={control}
name="lead"
render={({ field: { value, onChange } }) => (
<ModuleLeadSelect value={value} onChange={onChange} />
)}
/>
<Controller
control={control}
name="members"
render={({ field: { value, onChange } }) => (
<ModuleMembersSelect value={value} onChange={onChange} />
)}
/>
</div> </div>
</div> </div>
</div> </div>

View File

@ -106,6 +106,7 @@ export const CreateUpdateModuleModal: React.FC<Props> = ({ isOpen, setIsOpen, da
const payload: Partial<IModule> = { const payload: Partial<IModule> = {
...formData, ...formData,
members_list: formData.members,
}; };
if (!data) await createModule(payload); if (!data) await createModule(payload);

View File

@ -1,57 +1,78 @@
import React from "react"; import React from "react";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import Image from "next/image";
import useSWR from "swr"; import useSWR from "swr";
// react-hook-form
import { Controller, Control } from "react-hook-form";
// services // services
import projectServices from "services/project.service"; import projectServices from "services/project.service";
// ui // ui
import SearchListbox from "components/search-listbox"; import { Avatar, CustomSearchSelect } from "components/ui";
// icons // icons
import { UserIcon } from "@heroicons/react/24/outline"; import User from "public/user.png";
// types
import type { IModule } from "types";
// fetch-keys // fetch-keys
import { PROJECT_MEMBERS } from "constants/fetch-keys"; import { PROJECT_MEMBERS } from "constants/fetch-keys";
type Props = { type Props = {
control: Control<IModule, any>; value: string | null;
onChange: () => void;
}; };
export const ModuleLeadSelect: React.FC<Props> = ({ control }) => { export const ModuleLeadSelect: React.FC<Props> = ({ value, onChange }) => {
const router = useRouter(); const router = useRouter();
const { workspaceSlug, projectId } = router.query; const { workspaceSlug, projectId } = router.query;
const { data: people } = useSWR( const { data: members } = useSWR(
workspaceSlug && projectId ? PROJECT_MEMBERS(projectId as string) : null, workspaceSlug && projectId ? PROJECT_MEMBERS(projectId as string) : null,
workspaceSlug && projectId workspaceSlug && projectId
? () => projectServices.projectMembers(workspaceSlug as string, projectId as string) ? () => projectServices.projectMembers(workspaceSlug as string, projectId as string)
: null : null
); );
const options =
members?.map((member) => ({
value: member.member.id,
query:
(member.member.first_name && member.member.first_name !== ""
? member.member.first_name
: member.member.email) +
" " +
member.member.last_name ?? "",
content: (
<div className="flex items-center gap-2">
<Avatar user={member.member} />
{member.member.first_name && member.member.first_name !== ""
? member.member.first_name
: member.member.email}
</div>
),
})) ?? [];
const selectedOption = members?.find((m) => m.member.id === value)?.member;
return ( return (
<Controller <CustomSearchSelect
control={control} options={options}
name="lead" value={value}
render={({ field: { value, onChange } }) => ( label={
<SearchListbox <div className="flex items-center gap-2 text-gray-500">
title="Lead" {selectedOption ? (
optionsFontsize="sm" <Avatar user={selectedOption} />
options={people?.map((person) => ({ ) : (
value: person.member.id, <div className="h-4 w-4 rounded-full bg-white">
display: <Image src={User} height="100%" width="100%" className="rounded-full" alt="No user" />
person.member.first_name && person.member.first_name !== "" </div>
? person.member.first_name )}
: person.member.email, {selectedOption
}))} ? selectedOption?.first_name && selectedOption.first_name !== ""
value={value} ? selectedOption?.first_name
onChange={onChange} : selectedOption?.email
icon={<UserIcon className="h-3 w-3 text-gray-500" />} : "N/A"}
/> </div>
)} }
onChange={onChange}
noChevron
/> />
); );
}; };

View File

@ -4,55 +4,72 @@ import { useRouter } from "next/router";
import useSWR from "swr"; import useSWR from "swr";
// react-hook-form
import { Controller, Control } from "react-hook-form";
// services // services
import projectServices from "services/project.service"; import projectServices from "services/project.service";
// ui // ui
import SearchListbox from "components/search-listbox"; import { AssigneesList, Avatar, CustomSearchSelect } from "components/ui";
// icons // icons
import { UserIcon } from "@heroicons/react/24/outline"; import { UserGroupIcon } from "@heroicons/react/24/outline";
// types
import type { IModule } from "types";
// fetch-keys // fetch-keys
import { PROJECT_MEMBERS } from "constants/fetch-keys"; import { PROJECT_MEMBERS } from "constants/fetch-keys";
type Props = { type Props = {
control: Control<IModule, any>; value: string[];
onChange: () => void;
}; };
export const ModuleMembersSelect: React.FC<Props> = ({ control }) => { export const ModuleMembersSelect: React.FC<Props> = ({ value, onChange }) => {
const router = useRouter(); const router = useRouter();
const { workspaceSlug, projectId } = router.query; const { workspaceSlug, projectId } = router.query;
const { data: people } = useSWR( const { data: members } = useSWR(
workspaceSlug && projectId ? PROJECT_MEMBERS(projectId as string) : null, workspaceSlug && projectId ? PROJECT_MEMBERS(projectId as string) : null,
workspaceSlug && projectId workspaceSlug && projectId
? () => projectServices.projectMembers(workspaceSlug as string, projectId as string) ? () => projectServices.projectMembers(workspaceSlug as string, projectId as string)
: null : null
); );
const options =
members?.map((member) => ({
value: member.member.id,
query:
(member.member.first_name && member.member.first_name !== ""
? member.member.first_name
: member.member.email) +
" " +
member.member.last_name ?? "",
content: (
<div className="flex items-center gap-2">
<Avatar user={member.member} />
{member.member.first_name && member.member.first_name !== ""
? member.member.first_name
: member.member.email}
</div>
),
})) ?? [];
return ( return (
<Controller <CustomSearchSelect
control={control} value={value}
name="members_list" label={
render={({ field: { value, onChange } }) => ( <div className="flex items-center gap-2 text-gray-500">
<SearchListbox {value && value.length > 0 && Array.isArray(value) ? (
title="Members" <div className="flex items-center justify-center gap-2">
optionsFontsize="sm" <AssigneesList userIds={value} length={3} showLength={false} />
options={people?.map((person) => ({ <span className="text-gray-500">{value.length} Assignees</span>
value: person.member.id, </div>
display: ) : (
person.member.first_name && person.member.first_name !== "" <div className="flex items-center justify-center gap-2">
? person.member.first_name <UserGroupIcon className="h-4 w-4 text-gray-500" />
: person.member.email, <span className="text-gray-500">Assignee</span>
}))} </div>
multiple={true} )}
value={value} </div>
onChange={onChange} }
icon={<UserIcon className="h-3 w-3 text-gray-500" />} options={options}
/> onChange={onChange}
)} height="md"
multiple
noChevron
/> />
); );
}; };

View File

@ -221,8 +221,8 @@ export const SingleModuleCard: React.FC<Props> = ({ module, handleEditModule })
<UserGroupIcon className="h-5 w-5 text-gray-400" /> <UserGroupIcon className="h-5 w-5 text-gray-400" />
<span>Members:</span> <span>Members:</span>
<div className="flex items-center gap-1 text-xs"> <div className="flex items-center gap-1 text-xs">
{module.members_detail && module.members_detail.length > 0 ? ( {module.members && module.members.length > 0 ? (
<AssigneesList users={module.members_detail} length={3} /> <AssigneesList userIds={module.members} length={3} />
) : ( ) : (
<div className="flex items-center gap-1"> <div className="flex items-center gap-1">
<Image <Image

View File

@ -184,18 +184,18 @@ const RemirrorRichTextEditor: FC<IRemirrorRichTextEditor> = (props) => {
manager={manager} manager={manager}
initialContent={state} initialContent={state}
classNames={[ classNames={[
`p-4 relative focus:outline-none rounded-md border border-transparent focus:border-theme ${customClassName}`, `p-4 relative focus:outline-none rounded-md border focus:border-theme ${customClassName}`,
]} ]}
editable={editable} editable={editable}
onBlur={() => { onBlur={() => {
onBlur(jsonValue, htmlValue); onBlur(jsonValue, htmlValue);
}} }}
> >
{(!value || value === "" || value?.content?.[0]?.content === undefined) && ( {/* {(!value || value === "" || value?.content?.[0]?.content === undefined) && (
<p className="pointer-events-none absolute top-[8.8rem] left-9 text-gray-300"> <p className="pointer-events-none absolute top-[8.8rem] left-12 text-gray-300">
{placeholder || "Enter text..."} {placeholder || "Enter text..."}
</p> </p>
)} )} */}
<EditorComponent /> <EditorComponent />
{imageLoader && ( {imageLoader && (