Files
swiss-datashare/frontend/src/components/upload/modals/showCompletedUploadModal.tsx

83 lines
2.1 KiB
TypeScript
Raw Normal View History

2022-04-25 15:15:17 +02:00
import {
ActionIcon,
Button,
2022-10-10 22:14:23 +02:00
Stack,
2022-04-25 15:15:17 +02:00
Text,
TextInput,
Title,
2022-04-25 15:15:17 +02:00
} from "@mantine/core";
import { useClipboard } from "@mantine/hooks";
import { useModals } from "@mantine/modals";
import { ModalsContextProps } from "@mantine/modals/lib/context";
import moment from "moment";
2022-04-25 15:15:17 +02:00
import { useRouter } from "next/router";
import { TbCopy } from "react-icons/tb";
2022-10-18 14:27:14 +02:00
import { Share } from "../../../types/share.type";
import toast from "../../../utils/toast.util";
const showCompletedUploadModal = (modals: ModalsContextProps, share: Share) => {
2022-04-25 15:15:17 +02:00
return modals.openModal({
closeOnClickOutside: false,
withCloseButton: false,
closeOnEscape: false,
2022-05-06 10:25:10 +02:00
title: (
2022-10-10 22:14:23 +02:00
<Stack align="stretch" spacing={0}>
2022-05-06 10:25:10 +02:00
<Title order={4}>Share ready</Title>
2022-10-10 22:14:23 +02:00
</Stack>
2022-05-06 10:25:10 +02:00
),
children: <Body share={share} />,
2022-04-25 15:15:17 +02:00
});
};
const Body = ({ share }: { share: Share }) => {
2022-04-25 15:15:17 +02:00
const clipboard = useClipboard({ timeout: 500 });
const modals = useModals();
const router = useRouter();
const link = `${window.location.origin}/share/${share.id}`;
2022-04-25 15:15:17 +02:00
return (
<Stack align="stretch">
2022-04-25 15:15:17 +02:00
<TextInput
readOnly
2022-04-25 15:15:17 +02:00
variant="filled"
value={link}
rightSection={
window.isSecureContext && (
<ActionIcon
onClick={() => {
clipboard.copy(link);
toast.success("Your link was copied to the keyboard.");
}}
>
<TbCopy />
</ActionIcon>
)
2022-04-25 15:15:17 +02:00
}
/>
<Text
size="xs"
sx={(theme) => ({
color: theme.colors.gray[6],
})}
>
{/* If our share.expiration is timestamp 0, show a different message */}
{moment(share.expiration).unix() === 0
? "This share will never expire."
2022-10-16 20:21:35 +02:00
: `This share will expire on ${moment(share.expiration).format(
"LLL"
)}`}
2022-04-25 15:15:17 +02:00
</Text>
<Button
onClick={() => {
modals.closeAll();
router.push("/upload");
}}
>
Done
</Button>
2022-10-10 22:14:23 +02:00
</Stack>
2022-04-25 15:15:17 +02:00
);
};
export default showCompletedUploadModal;