Moltivie / the-t3-stack

Found unnecessary else blocks JS-0056
Anti-pattern
Minor
a year agoa year old
Unnecessary 'else' after 'return'.
180        </main>
181      </>
182    );
183  } else {184    return <div>test</div>;185  }186};
187
188export default AdminIndex;
Unnecessary 'else' after 'return'.
 95        </main>
 96      </>
 97    );
 98  } else { 99    return (100      <>101        <Head>102          <title>My profile</title>103          <meta name="description" content="" />104          <link rel="icon" href="/favicon.ico" />105        </Head>106        <main className="h-full min-h-screen w-full bg-gray-800">107          <section className="mx-auto flex h-screen max-w-7xl flex-col items-center justify-center">108            <header className="grid w-full grid-cols-3 items-center justify-center py-10">109              <h1 className="col-start-2 text-center text-4xl font-bold uppercase tracking-wider text-gray-200">110                My profile111              </h1>112              <div className="flex w-full items-center justify-end space-x-4">113                {(session?.user?.role || 1) >= 2 && (114                  <Link href="/admin">115                    <button116                      type="button"117                      className="mr-3 rounded-md border bg-red-500 p-2 font-semibold text-gray-200 transition duration-200 hover:border-gray-800 hover:bg-red-200 hover:text-gray-800"118                    >119                      Admin120                    </button>121                  </Link>122                )}123                <Link href="/profile/me">124                  <Image125                    className="cursor-pointer rounded-full border border-gray-200 transition duration-200 hover:scale-105"126                    src={session?.user?.image || "_blank"}127                    width={50}128                    height={50}129                    alt={"avatar"}130                  />131                </Link>132                <h3 className="text-gray-200">133                  {session?.user?.name || "No name"}134                </h3>135                {process.env.NEXT_PUBLIC_NODE_ENV === "development" && (136                  <p className="text-yellow-600">137                    {session?.user?.role138                      ? "Role: " + session?.user?.role139                      : "No role"}140                  </p>141                )}142                <button143                  type="button"144                  className="rounded-md border border-gray-200 bg-transparent p-2 font-semibold text-gray-200 transition duration-200 hover:bg-gray-200 hover:text-gray-800"145                  // skipcq: JS-0417146                  onClick={handleLogout}147                >148                  Sign out149                </button>150              </div>151            </header>152            <section className="mt-24 flex h-full w-full flex-col items-center text-gray-200">153              <h1 className="col-start-2 text-center text-4xl font-bold uppercase tracking-wider">154                Welcome&nbsp;155                <span className="bg-gradient-to-l from-gray-200 to-gray-600 bg-clip-text tracking-wider text-transparent">156                  {session?.user?.name}&nbsp;!157                </span>158              </h1>159              <ul className="mt-10 flex flex-col items-center justify-center">160                {161                  <li162                    key={session?.user?.id || 0}163                    className="my-2 flex w-full items-center gap-5 rounded-md bg-gray-700 p-4 transition duration-100"164                  >165                    <Image166                      className="transtition rounded-full border-2 border-gray-200 duration-300"167                      src={session?.user?.image || "_blank"}168                      width={50}169                      height={50}170                      alt={`avatar-${session?.user?.id || 0}`}171                    />172                    <p className="w-full whitespace-nowrap text-center text-2xl text-gray-400">173                      {session?.user?.name || "No name"}174                    </p>175                    <div className="h-6 border-[0.5px] border-gray-300" />176                    <p className="w-full whitespace-nowrap text-center text-xl text-gray-400">177                      {session?.user?.email || "No email"}178                    </p>179                    <div className="h-6 border-[0.5px] border-gray-300" />180                    <p className="w-full whitespace-nowrap text-center text-xl text-gray-400">181                      {session?.user?.role || "No company"}182                    </p>183                    <div className="h-6 border-[0.5px] border-gray-300" />184                    <button185                      type="button"186                      // skipcq: JS-0417187                      onClick={() => setModal(true)}188                      disabled={modal || mutationUpdate.isLoading}189                    >190                      <MdEdit className="h-10 w-10 rounded-md border border-gray-200 bg-transparent p-2 text-gray-200 hover:border-yellow-200 hover:bg-yellow-200 hover:text-gray-700" />191                    </button>192                  </li>193                }194              </ul>195              <Link href="/">196                <button197                  type="button"198                  className="group mt-5 flex items-center justify-center rounded-full bg-gray-400 p-5 text-xl uppercase text-gray-600 hover:bg-gray-500"199                >200                  <IoIosArrowBack className="h-10 w-10 group-hover:text-gray-200" />201                </button>202              </Link>203            </section>204          </section>205          <footer className="absolute bottom-0 grid w-full grid-cols-3 p-4">206            <p className="col-start-2 flex justify-center capitalize text-gray-200">207              Made with  by Aiman El Aaqdi208            </p>209            <p className="mr-24 flex justify-end text-gray-200">210              Source available on211              <Link212                href="https://github.com/Moltivie/the-t3-stack"213                className="text-blue-400"214              >215                &nbsp;GitHub216              </Link>217            </p>218          </footer>219        </main>220        {221          // Modal222          modal && (223            <div className="fixed top-1/2 left-1/2 z-10 h-screen w-screen -translate-x-1/2 -translate-y-1/2 transform bg-black/60">224              <div className="flex h-full w-full items-center justify-center">225                <div className="flex h-fit w-96 flex-col items-center gap-y-4 rounded bg-gray-200 p-4 text-gray-600">226                  <h3 className="mt-10 text-3xl font-medium uppercase">227                    Username228                  </h3>229                  <input230                    type="text"231                    maxLength={10}232                    className="h-10 w-3/4 rounded px-2 text-xl outline-none"233                    value={username}234                    // skipcq: JS-0417235                    onChange={(e) => setUsername(e.target.value)}236                    // skipcq: JS-0417237                    onKeyPress={(e) => {238                      if (e.key === "Enter") {239                        handleUpdate();240                      }241                    }}242                  />243                  <div className="my-5 flex w-full items-center justify-center gap-x-10">244                    <button245                      type="button"246                      className="flex h-10 w-32 items-center justify-center rounded-md bg-gray-600 text-lg uppercase text-gray-200 hover:bg-gray-500"247                      // skipcq: JS-0417248                      onClick={handleUpdate}249                      disabled={mutationUpdate.isLoading}250                    >251                      {mutationUpdate.isLoading ? (252                        <ImSpinner2 className="animate-spin" />253                      ) : (254                        "Save"255                      )}256                    </button>257                    <button258                      type="button"259                      className="h-10 w-32 rounded-md border-2 border-gray-600 text-lg uppercase text-gray-600 hover:bg-gray-600 hover:text-gray-200"260                      // skipcq: JS-0417261                      onClick={() => {262                        // Reset modal handlers states263                        setModal(false);264                        setUsername(session?.user?.name || "");265                      }}266                      disabled={mutationUpdate.isLoading}267                    >268                      Cancel269                    </button>270                  </div>271                </div>272              </div>273            </div>274          )275        }276      </>277    );278  }279};
280
281export default ProfilePage;
Unnecessary 'else' after 'return'.
 57        </main>
 58      </>
 59    );
 60  } else { 61    return ( 62      <> 63        <Head> 64          <title>Candidate as moderator</title> 65          <meta name="description" content="" /> 66          <link rel="icon" href="/favicon.ico" /> 67        </Head> 68 69        <main className="h-full min-h-screen w-full bg-gray-800"> 70          <section className="mx-auto flex max-w-7xl flex-col items-center justify-center"> 71            <header className="grid w-full grid-cols-3 items-center justify-center py-10"> 72              <h1 className="col-start-2 text-center text-2xl font-bold uppercase tracking-wider text-gray-200"> 73                Candidate as Moderator 74              </h1> 75              { 76                // If the user is not logged in, show the login button. 77                !session ? ( 78                  <div className="flex w-full justify-end space-x-4"> 79                    <button 80                      type="button" 81                      className="rounded-md border border-gray-200 bg-transparent p-2 font-semibold text-gray-200 transition duration-200 hover:bg-gray-200 hover:text-gray-800" 82                      // skipcq: JS-0417 83                      onClick={handleLogin} 84                    > 85                      Sign in 86                    </button> 87                    <button 88                      type="button" 89                      className="transform rounded-md border border-gray-200 bg-gray-200 p-2 font-semibold text-gray-700 transition duration-200 hover:scale-105" 90                    > 91                      Sign Up 92                    </button> 93                  </div> 94                ) : ( 95                  // If the user is logged in, show the logout button 96                  <div className="flex w-full items-center justify-end space-x-4"> 97                    {(session?.user?.role || 1) >= 2 && ( 98                      <Link href="/admin"> 99                        <button100                          type="button"101                          className="mr-3 rounded-md border bg-red-500 p-2 font-semibold text-gray-200 transition duration-200 hover:border-gray-800 hover:bg-red-200 hover:text-gray-800"102                        >103                          Admin104                        </button>105                      </Link>106                    )}107                    <Link href="/profile/me">108                      <Image109                        className="cursor-pointer rounded-full border border-gray-200 transition duration-200 hover:scale-105"110                        src={session?.user?.image || "_blank"}111                        width={50}112                        height={50}113                        alt={"avatar"}114                      />115                    </Link>116                    <h3 className="text-gray-200">{session.user?.name}</h3>117                    <button118                      type="button"119                      className="rounded-md border border-gray-200 bg-transparent p-2 font-semibold text-gray-200 transition duration-200 hover:bg-gray-200 hover:text-gray-800"120                      // skipcq: JS-0417121                      onClick={handleLogout}122                    >123                      Sign out124                    </button>125                  </div>126                )127              }128            </header>129            <div className="flex flex-col items-center justify-center">130              {131                // If the user is not logged in, show the login button.132                !session ? (133                  <div className="flex w-full justify-end space-x-4">134                    <h1 className="mt-10 text-5xl text-gray-200">135                      To proceed you need a registered account136                    </h1>137                  </div>138                ) : !userIsRegistered ? (139                  // If the user is logged in, show the logout button140                  <div className="flex w-full items-center justify-start space-x-4">141                    <form>142                      <div className="flex flex-col items-center space-y-4">143                        <div className="flex flex-col items-center space-y-2">144                          <label145                            htmlFor="email"146                            className="mt-10 mb-6 text-xl font-medium capitalize text-gray-200"147                          >148                            A bit about yourself149                          </label>150                          <textarea151                            name="message"152                            id="message"153                            className={`h-72 w-80 rounded-md border border-gray-200 bg-transparent p-2 font-semibold text-gray-200 outline-none transition duration-200 hover:bg-gray-200 hover:text-gray-800 ${154                              userIsRegistered &&155                              "pointer-events-none opacity-30"156                            }`}157                          />158                        </div>159                        <button160                          type="button"161                          className={`w-fit rounded-md border border-gray-200 bg-transparent px-4 py-3 font-semibold text-gray-200 transition duration-200 hover:bg-gray-200 hover:text-gray-800 ${162                            userIsRegistered && "pointer-events-none opacity-30"163                          }`}164                          onClick={handleSubmit}165                          disabled={166                            userRegisteredisLoading ||167                            mutationRegister.isLoading ||168                            (userIsRegistered !== undefined &&169                              userIsRegistered !== null)170                          }171                        >172                          {userRegisteredisLoading ||173                          mutationRegister.isLoading ? (174                            <ImSpinner2 className="animate-spin" />175                          ) : userIsRegistered ? (176                            "You have already applied"177                          ) : (178                            "Join the staff!"179                          )}180                        </button>181                      </div>182                    </form>183                  </div>184                ) : (185                  <div className="mt-24 flex h-full w-full items-center justify-center space-x-4 text-gray-200">186                    <h3 className="flex items-center justify-center text-4xl">187                      Your candidature&apos;s status:188                    </h3>189                    <div className="flex items-center justify-center space-x-3">190                      <div191                        className={`h-2 w-2 animate-ping rounded-full ${192                          userIsRegistered.status == 1193                            ? "bg-orange-400"194                            : userIsRegistered.status == 2195                            ? "bg-green-400"196                            : "bg-red-400"197                        } `}198                      />199                      <p className="flex items-end text-2xl text-gray-200">200                        {userIsRegistered.status == 1201                          ? "Pending"202                          : userIsRegistered.status == 2203                          ? "Accepted"204                          : "Rejected"}205                      </p>206                    </div>207                  </div>208                )209              }210211              <Link href="/">212                <button213                  type="button"214                  className=" group mt-10 flex items-center justify-center rounded-full bg-gray-400 p-5 text-xl uppercase text-gray-600 hover:bg-gray-500"215                >216                  <IoIosArrowBack className="h-10 w-10 group-hover:text-gray-200" />217                </button>218              </Link>219            </div>220          </section>221          <footer className="absolute bottom-0 grid w-full grid-cols-3 p-4">222            <p className="col-start-2 flex justify-center capitalize text-gray-200">223              Made with  by Aiman El Aaqdi224            </p>225            <p className="mr-24 flex justify-end text-gray-200">226              Source available on227              <Link228                href="https://github.com/Moltivie/the-t3-stack"229                className="text-blue-400"230              >231                &nbsp;GitHub232              </Link>233            </p>234          </footer>235        </main>236      </>237    );238  }239};
240
241export default CandidateModerator;