All files / src/sections/PayBuilder/LaunchStep/PublicURLShare PublicInputShare.tsx

100% Statements 7/7
100% Branches 9/9
100% Functions 2/2
100% Lines 7/7

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            66x                 26x 26x 26x 26x 26x     26x                                                                  
import { SxProps } from "@mui/material";
import { GiveInput } from "@shared/GiveInputs/GiveInput";
import GiveText from "@shared/Text/GiveText";
import CopyButton from "features/Merchants/MerchantSidePanel/GiveMerchantFile/components/CopyButton";
import { useMemo } from "react";
 
const PublicInputShare = ({
  url,
  textProps,
  label = "Public URL",
}: {
  url: string;
  textProps?: SxProps;
  label?: string;
}) => {
  const hasId = useMemo(() => {
    const urlParts = url.split("/");
    const idPart = urlParts[urlParts.length - 1];
    const id = idPart.split("?")[0];
    return !isNaN(Number(id)) && idPart.trim() !== "";
  }, [url]);
 
  return (
    <>
      <GiveText
        sx={{
          fontSize: "18px",
          ...textProps,
        }}
      >
        {label}
      </GiveText>
      <GiveInput
        value={hasId ? url : ""}
        placeholder={url}
        fullWidth
        sx={{
          height: "48px",
          userSelect: hasId ? "auto" : "none",
          pointerEvents: hasId ? "auto" : "none",
          "& .MuiInputBase-root": {
            borderRadius: "12px",
            height: "48px",
          },
        }}
        onChange={undefined}
        InputProps={{
          endAdornment: <CopyButton text={url} disabled={!hasId} fluidWidth />,
        }}
      />
    </>
  );
};
 
export default PublicInputShare;