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

85 lines
2.2 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";
import getConfig from "next/config";
2022-04-25 15:15:17 +02:00
import { useRouter } from "next/router";
import { TbCopy } from "react-icons/tb";
import { Share } from "../../types/share.type";
import toast from "../../utils/toast.util";
const { publicRuntimeConfig } = getConfig();
2022-04-25 15:15:17 +02:00
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
variant="filled"
value={link}
rightSection={
<ActionIcon
onClick={() => {
clipboard.copy(link);
toast.success("Your link was copied to the keyboard.");
}}
>
<TbCopy />
2022-04-25 15:15:17 +02:00
</ActionIcon>
}
/>
<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."
: `This share will expire on ${
publicRuntimeConfig.TWELVE_HOUR_TIME === "true"
? moment(share.expiration).format("MMMM Do YYYY, h:mm a")
: moment(share.expiration).format("MMMM DD YYYY, HH:mm")
}`}
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;