-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4643781
commit 8c26bfd
Showing
7 changed files
with
656 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
247 changes: 247 additions & 0 deletions
247
app/components/LeftPaneEntries/TableAndVisualItem/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,247 @@ | ||
import React, { useCallback, useMemo } from 'react'; | ||
import { BsDownload } from 'react-icons/bs'; | ||
import { | ||
IoCheckmark, | ||
IoClose, | ||
} from 'react-icons/io5'; | ||
|
||
import { | ||
_cs, | ||
isDefined, | ||
} from '@togglecorp/fujs'; | ||
import { | ||
Container, | ||
QuickActionButton, | ||
useInputState, | ||
Button, | ||
QuickActionButtonProps, | ||
QuickActionLink, | ||
} from '@the-deep/deep-ui'; | ||
import { requiredStringCondition } from '@togglecorp/toggle-form'; | ||
|
||
import ExcerptTextArea from '#components/entry/ExcerptTextArea'; | ||
import ExcerptInput from '#components/entry/ExcerptInput'; | ||
import { | ||
EntryTagTypeEnum, | ||
LeadPreviewAttachmentType, | ||
} from '#generated/types'; | ||
|
||
import styles from './styles.css'; | ||
|
||
interface ExcerptModalProps { | ||
title: string; | ||
excerpt?: string; | ||
onComplete?: (modifiedExcerpt: string | undefined) => void; | ||
} | ||
|
||
export function ExcerptModal(props: ExcerptModalProps) { | ||
const { | ||
title, | ||
excerpt: excerptFromProps, | ||
onComplete, | ||
} = props; | ||
|
||
const [excerpt, setExcerpt] = useInputState(excerptFromProps); | ||
|
||
const handleSubmit = React.useCallback( | ||
() => { | ||
if (onComplete) { | ||
onComplete(excerpt); | ||
} | ||
}, | ||
[onComplete, excerpt], | ||
); | ||
|
||
return ( | ||
<Container | ||
className={styles.excerptModalContainer} | ||
heading={title} | ||
spacing="compact" | ||
footerActions={( | ||
<Button | ||
name={excerpt} | ||
onClick={handleSubmit} | ||
disabled={requiredStringCondition(excerpt) !== undefined} | ||
> | ||
Done | ||
</Button> | ||
)} | ||
> | ||
<ExcerptTextArea | ||
className={styles.excerptTextArea} | ||
name="modified-excerpt" | ||
value={excerpt} | ||
onChange={setExcerpt} | ||
rows={10} | ||
/> | ||
</Container> | ||
); | ||
} | ||
|
||
interface TableAndVisualItemProps { | ||
attachmentId: string; | ||
onClick?: (dataId: LeadPreviewAttachmentType['id'], type: 'IMAGE' | 'ATTACHMENT') => void; | ||
onApproveButtonClick?: QuickActionButtonProps<string>['onClick']; | ||
onDiscardButtonClick?: QuickActionButtonProps<string>['onClick']; | ||
onEntryDelete?: (entryId: string) => void; | ||
onEntryRestore?: (entryId: string) => void; | ||
className?: string; | ||
disableApproveButton?: boolean; | ||
disableDiscardButton?: boolean; | ||
disableClick?: boolean; | ||
errored?: boolean; | ||
data: LeadPreviewAttachmentType; | ||
isActive?: boolean; | ||
} | ||
|
||
function TableAndVisualItem(props: TableAndVisualItemProps) { | ||
const { | ||
className, | ||
attachmentId, | ||
onClick, | ||
onApproveButtonClick, | ||
onDiscardButtonClick, | ||
disableApproveButton, | ||
disableDiscardButton, | ||
disableClick, | ||
onEntryDelete, | ||
onEntryRestore, | ||
deleted, | ||
errored, | ||
stale, | ||
data, | ||
isActive, | ||
} = props; | ||
|
||
const entryTypeFromLead = useMemo((): EntryTagTypeEnum | undefined => { | ||
if (data?.type === 'IMAGE' || data?.type === 'XLSX') { | ||
return 'IMAGE'; | ||
} | ||
return undefined; | ||
}, [data]); | ||
|
||
const handleClick = React.useCallback(() => { | ||
if (onClick && !disableClick) { | ||
onClick(attachmentId, data?.type === 'IMAGE' ? 'IMAGE' : 'ATTACHMENT'); | ||
} | ||
}, [attachmentId, onClick, disableClick, data?.type]); | ||
|
||
return ( | ||
<div | ||
className={styles.clickableArea} | ||
onClick={handleClick} | ||
role="presentation" | ||
> | ||
<Container | ||
className={_cs( | ||
className, | ||
isActive && styles.active && styles.taggedExcerpt, | ||
)} | ||
headerActions={data?.type === 'XLSX' ? ( | ||
<QuickActionLink | ||
title="Open external" | ||
to={data?.file?.url || ''} | ||
> | ||
<BsDownload /> | ||
</QuickActionLink> | ||
) : undefined} | ||
// heading={isDefined(entryServerId) ? ( | ||
// <NumberOutput | ||
// className={styles.attachmentId} | ||
// prefix="#" | ||
// value={Number(entryServerId)} | ||
// /> | ||
// ) : ( | ||
// <span className={styles.unsavedEntry}>(unsaved entry)</span> | ||
// )} | ||
heading={isActive && ( | ||
<span className={styles.unsavedEntry}>(unsaved entry)</span> | ||
)} | ||
headingClassName={styles.heading} | ||
headingSize="extraSmall" | ||
headingSectionClassName={styles.headingSection} | ||
// footerIcons={( | ||
// <> | ||
// {stale && !deleted && !errored && ( | ||
// <Tag | ||
// spacing="compact" | ||
// > | ||
// Changed | ||
// </Tag> | ||
// )} | ||
// {deleted && ( | ||
// <Tag | ||
// variant="complement2" | ||
// spacing="compact" | ||
// > | ||
// Deleted | ||
// </Tag> | ||
// )} | ||
// {errored && ( | ||
// <Tag | ||
// spacing="compact" | ||
// > | ||
// Error | ||
// </Tag> | ||
// )} | ||
// </> | ||
// )} | ||
footerQuickActions={isActive && ( | ||
<> | ||
<QuickActionButton | ||
title="Discard changes" | ||
name={attachmentId} | ||
onClick={onDiscardButtonClick} | ||
disabled={disableDiscardButton} | ||
> | ||
<IoClose /> | ||
</QuickActionButton> | ||
<QuickActionButton | ||
title="Approve changes" | ||
name={attachmentId} | ||
onClick={onApproveButtonClick} | ||
variant="primary" | ||
disabled={disableApproveButton} | ||
> | ||
<IoCheckmark /> | ||
</QuickActionButton> | ||
{/* {deleted ? ( | ||
<QuickActionButton | ||
title="Restore entry" | ||
name={attachmentId} | ||
onClick={onEntryRestore} | ||
> | ||
<IoArrowUndoSharp /> | ||
</QuickActionButton> | ||
) : ( | ||
<QuickActionButton | ||
title="Delete entry" | ||
name={attachmentId} | ||
onClick={onEntryDelete} | ||
> | ||
<IoTrashBinOutline /> | ||
</QuickActionButton> | ||
)} */} | ||
</> | ||
)} | ||
contentClassName={styles.content} | ||
> | ||
{isDefined(entryTypeFromLead) && ( | ||
<ExcerptInput | ||
// className={styles.taggedExcerpt} | ||
value={data?.type} | ||
leadImageUrl={data?.filePreview?.url ?? undefined} | ||
entryType={entryTypeFromLead} | ||
image={undefined} | ||
imageRaw={undefined} | ||
readOnly | ||
/> | ||
)} | ||
|
||
<div className={styles.verticalBorder} /> | ||
</Container> | ||
</div> | ||
); | ||
} | ||
|
||
export default TableAndVisualItem; |
Oops, something went wrong.