/** * Copyright 2021 Design Barn Inc. */ // NOT IN USE import React, { useEffect, useState } from 'react'; import { gql, useMutation } from 'urql'; import { CrownIcon, DownChevronIcon } from '../../../../../assets/Icons'; import { useWorkspace } from '../../../../../context/workspace-provider'; const statusOptions = ['Approved', 'In Progress', 'Needs Review', 'No Status'] as const; const statusColors: { [key: string]: string } = { Approved: 'bg-green-500', 'In Progress': 'bg-purple-500', 'Needs Review': 'bg-orange-500', 'No Status': 'bg-gray-400', }; const textToStatus: { [key: string]: string | null } = { Approved: 'Approved', 'In Progress': 'InProgress', 'Needs Review': 'NeedsReview', 'No Status': null, }; const statusToText: { [key: string]: typeof statusOptions[number] } = { Approved: 'Approved', InProgress: 'In Progress', NeedsReview: 'Needs Review', NoStatus: 'No Status', }; interface StatusTextProps { light?: boolean; showCrown?: boolean; value: string; } const StatusText: React.FC = ({ light = false, showCrown = false, value }: StatusTextProps) => (
{value}
{showCrown && }
); export const UPDATE_ANIMATION_STATUS = gql` mutation updateAnimationStatus($status: FileStatus, $id: String!) { updateAnimationStatus(status: $status, id: $id) { id status animationUrl } } `; export interface StatusDropdownProps { id: string; isPremium?: boolean; status: string; } export const StatusDropdown: React.FC = ({ id, isPremium = false, status, }: StatusDropdownProps) => { const workspace = useWorkspace(); const [isOpen, setIsOpen] = useState(false); const [selected, setSelected] = useState(statusToText[status || 'NoStatus']); // eslint-disable-next-line @typescript-eslint/no-unused-vars const [_, updateAnimationStatus] = useMutation(UPDATE_ANIMATION_STATUS); useEffect(() => { function handleClickOutside() { setIsOpen(false); } window.addEventListener('click', handleClickOutside); return () => { window.removeEventListener('click', handleClickOutside); }; }, []); const toggleDropdown = () => { setIsOpen(!isOpen); }; const chooseStatus = (sts: typeof statusOptions[number]) => { if (isPremium) { updateAnimationStatus({ variables: { id, status: textToStatus[sts], }, }); setSelected(sts); toggleDropdown(); } else { workspace.showUpsellModal(); } }; return (
) => event.stopPropagation()} className="relative inline-block w-40" >
{!isPremium && }
{isOpen && (
    {statusOptions.map((stsOpt: typeof statusOptions[number], i: number) => { return (
  • chooseStatus(stsOpt)} className="group p-0.5 cursor-pointer rounded-md hover-black-light" >
  • ); })}
)}
); };