All files / src/shared/ProfileImage/EditProfileImageModal/components ImagePreview.tsx

100% Statements 7/7
88.88% Branches 8/9
100% Functions 3/3
100% Lines 5/5

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 100                                          2x                     33x                                                                                             33x               33x             2x          
import { styled } from "@theme/v2/Provider";
import { Stack } from "@mui/material";
import GiveText from "@shared/Text/GiveText";
import GiveButton from "@shared/Button/GiveButton";
import { UploadSimpleIcon } from "@phosphor-icons/react";
import GiveThumbnail, {
  GiveThumbnailProps,
} from "@shared/Thumbnail/GiveThumbnail";
 
type TImagePreview = {
  imageUrl: string | undefined;
  title: string;
  hasPickedAFile: (e: React.ChangeEvent<HTMLInputElement>) => void;
  handleDelete?: () => void;
  canUpload?: boolean;
  canDelete?: boolean;
  thumbnailType: GiveThumbnailProps["type"];
  shouldBeRounded?: boolean;
  disabled?: boolean;
};
 
const ImagePreview = ({
  imageUrl,
  thumbnailType,
  title,
  hasPickedAFile,
  handleDelete,
  canUpload,
  canDelete,
  shouldBeRounded,
  disabled = false,
}: TImagePreview) => {
  return (
    <>
      <ImageContainer>
        <GiveThumbnail
          type={thumbnailType}
          size="large"
          imageUrl={imageUrl}
          name={title}
          shouldBeRounded={shouldBeRounded}
        />
 
        <GiveText color="primary" variant="bodyM">
          {title}
        </GiveText>
      </ImageContainer>
 
      <Buttons>
        <GiveButton
          label="Remove Image"
          color="destructive"
          size="large"
          variant="ghost"
          disabled={!canDelete || !handleDelete || disabled}
          onClick={handleDelete}
        />
 
        <label htmlFor="contained-button-file">
          <Input
            type="file"
            disabled={!canUpload || !hasPickedAFile}
            onChange={hasPickedAFile}
            id="contained-button-file"
            data-testid="contained-button-file"
          />
          <GiveButton
            component="span"
            label="Upload Image"
            size="large"
            disabled={!canUpload || !hasPickedAFile || disabled}
            startIcon={<UploadSimpleIcon size={18} />}
          />
        </label>
      </Buttons>
    </>
  );
};
 
const ImageContainer = styled(Stack)(() => ({
  margin: "16px 0 40px",
  display: "flex",
  alignItems: "center",
  justifyContent: "center",
  gap: "12px",
}));
 
const Buttons = styled(Stack)(({ theme }) => ({
  alignItems: "center",
  gap: "12px",
  flexDirection: "row",
  justifyContent: "flex-end",
}));
 
const Input = styled("input")({
  display: "none",
});
 
export default ImagePreview;