2023-09-14 07:39:21 +00:00
|
|
|
import { useEffect } from "react";
|
|
|
|
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
|
|
|
// mobx
|
|
|
|
import { useMobxStore } from "lib/mobx/store-provider";
|
|
|
|
import { observer } from "mobx-react-lite";
|
2023-09-15 05:54:51 +00:00
|
|
|
// components
|
|
|
|
import {
|
|
|
|
CustomCheckboxAttribute,
|
2023-09-15 12:17:51 +00:00
|
|
|
CustomDateTimeAttribute,
|
|
|
|
CustomEmailAttribute,
|
2023-09-15 05:54:51 +00:00
|
|
|
CustomFileAttribute,
|
2023-09-15 12:17:51 +00:00
|
|
|
CustomNumberAttribute,
|
|
|
|
CustomRelationAttribute,
|
2023-09-15 05:54:51 +00:00
|
|
|
CustomSelectAttribute,
|
|
|
|
CustomTextAttribute,
|
2023-09-15 12:17:51 +00:00
|
|
|
CustomUrlAttribute,
|
2023-09-15 05:54:51 +00:00
|
|
|
} from "components/custom-attributes";
|
|
|
|
// ui
|
2023-09-14 07:39:21 +00:00
|
|
|
import { Loader } from "components/ui";
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
entityId: string;
|
|
|
|
issueId: string;
|
2023-09-15 12:17:51 +00:00
|
|
|
onChange: (attributeId: string, val: string[]) => Promise<void>;
|
2023-09-14 07:39:21 +00:00
|
|
|
projectId: string;
|
2023-09-15 12:17:51 +00:00
|
|
|
values: { [key: string]: string[] };
|
2023-09-14 07:39:21 +00:00
|
|
|
};
|
|
|
|
|
2023-09-15 08:44:08 +00:00
|
|
|
export const IssueModalCustomAttributesList: React.FC<Props> = observer(
|
2023-09-15 12:17:51 +00:00
|
|
|
({ entityId, issueId, onChange, projectId, values }) => {
|
2023-09-14 07:39:21 +00:00
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug } = router.query;
|
|
|
|
|
|
|
|
const { customAttributes: customAttributesStore } = useMobxStore();
|
|
|
|
const { entityAttributes, fetchEntityDetails, fetchEntityDetailsLoader } =
|
|
|
|
customAttributesStore;
|
|
|
|
|
|
|
|
const attributes = entityAttributes[entityId] ?? {};
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (!entityAttributes[entityId]) {
|
|
|
|
if (!workspaceSlug) return;
|
|
|
|
|
|
|
|
fetchEntityDetails(workspaceSlug.toString(), entityId);
|
|
|
|
}
|
|
|
|
}, [entityAttributes, entityId, fetchEntityDetails, workspaceSlug]);
|
|
|
|
|
|
|
|
return (
|
2023-09-15 12:17:51 +00:00
|
|
|
<>
|
2023-09-14 07:39:21 +00:00
|
|
|
{fetchEntityDetailsLoader ? (
|
|
|
|
<Loader className="flex items-center gap-2">
|
|
|
|
<Loader.Item height="27px" width="90px" />
|
|
|
|
<Loader.Item height="27px" width="90px" />
|
|
|
|
<Loader.Item height="27px" width="90px" />
|
|
|
|
</Loader>
|
|
|
|
) : (
|
2023-09-15 12:17:51 +00:00
|
|
|
<>
|
2023-09-14 07:39:21 +00:00
|
|
|
{Object.entries(attributes).map(([attributeId, attribute]) => (
|
|
|
|
<div key={attributeId}>
|
2023-09-15 12:17:51 +00:00
|
|
|
{attribute.type === "checkbox" && (
|
|
|
|
<CustomCheckboxAttribute
|
2023-09-14 07:39:21 +00:00
|
|
|
attributeDetails={attribute}
|
|
|
|
issueId={issueId}
|
2023-09-15 12:17:51 +00:00
|
|
|
onChange={(val: string) => onChange(attribute.id, [val])}
|
2023-09-14 07:39:21 +00:00
|
|
|
projectId={projectId}
|
2023-09-15 12:17:51 +00:00
|
|
|
value={attribute.default_value === "checked" ? true : false}
|
2023-09-14 07:39:21 +00:00
|
|
|
/>
|
|
|
|
)}
|
2023-09-15 12:17:51 +00:00
|
|
|
{attribute.type === "datetime" && (
|
|
|
|
<CustomDateTimeAttribute
|
2023-09-15 05:54:51 +00:00
|
|
|
attributeDetails={attribute}
|
|
|
|
issueId={issueId}
|
2023-09-15 12:17:51 +00:00
|
|
|
onChange={(val: string) => onChange(attribute.id, [val])}
|
2023-09-15 05:54:51 +00:00
|
|
|
projectId={projectId}
|
2023-09-15 12:17:51 +00:00
|
|
|
value={
|
|
|
|
attribute.default_value !== "" ? new Date(attribute.default_value) : undefined
|
|
|
|
}
|
2023-09-15 05:54:51 +00:00
|
|
|
/>
|
|
|
|
)}
|
2023-09-15 12:17:51 +00:00
|
|
|
{attribute.type === "email" && (
|
|
|
|
<CustomEmailAttribute
|
2023-09-15 05:54:51 +00:00
|
|
|
attributeDetails={attribute}
|
|
|
|
issueId={issueId}
|
2023-09-15 12:17:51 +00:00
|
|
|
onChange={(val: string) => onChange(attribute.id, [val])}
|
2023-09-15 05:54:51 +00:00
|
|
|
projectId={projectId}
|
2023-09-15 12:17:51 +00:00
|
|
|
value={attribute.default_value}
|
2023-09-15 05:54:51 +00:00
|
|
|
/>
|
|
|
|
)}
|
2023-09-15 07:06:51 +00:00
|
|
|
{attribute.type === "file" && (
|
2023-09-15 05:54:51 +00:00
|
|
|
<CustomFileAttribute
|
|
|
|
attributeDetails={attribute}
|
|
|
|
issueId={issueId}
|
2023-09-15 12:17:51 +00:00
|
|
|
onChange={(val: string) => onChange(attribute.id, [val])}
|
|
|
|
projectId={projectId}
|
|
|
|
value={undefined}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{attribute.type === "multi_select" && (
|
|
|
|
<CustomSelectAttribute
|
|
|
|
attributeDetails={attribute}
|
|
|
|
issueId={issueId}
|
|
|
|
onChange={(val: string[]) => onChange(attribute.id, val)}
|
|
|
|
projectId={projectId}
|
|
|
|
value={[]}
|
|
|
|
multiple
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{attribute.type === "number" && (
|
|
|
|
<CustomNumberAttribute
|
|
|
|
attributeDetails={attribute}
|
|
|
|
issueId={issueId}
|
|
|
|
onChange={(val: string) => onChange(attribute.id, [val])}
|
|
|
|
projectId={projectId}
|
|
|
|
value={
|
|
|
|
attribute.default_value !== ""
|
|
|
|
? parseInt(attribute.default_value, 10)
|
|
|
|
: undefined
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{attribute.type === "relation" && (
|
|
|
|
<CustomRelationAttribute
|
|
|
|
attributeDetails={attribute}
|
|
|
|
issueId={issueId}
|
|
|
|
onChange={(val: string) => onChange(attribute.id, [val])}
|
|
|
|
projectId={projectId}
|
|
|
|
value={attribute.default_value !== "" ? attribute.default_value : undefined}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{attribute.type === "select" && (
|
|
|
|
<CustomSelectAttribute
|
|
|
|
attributeDetails={attribute}
|
|
|
|
issueId={issueId}
|
|
|
|
onChange={(val: string) => onChange(attribute.id, [val])}
|
|
|
|
projectId={projectId}
|
|
|
|
value={attribute.default_value !== "" ? attribute.default_value : undefined}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{attribute.type === "text" && (
|
|
|
|
<CustomTextAttribute
|
|
|
|
attributeDetails={attribute}
|
|
|
|
issueId={issueId}
|
|
|
|
onChange={(val: string) => onChange(attribute.id, [val])}
|
|
|
|
projectId={projectId}
|
|
|
|
value={attribute.default_value}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{attribute.type === "url" && (
|
|
|
|
<CustomUrlAttribute
|
|
|
|
attributeDetails={attribute}
|
|
|
|
issueId={issueId}
|
|
|
|
onChange={(val: string) => {
|
|
|
|
console.log(val);
|
|
|
|
onChange(attribute.id, [val]);
|
|
|
|
}}
|
2023-09-15 05:54:51 +00:00
|
|
|
projectId={projectId}
|
2023-09-15 12:17:51 +00:00
|
|
|
value={values[attribute.id]?.[0]}
|
2023-09-15 05:54:51 +00:00
|
|
|
/>
|
|
|
|
)}
|
2023-09-14 07:39:21 +00:00
|
|
|
</div>
|
|
|
|
))}
|
2023-09-15 12:17:51 +00:00
|
|
|
</>
|
2023-09-14 07:39:21 +00:00
|
|
|
)}
|
2023-09-15 12:17:51 +00:00
|
|
|
</>
|
2023-09-14 07:39:21 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|