forked from github/plane
ddb07dbe5f
* chore: removed inbox id * fix: inbox changes * chore: resolved merge conflicts * chore: inbox issue response changes * chore: inbox issue filters * fix: inbox implementation revamp * fix: type fixes * fix: pagination implementation * fix: inbox fixes * fix: pagination fixes * fix: inbox Issues pagination fixes * chore: triage state change * fix: inbox fixes * chore: filtering using boolean * chore: total results in the pagination * fix: inbox main content changes * fix: develop pull fixes * chore: resolved build erros in inbox issues * dev: fix migrations * chore: module, labels and assignee in inbox * chore: inbox issue order by * chore: inbox filters * chore: inbox ui revamp * chore: inbox type updated * chore: updated filters * chore: updated filter menmbers and date types in inbox issue filter * chore: inbox issue filter updated * chore: updated date filter in the inbox issue filter * chore: moved the current tab state from local state to store * chore: updated the filter and fetch request in the inbox issues * chore: updated tab change handler * chore: handled isEmpty in the issue filters query params * chore: inbox sidebar updated * chore: enabled create inbox issue in mobx * chore: replaced the key inbox_status to status * chore: inbox sidebar pagination * chore: updated inbox issue services * chore: inbox sidebar total count indicator * chore: create inbox issue updated * chore: updated inbox issue sidebar layout * chore: rendering issue detail in inbox issue * chore: inbox issue content updated * chore: create inbox issue modal description improvement * fix: updated delete functionality in inbox store * chore: updated multiple inbox issue creation * chore: handled loading, empty states and inbox user access permissions * chore: updated rendering issues in the sidebar * chore: inbox sidebar label improvement * chore: handled empty states * chore: disabled inbox empty state added * chore: module, labels and assignee in list endpoint * chore: labels in list endpoint * chore: inboc issue serializer * chore: representation in serializer * chore: super function * chore: inbox empty state updated * chore: implemented applied filters * chore: inbox empty state updated * chore: update date formats in applied filters * chore: inbox skeleton updated * chore: ui changes in the siebar list item * chore: removed the module and cycle ids * chore: inbox sidebar tab * chore: inbox actions * chore: updated inbox issue header actions * chore: updated inbox issue code cleanup * chore: loader improvement * chore: inbox sidebar improvement * chore: inbox sidebar empty state flicker * fix: inbox issue delete operation * chore: inbox issue title and description update indicator added * fix: resolved issue property rendering in initial load * chore: inbox sidebar and detail header improvement * fix: handling selected filter in the issue filters and applied filters * chore: inbox issue detail improvement * chore: inbox issue label updated * chore: inbox issue sidebar improvement * fix: handling issue description update when we move between the issues in inbox * chore: removed inbox issue helpers file * chore: boolean checked * chore: resolved file change requests --------- Co-authored-by: NarayanBavisetti <narayan3119@gmail.com> Co-authored-by: sriram veeraghanta <veeraghanta.sriram@gmail.com> Co-authored-by: pablohashescobar <nikhilschacko@gmail.com> Co-authored-by: Anmol Singh Bhatia <anmolsinghbhatia@plane.so>
167 lines
5.5 KiB
TypeScript
167 lines
5.5 KiB
TypeScript
import { FC, useState, Fragment, useEffect } from "react";
|
|
import { TwitterPicker } from "react-color";
|
|
import { Controller, useForm } from "react-hook-form";
|
|
import { usePopper } from "react-popper";
|
|
import { Plus, X, Loader } from "lucide-react";
|
|
import { Popover } from "@headlessui/react";
|
|
import { IIssueLabel } from "@plane/types";
|
|
// hooks
|
|
import { Input, TOAST_TYPE, setToast } from "@plane/ui";
|
|
// ui
|
|
// types
|
|
import { TLabelOperations } from "./root";
|
|
|
|
type ILabelCreate = {
|
|
workspaceSlug: string;
|
|
projectId: string;
|
|
issueId: string;
|
|
values: string[];
|
|
labelOperations: TLabelOperations;
|
|
disabled?: boolean;
|
|
};
|
|
|
|
const defaultValues: Partial<IIssueLabel> = {
|
|
name: "",
|
|
color: "#ff0000",
|
|
};
|
|
|
|
export const LabelCreate: FC<ILabelCreate> = (props) => {
|
|
const { workspaceSlug, projectId, issueId, values, labelOperations, disabled = false } = props;
|
|
// state
|
|
const [isCreateToggle, setIsCreateToggle] = useState(false);
|
|
const handleIsCreateToggle = () => setIsCreateToggle(!isCreateToggle);
|
|
const [referenceElement, setReferenceElement] = useState<HTMLButtonElement | null>(null);
|
|
const [popperElement, setPopperElement] = useState<HTMLDivElement | null>(null);
|
|
// react hook form
|
|
const {
|
|
handleSubmit,
|
|
formState: { errors, isSubmitting },
|
|
reset,
|
|
control,
|
|
setFocus,
|
|
} = useForm<Partial<IIssueLabel>>({
|
|
defaultValues,
|
|
});
|
|
|
|
const { styles, attributes } = usePopper(referenceElement, popperElement, {
|
|
placement: "bottom-start",
|
|
modifiers: [
|
|
{
|
|
name: "preventOverflow",
|
|
options: {
|
|
padding: 12,
|
|
},
|
|
},
|
|
],
|
|
});
|
|
|
|
useEffect(() => {
|
|
if (!isCreateToggle) return;
|
|
|
|
setFocus("name");
|
|
reset();
|
|
}, [isCreateToggle, reset, setFocus]);
|
|
|
|
const handleLabel = async (formData: Partial<IIssueLabel>) => {
|
|
if (!workspaceSlug || !projectId || isSubmitting) return;
|
|
|
|
try {
|
|
const labelResponse = await labelOperations.createLabel(workspaceSlug, projectId, formData);
|
|
const currentLabels = [...(values || []), labelResponse.id];
|
|
await labelOperations.updateIssue(workspaceSlug, projectId, issueId, { label_ids: currentLabels });
|
|
reset(defaultValues);
|
|
} catch (error) {
|
|
setToast({
|
|
title: "Label creation failed",
|
|
type: TOAST_TYPE.ERROR,
|
|
message: "Label creation failed. Please try again sometime later.",
|
|
});
|
|
}
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<div
|
|
className="relative flex flex-shrink-0 cursor-pointer items-center gap-1 rounded-full border border-custom-border-100 p-0.5 px-2 text-xs text-custom-text-300 transition-all hover:bg-custom-background-90 hover:text-custom-text-200"
|
|
onClick={handleIsCreateToggle}
|
|
>
|
|
<div className="flex-shrink-0">
|
|
{isCreateToggle ? <X className="h-2.5 w-2.5" /> : <Plus className="h-2.5 w-2.5" />}
|
|
</div>
|
|
<div className="flex-shrink-0">{isCreateToggle ? "Cancel" : "New"}</div>
|
|
</div>
|
|
|
|
{isCreateToggle && (
|
|
<form className="relative flex items-center gap-x-2" onSubmit={handleSubmit(handleLabel)}>
|
|
<div>
|
|
<Controller
|
|
name="color"
|
|
control={control}
|
|
render={({ field: { value, onChange } }) => (
|
|
<Popover>
|
|
<>
|
|
<Popover.Button as={Fragment}>
|
|
<button type="button" ref={setReferenceElement} className="grid place-items-center outline-none">
|
|
{value && value?.trim() !== "" && (
|
|
<span
|
|
className="h-6 w-6 rounded"
|
|
style={{
|
|
backgroundColor: value ?? "black",
|
|
}}
|
|
/>
|
|
)}
|
|
</button>
|
|
</Popover.Button>
|
|
<Popover.Panel className="fixed z-10">
|
|
<div
|
|
className="p-2 max-w-xs sm:px-0"
|
|
ref={setPopperElement}
|
|
style={styles.popper}
|
|
{...attributes.popper}
|
|
>
|
|
<TwitterPicker triangle={"hide"} color={value} onChange={(value) => onChange(value.hex)} />
|
|
</div>
|
|
</Popover.Panel>
|
|
</>
|
|
</Popover>
|
|
)}
|
|
/>
|
|
</div>
|
|
<Controller
|
|
control={control}
|
|
name="name"
|
|
rules={{
|
|
required: "This is required",
|
|
}}
|
|
render={({ field: { value, onChange, ref } }) => (
|
|
<Input
|
|
id="name"
|
|
name="name"
|
|
type="text"
|
|
value={value ?? ""}
|
|
onChange={onChange}
|
|
ref={ref}
|
|
hasError={Boolean(errors.name)}
|
|
placeholder="Title"
|
|
className="w-full"
|
|
disabled={isSubmitting}
|
|
/>
|
|
)}
|
|
/>
|
|
<button
|
|
type="button"
|
|
className="grid place-items-center rounded bg-red-500 p-1.5"
|
|
onClick={() => setIsCreateToggle(false)}
|
|
disabled={disabled}
|
|
>
|
|
<X className="h-4 w-4 text-white" />
|
|
</button>
|
|
<button type="submit" className="grid place-items-center rounded bg-green-500 p-1.5" disabled={isSubmitting}>
|
|
{isSubmitting ? <Loader className="spin h-4 w-4 text-white" /> : <Plus className="h-4 w-4 text-white" />}
|
|
</button>
|
|
</form>
|
|
)}
|
|
</>
|
|
);
|
|
};
|