Open link in new tab and added cell url (#782)
This commit is contained in:
@ -2,10 +2,11 @@ import { useEffect, useState } from 'react';
|
|||||||
import { useRecoilValue } from 'recoil';
|
import { useRecoilValue } from 'recoil';
|
||||||
|
|
||||||
import { companyDomainNameFamilyState } from '@/companies/states/companyDomainNameFamilyState';
|
import { companyDomainNameFamilyState } from '@/companies/states/companyDomainNameFamilyState';
|
||||||
import { EditableCellText } from '@/ui/table/editable-cell/types/EditableCellText';
|
|
||||||
import { useCurrentRowEntityId } from '@/ui/table/hooks/useCurrentEntityId';
|
import { useCurrentRowEntityId } from '@/ui/table/hooks/useCurrentEntityId';
|
||||||
import { useUpdateOneCompanyMutation } from '~/generated/graphql';
|
import { useUpdateOneCompanyMutation } from '~/generated/graphql';
|
||||||
|
|
||||||
|
import { EditableCellURL } from '../../../ui/table/editable-cell/types/EditableCellURL';
|
||||||
|
|
||||||
export function EditableCompanyDomainNameCell() {
|
export function EditableCompanyDomainNameCell() {
|
||||||
const currentRowEntityId = useCurrentRowEntityId();
|
const currentRowEntityId = useCurrentRowEntityId();
|
||||||
|
|
||||||
@ -20,8 +21,8 @@ export function EditableCompanyDomainNameCell() {
|
|||||||
}, [name]);
|
}, [name]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<EditableCellText
|
<EditableCellURL
|
||||||
value={internalValue}
|
url={internalValue}
|
||||||
onChange={setInternalValue}
|
onChange={setInternalValue}
|
||||||
onSubmit={() =>
|
onSubmit={() =>
|
||||||
updateCompany({
|
updateCompany({
|
||||||
|
|||||||
@ -20,7 +20,7 @@ const StyledClickable = styled.div`
|
|||||||
export function RawLink({ className, href, children, onClick }: OwnProps) {
|
export function RawLink({ className, href, children, onClick }: OwnProps) {
|
||||||
return (
|
return (
|
||||||
<StyledClickable className={className}>
|
<StyledClickable className={className}>
|
||||||
<ReactLink onClick={onClick} to={href}>
|
<ReactLink target="_blank" onClick={onClick} to={href}>
|
||||||
{children}
|
{children}
|
||||||
</ReactLink>
|
</ReactLink>
|
||||||
</StyledClickable>
|
</StyledClickable>
|
||||||
|
|||||||
@ -0,0 +1,64 @@
|
|||||||
|
import { ChangeEvent, useEffect, useState } from 'react';
|
||||||
|
|
||||||
|
import { InplaceInputTextEditMode } from '@/ui/inplace-input/components/InplaceInputTextEditMode';
|
||||||
|
|
||||||
|
import { RawLink } from '../../../link/components/RawLink';
|
||||||
|
import { CellSkeleton } from '../components/CellSkeleton';
|
||||||
|
import { EditableCell } from '../components/EditableCell';
|
||||||
|
|
||||||
|
type OwnProps = {
|
||||||
|
placeholder?: string;
|
||||||
|
url: string;
|
||||||
|
onChange: (newURL: string) => void;
|
||||||
|
editModeHorizontalAlign?: 'left' | 'right';
|
||||||
|
loading?: boolean;
|
||||||
|
onSubmit?: () => void;
|
||||||
|
onCancel?: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function EditableCellURL({
|
||||||
|
url,
|
||||||
|
placeholder,
|
||||||
|
onChange,
|
||||||
|
editModeHorizontalAlign,
|
||||||
|
loading,
|
||||||
|
onCancel,
|
||||||
|
onSubmit,
|
||||||
|
}: OwnProps) {
|
||||||
|
const [internalValue, setInternalValue] = useState(url);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setInternalValue(url);
|
||||||
|
}, [url]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<EditableCell
|
||||||
|
editModeHorizontalAlign={editModeHorizontalAlign}
|
||||||
|
editModeContent={
|
||||||
|
<InplaceInputTextEditMode
|
||||||
|
placeholder={placeholder || ''}
|
||||||
|
autoFocus
|
||||||
|
value={internalValue}
|
||||||
|
onChange={(event: ChangeEvent<HTMLInputElement>) => {
|
||||||
|
setInternalValue(event.target.value);
|
||||||
|
onChange(event.target.value);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
onSubmit={onSubmit}
|
||||||
|
onCancel={onCancel}
|
||||||
|
nonEditModeContent={
|
||||||
|
loading ? (
|
||||||
|
<CellSkeleton />
|
||||||
|
) : (
|
||||||
|
<RawLink
|
||||||
|
onClick={(e) => e.stopPropagation()}
|
||||||
|
href={internalValue ? 'https://' + internalValue : ''}
|
||||||
|
>
|
||||||
|
{internalValue}
|
||||||
|
</RawLink>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
></EditableCell>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user