All files / Rindu/components/StorybookConfigurationModal StorybookConfigurationModal.tsx

0% Statements 0/15
100% Branches 0/0
0% Functions 0/5
0% Lines 0/15

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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188                                                                                                                                                                                                                                                                                                                                                                                       
import { ReactElement, useState } from "react";
 
import { FormToggle, Heading, SelectControl, TextControl } from "components";
import { useTranslations } from "hooks";
import { AsType } from "types/heading";
import { ACCESS_TOKEN_COOKIE, getLocale, Locale, makeCookie } from "utils";
 
export interface StorybookConfigurationModalProps {
  setProduct: (product: string) => void;
  setIsLogin: (isLogin: boolean) => void;
  setLanguage: (language: Locale) => void;
  product: string;
  isLogin: boolean;
  language: Locale;
}
 
export default function StorybookConfigurationModal({
  setProduct,
  setIsLogin,
  product,
  isLogin,
  language,
  setLanguage,
}: Readonly<StorybookConfigurationModalProps>): ReactElement {
  const [inputAccessToken, setInputAccessToken] = useState("");
  const [isLoggedInput, setIsLoggedInput] = useState(isLogin);
  const { translations } = useTranslations();
  return (
    <div className="preferences-container">
      <Heading number={4} as={AsType.H2}>
        Language
      </Heading>
      <div className="section">
        <div className="label-container">
          <label htmlFor="product">
            Select a language to use with the components
          </label>
        </div>
        <div className="select-container">
          <SelectControl
            options={[
              {
                label: translations.pages.preferences.spanish,
                value: Locale.ES,
              },
              {
                label: translations.pages.preferences.english,
                value: Locale.EN,
              },
            ]}
            id="language"
            defaultValue={language}
            onChange={(e) => {
              setLanguage(getLocale(e.target.value));
            }}
          />
        </div>
      </div>
      <Heading number={4} as={AsType.H2}>
        Product Selection
      </Heading>
      <div className="section">
        <div className="label-container">
          <label htmlFor="product">
            Select a product to use with the components
          </label>
        </div>
        <div className="select-container">
          <SelectControl
            options={[
              { label: "Premium", value: "premium" },
              { label: "Free", value: "free" },
            ]}
            id="product"
            defaultValue={product}
            onChange={(e) => {
              setProduct(e.target.value);
            }}
          />
        </div>
      </div>
      <Heading number={4} as={AsType.H2}>
        Access Token
      </Heading>
      <div className="section">
        <div className="label-container">
          <label htmlFor="accessToken">
            To obtain an access token with the required scopes, go to{" "}
            <a
              href="https://developer.spotify.com/documentation/web-api/concepts/access-token"
              target="_blank"
              rel="noreferrer"
            >
              https://developer.spotify.com/documentation/web-api/concepts/access-token
            </a>{" "}
            and follow the instructions.
          </label>
        </div>
        <div className="select-container">
          <TextControl
            id="accessToken"
            placeholder="Paste your access token here"
            value={inputAccessToken}
            onChange={(e) => {
              setInputAccessToken(e.target.value);
              makeCookie({
                name: ACCESS_TOKEN_COOKIE,
                value: e.target.value,
                age: 60 * 60 * 24 * 30 * 2,
              });
            }}
            popupText="This is the access token that will be used to make requests to the Spotify API."
          />
        </div>
      </div>
      <Heading number={4} as={AsType.H2}>
        Logged In Status
      </Heading>
      <div className="section">
        <div className="label-container">
          <label htmlFor="isLoggedIn">
            Toggle the logged in status for the components
          </label>
        </div>
        <div className="select-container">
          <FormToggle
            id="isLoggedIn"
            name="isLoggedIn"
            checked={isLoggedInput}
            tabIndex={0}
            onChange={(e) => {
              setIsLogin(e.target.checked);
              setIsLoggedInput(e.target.checked);
            }}
          />
        </div>
      </div>
      <style jsx>{`
        :global(.modal) {
          overflow: auto;
        }
        .preferences-container {
          position: relative;
          display: flex;
          flex-direction: column;
          gap: 24px;
          margin: 0 auto;
          max-width: 900px;
          padding: 16px 0px;
        }
        .section {
          display: grid;
          gap: 8px 24px;
          grid-template-columns: 1.8fr 1fr;
        }
        .label-container {
          align-items: center;
          display: -webkit-box;
          display: -ms-flexbox;
          display: flex;
        }
        label {
          box-sizing: border-box;
          margin-block: 0px;
          font-size: 0.875rem;
          font-weight: 400;
          color: #a7a7a7;
        }
        .select-container {
          align-items: center;
          display: flex;
          justify-content: flex-end;
          position: relative;
          width: 100%;
        }
        a {
          color: #fff;
          text-decoration: none;
          font-weight: 600;
        }
        a:hover {
          text-decoration: underline;
        }
      `}</style>
    </div>
  );
}