File size: 2,415 Bytes
9cd6ddb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import classNames from "classnames";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faCheck } from "@fortawesome/free-solid-svg-icons";

import { Label } from "@/components/label";
import { BADGE_COMPONENTS } from "@/components/svg/badges";
import { BadgeType } from "@/types/badge";
import { useUser } from "@/utils/auth";
import { PremiumContext } from "@/components/premium/premium";
import { useContext } from "react";
import { Premium } from "@/components/premium";

export const SelectShapes = ({
  badge,
  onChange,
}: {
  badge: BadgeType;
  onChange: (b: BadgeType) => void;
}) => {
  const { user } = useUser();
  const { setOpen } = useContext(PremiumContext);
  return (
    <div>
      <Label className="mb-2">Shapes</Label>
      <div className="grid grid-cols-2 lg:grid-cols-3 gap-6">
        {BADGE_COMPONENTS.map((component, i) => {
          const Component = component.mini as any;
          return (
            <div
              key={i}
              className={classNames(
                "flex items-center justify-start gap-2 cursor-pointer",
                {
                  "opacity-50 relative": component.isPremium && !user,
                }
              )}
              onClick={
                component.isPremium && !user
                  ? () => setOpen(true)
                  : () =>
                      onChange({
                        ...badge,
                        type:
                          component?.name === badge?.type
                            ? "circle"
                            : component.name,
                      })
              }
            >
              <div
                className={classNames(
                  "w-5 h-5 min-w-[1.25rem] border-2 rounded flex items-center justify-center",
                  {
                    "bg-green bg-opacity-60 border-green":
                      badge?.type === component.name,
                    "border-dark-200": badge?.type !== component.name,
                  }
                )}
              >
                {badge?.type === component.name && (
                  <FontAwesomeIcon
                    icon={faCheck}
                    className="w-3 text-white text-opacity-100"
                  />
                )}
              </div>
              <Component />
            </div>
          );
        })}
      </div>
    </div>
  );
};