All files / src/sections/Actions/Share CustomLink.tsx

0% Statements 0/17
0% Branches 0/14
0% Functions 0/7
0% Lines 0/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99                                                                                                                                                                                                     
import { CheckMarkIcon } from "@assets/icons";
import { Input } from "@common/Input";
import { Text } from "@common/Text";
import { Button } from "@components/common/Button";
import { Link, Stack } from "@mui/material";
import { useTheme } from "@mui/material/styles";
import useMediaQuery from "@mui/material/useMediaQuery";
import { palette } from "@palette";
import React from "react";
 
const CustomLink = () => {
  const theme = useTheme();
  const isDesktop = useMediaQuery(theme.breakpoints.up("sm"));
 
  const [copied, setCopied] = React.useState(false);
  const [add, setAdd] = React.useState("");
  const [value, setValue] = React.useState(
    "https://staging.givepayments.com/" + add,
  );
  const [active, setActive] = React.useState(false);
 
  return (
    <Stack direction="column" alignItems="flex-start" gap="4px">
      <Stack
        alignItems={isDesktop ? "center" : "stretch"}
        direction={isDesktop ? "row" : "column"}
        gap={2}
        width="100%"
      >
        <Input
          sx={{ width: isDesktop ? "574px" : "100%" }}
          fullWidth
          value={value}
          onChange={(e) => setValue(e.target.value)}
          disabled={!active || copied}
        />
        <Stack direction="row" spacing={1} sx={{ width: "100%" }}>
          {!isDesktop && (
            <Button
              type="submit"
              variant="text"
              fullWidth
              onClick={() => {
                setValue(`https://staging.givepayments.com/jhuhuh` + add);
                setActive(true);
              }}
            >
              Edit Link
            </Button>
          )}
          {copied ? (
            <Button
              variant="primary"
              fullWidth={!isDesktop}
              startIcon={<CheckMarkIcon />}
            >
              <Text color={palette.success.main} fontWeight="medium">
                Copied
              </Text>
            </Button>
          ) : (
            <Button
              type="submit"
              variant="primary"
              fullWidth={!isDesktop}
              onClick={() => {
                navigator.clipboard.writeText(value);
                setTimeout(() => setCopied(false), 2000);
                setCopied(true);
              }}
            >
              Copy Link
            </Button>
          )}
        </Stack>
      </Stack>
      {isDesktop && (
        <Link
          sx={{ cursor: "pointer" }}
          onClick={() => {
            setValue(`https://staging.givepayments.com/jhuhuh` + add);
          }}
        >
          <Text
            onClick={() => setActive(true)}
            variant="body"
            fontWeight="medium"
            color={palette.primary.main}
          >
            Edit share link
          </Text>
        </Link>
      )}
    </Stack>
  );
};
 
export default CustomLink;