Blaze it
30
.env.example
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#Database
|
||||||
|
DATABASE_URL=""
|
||||||
|
|
||||||
|
# Redis
|
||||||
|
REDIS_URL=""
|
||||||
|
|
||||||
|
#Next Auth Core
|
||||||
|
NEXTAUTH_SECRET=""
|
||||||
|
NEXTAUTH_URL=""
|
||||||
|
|
||||||
|
# Next Auth Github Provider
|
||||||
|
GITHUB_CLIENT_ID=""
|
||||||
|
GITHUB_CLIENT_SECRET=""
|
||||||
|
|
||||||
|
# Next Auth Google Provider
|
||||||
|
GOOGLE_CLIENT_ID=""
|
||||||
|
GOOGLE_CLIENT_SECRET=""
|
||||||
|
|
||||||
|
# Ably
|
||||||
|
ABLY_PRIVATE_KEY=""
|
||||||
|
NEXT_PUBLIC_ABLY_PUBLIC_KEY=""
|
||||||
|
|
||||||
|
# Email
|
||||||
|
JMAP_TOKEN=""
|
||||||
|
JMAP_USERNAME=""
|
||||||
|
JMAP_HOSTNAME=""
|
||||||
|
|
||||||
|
# Misc
|
||||||
|
APP_ENV=""
|
||||||
|
NEXT_PUBLIC_APP_ENV=""
|
31
.eslintrc.cjs
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
/** @type {import("eslint").Linter.Config} */
|
||||||
|
const config = {
|
||||||
|
overrides: [
|
||||||
|
{
|
||||||
|
extends: [
|
||||||
|
"plugin:@typescript-eslint/recommended-requiring-type-checking",
|
||||||
|
],
|
||||||
|
files: ["*.ts", "*.tsx"],
|
||||||
|
parserOptions: {
|
||||||
|
project: "tsconfig.json",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
parser: "@typescript-eslint/parser",
|
||||||
|
parserOptions: {
|
||||||
|
project: "./tsconfig.json",
|
||||||
|
},
|
||||||
|
plugins: ["@typescript-eslint"],
|
||||||
|
extends: ["next/core-web-vitals", "plugin:@typescript-eslint/recommended"],
|
||||||
|
rules: {
|
||||||
|
"@typescript-eslint/consistent-type-imports": [
|
||||||
|
"warn",
|
||||||
|
{
|
||||||
|
prefer: "type-imports",
|
||||||
|
fixStyle: "inline-type-imports",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = config;
|
54
.gitignore
vendored
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
/node_modules
|
||||||
|
/.pnp
|
||||||
|
.pnp.js
|
||||||
|
|
||||||
|
# testing
|
||||||
|
/coverage
|
||||||
|
|
||||||
|
# database
|
||||||
|
/prisma/db.sqlite
|
||||||
|
/prisma/db.sqlite-journal
|
||||||
|
|
||||||
|
# next.js
|
||||||
|
/.next/
|
||||||
|
/out/
|
||||||
|
next-env.d.ts
|
||||||
|
|
||||||
|
# production
|
||||||
|
/build
|
||||||
|
|
||||||
|
# misc
|
||||||
|
.DS_Store
|
||||||
|
*.pem
|
||||||
|
|
||||||
|
# debug
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
.pnpm-debug.log*
|
||||||
|
|
||||||
|
# local env files
|
||||||
|
# do not commit any .env files to git, except for the .env.example file. https://create.t3.gg/en/usage/env-variables#using-environment-variables
|
||||||
|
.env
|
||||||
|
.env*.local
|
||||||
|
|
||||||
|
# vercel
|
||||||
|
.vercel
|
||||||
|
|
||||||
|
# typescript
|
||||||
|
*.tsbuildinfo
|
||||||
|
|
||||||
|
# next-pwa
|
||||||
|
/public/precache.*.*.js
|
||||||
|
/public/sw.js
|
||||||
|
/public/workbox-*.js
|
||||||
|
/public/worker-*.js
|
||||||
|
/public/fallback-*.js
|
||||||
|
/public/precache.*.*.js.map
|
||||||
|
/public/sw.js.map
|
||||||
|
/public/workbox-*.js.map
|
||||||
|
/public/worker-*.js.map
|
||||||
|
/public/fallback-*.js
|
1
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{}
|
16
CHANGELOG.md
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
# Changelog
|
||||||
|
|
||||||
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
## 1.0.0 - Proactively streamline market-driven customer service (2023-05-10)
|
||||||
|
|
||||||
|
🎉🎉🎉
|
||||||
|
✨ You can now create and join rooms to vote on scrum stories with your team!
|
||||||
|
✨ Signin works with Github or Google OAuth
|
||||||
|
✨ Rooms allow for custom scales
|
||||||
|
✨ Room owners can reset votes, change the story being votes on, and even download a CSV with stats on how votes went
|
||||||
|
|
||||||
|
## 1.0.1 - Completely orchestrate principle-centered initiatives (2023-05-14)
|
||||||
|
|
||||||
|
🚧 Changed VERCEL_ENV to APP_ENV
|
||||||
|
🚧 Added indicators for the environment in development and local
|
128
CODE_OF_CONDUCT.md
Normal file
|
@ -0,0 +1,128 @@
|
||||||
|
# Contributor Covenant Code of Conduct
|
||||||
|
|
||||||
|
## Our Pledge
|
||||||
|
|
||||||
|
We as members, contributors, and leaders pledge to make participation in our
|
||||||
|
community a harassment-free experience for everyone, regardless of age, body
|
||||||
|
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
||||||
|
identity and expression, level of experience, education, socio-economic status,
|
||||||
|
nationality, personal appearance, race, religion, or sexual identity
|
||||||
|
and orientation.
|
||||||
|
|
||||||
|
We pledge to act and interact in ways that contribute to an open, welcoming,
|
||||||
|
diverse, inclusive, and healthy community.
|
||||||
|
|
||||||
|
## Our Standards
|
||||||
|
|
||||||
|
Examples of behavior that contributes to a positive environment for our
|
||||||
|
community include:
|
||||||
|
|
||||||
|
* Demonstrating empathy and kindness toward other people
|
||||||
|
* Being respectful of differing opinions, viewpoints, and experiences
|
||||||
|
* Giving and gracefully accepting constructive feedback
|
||||||
|
* Accepting responsibility and apologizing to those affected by our mistakes,
|
||||||
|
and learning from the experience
|
||||||
|
* Focusing on what is best not just for us as individuals, but for the
|
||||||
|
overall community
|
||||||
|
|
||||||
|
Examples of unacceptable behavior include:
|
||||||
|
|
||||||
|
* The use of sexualized language or imagery, and sexual attention or
|
||||||
|
advances of any kind
|
||||||
|
* Trolling, insulting or derogatory comments, and personal or political attacks
|
||||||
|
* Public or private harassment
|
||||||
|
* Publishing others' private information, such as a physical or email
|
||||||
|
address, without their explicit permission
|
||||||
|
* Other conduct which could reasonably be considered inappropriate in a
|
||||||
|
professional setting
|
||||||
|
|
||||||
|
## Enforcement Responsibilities
|
||||||
|
|
||||||
|
Community leaders are responsible for clarifying and enforcing our standards of
|
||||||
|
acceptable behavior and will take appropriate and fair corrective action in
|
||||||
|
response to any behavior that they deem inappropriate, threatening, offensive,
|
||||||
|
or harmful.
|
||||||
|
|
||||||
|
Community leaders have the right and responsibility to remove, edit, or reject
|
||||||
|
comments, commits, code, wiki edits, issues, and other contributions that are
|
||||||
|
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
||||||
|
decisions when appropriate.
|
||||||
|
|
||||||
|
## Scope
|
||||||
|
|
||||||
|
This Code of Conduct applies within all community spaces, and also applies when
|
||||||
|
an individual is officially representing the community in public spaces.
|
||||||
|
Examples of representing our community include using an official e-mail address,
|
||||||
|
posting via an official social media account, or acting as an appointed
|
||||||
|
representative at an online or offline event.
|
||||||
|
|
||||||
|
## Enforcement
|
||||||
|
|
||||||
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||||
|
reported to the community leaders responsible for enforcement at
|
||||||
|
me@atridad.dev.
|
||||||
|
All complaints will be reviewed and investigated promptly and fairly.
|
||||||
|
|
||||||
|
All community leaders are obligated to respect the privacy and security of the
|
||||||
|
reporter of any incident.
|
||||||
|
|
||||||
|
## Enforcement Guidelines
|
||||||
|
|
||||||
|
Community leaders will follow these Community Impact Guidelines in determining
|
||||||
|
the consequences for any action they deem in violation of this Code of Conduct:
|
||||||
|
|
||||||
|
### 1. Correction
|
||||||
|
|
||||||
|
**Community Impact**: Use of inappropriate language or other behavior deemed
|
||||||
|
unprofessional or unwelcome in the community.
|
||||||
|
|
||||||
|
**Consequence**: A private, written warning from community leaders, providing
|
||||||
|
clarity around the nature of the violation and an explanation of why the
|
||||||
|
behavior was inappropriate. A public apology may be requested.
|
||||||
|
|
||||||
|
### 2. Warning
|
||||||
|
|
||||||
|
**Community Impact**: A violation through a single incident or series
|
||||||
|
of actions.
|
||||||
|
|
||||||
|
**Consequence**: A warning with consequences for continued behavior. No
|
||||||
|
interaction with the people involved, including unsolicited interaction with
|
||||||
|
those enforcing the Code of Conduct, for a specified period of time. This
|
||||||
|
includes avoiding interactions in community spaces as well as external channels
|
||||||
|
like social media. Violating these terms may lead to a temporary or
|
||||||
|
permanent ban.
|
||||||
|
|
||||||
|
### 3. Temporary Ban
|
||||||
|
|
||||||
|
**Community Impact**: A serious violation of community standards, including
|
||||||
|
sustained inappropriate behavior.
|
||||||
|
|
||||||
|
**Consequence**: A temporary ban from any sort of interaction or public
|
||||||
|
communication with the community for a specified period of time. No public or
|
||||||
|
private interaction with the people involved, including unsolicited interaction
|
||||||
|
with those enforcing the Code of Conduct, is allowed during this period.
|
||||||
|
Violating these terms may lead to a permanent ban.
|
||||||
|
|
||||||
|
### 4. Permanent Ban
|
||||||
|
|
||||||
|
**Community Impact**: Demonstrating a pattern of violation of community
|
||||||
|
standards, including sustained inappropriate behavior, harassment of an
|
||||||
|
individual, or aggression toward or disparagement of classes of individuals.
|
||||||
|
|
||||||
|
**Consequence**: A permanent ban from any sort of public interaction within
|
||||||
|
the community.
|
||||||
|
|
||||||
|
## Attribution
|
||||||
|
|
||||||
|
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||||
|
version 2.0, available at
|
||||||
|
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
||||||
|
|
||||||
|
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
||||||
|
enforcement ladder](https://github.com/mozilla/diversity).
|
||||||
|
|
||||||
|
[homepage]: https://www.contributor-covenant.org
|
||||||
|
|
||||||
|
For answers to common questions about this code of conduct, see the FAQ at
|
||||||
|
https://www.contributor-covenant.org/faq. Translations are available at
|
||||||
|
https://www.contributor-covenant.org/translations.
|
674
LICENSE
Normal file
|
@ -0,0 +1,674 @@
|
||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
the GNU General Public License is intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users. We, the Free Software Foundation, use the
|
||||||
|
GNU General Public License for most of our software; it applies also to
|
||||||
|
any other work released this way by its authors. You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to prevent others from denying you
|
||||||
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
|
or can get the source code. And you must show them these terms so they
|
||||||
|
know their rights.
|
||||||
|
|
||||||
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
|
that there is no warranty for this free software. For both users' and
|
||||||
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
|
changed, so that their problems will not be attributed erroneously to
|
||||||
|
authors of previous versions.
|
||||||
|
|
||||||
|
Some devices are designed to deny users access to install or run
|
||||||
|
modified versions of the software inside them, although the manufacturer
|
||||||
|
can do so. This is fundamentally incompatible with the aim of
|
||||||
|
protecting users' freedom to change the software. The systematic
|
||||||
|
pattern of such abuse occurs in the area of products for individuals to
|
||||||
|
use, which is precisely where it is most unacceptable. Therefore, we
|
||||||
|
have designed this version of the GPL to prohibit the practice for those
|
||||||
|
products. If such problems arise substantially in other domains, we
|
||||||
|
stand ready to extend this provision to those domains in future versions
|
||||||
|
of the GPL, as needed to protect the freedom of users.
|
||||||
|
|
||||||
|
Finally, every program is threatened constantly by software patents.
|
||||||
|
States should not allow patents to restrict development and use of
|
||||||
|
software on general-purpose computers, but in those that do, we wish to
|
||||||
|
avoid the special danger that patents applied to a free program could
|
||||||
|
make it effectively proprietary. To prevent this, the GPL assures that
|
||||||
|
patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU Affero General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the special requirements of the GNU Affero General Public License,
|
||||||
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
combination as such.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program does terminal interaction, make it output a short
|
||||||
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
|
<program> Copyright (C) <year> <name of author>
|
||||||
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, your program's commands
|
||||||
|
might be different; for a GUI interface, you would use an "about box".
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU GPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
The GNU General Public License does not permit incorporating your program
|
||||||
|
into proprietary programs. If your program is a subroutine library, you
|
||||||
|
may consider it more useful to permit linking proprietary applications with
|
||||||
|
the library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License. But first, please read
|
||||||
|
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
23
README.md
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
# Sprint Padawan
|
||||||
|
|
||||||
|
A scrum poker tool that helps agile teams plan their sprints in real-time.
|
||||||
|
|
||||||
|
## Stack
|
||||||
|
|
||||||
|
- Front-end framework: Nextjs
|
||||||
|
- Rendering method: SSR
|
||||||
|
- Hosting: Vercel
|
||||||
|
- Real-time pub/sub: Ably
|
||||||
|
- ORM: Prisma
|
||||||
|
- Database: Planetscale Serverless mySQL
|
||||||
|
- Cache: Upstash Redis
|
||||||
|
- Rate-limiting: Upstash Redis
|
||||||
|
|
||||||
|
## Versioning
|
||||||
|
|
||||||
|
- I use a bastardized version of semantic versioning. I jump to a new minor release whenever I feel like I made enough patch releases.
|
||||||
|
- All released are named using the corperate BS generator, found [here](https://www.atrixnet.com/bs-generator.html).
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
Feel free to propose changes via PR. I'm not awfully picky about formatting right now, so I'll accept/reject on a case-by-case basis. Please make sure to have an issue first though.
|
9
SECURITY.md
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# Security Policy
|
||||||
|
|
||||||
|
## Supported Versions
|
||||||
|
|
||||||
|
No previous versions will be supported. This project is not meant to be self-hosted. Doing so means you assume any risks associated. Only the latest version will be supported for security updates, which will be pushed via new versions.
|
||||||
|
|
||||||
|
## Reporting a Vulnerability
|
||||||
|
|
||||||
|
Reporting security issues should be done via email ideally. I can be reached at me@atridad.dev. Please include the repository you are reporting issues for, as well as any information regarding repro or related files (if you happen to know where the issue lies). I will work with you to identify the issues and patch them.
|
31
next.config.mjs
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
// @ts-check
|
||||||
|
import withPWA from "next-pwa";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation.
|
||||||
|
* This is especially useful for Docker builds.
|
||||||
|
*/
|
||||||
|
!process.env.SKIP_ENV_VALIDATION && (await import("./src/env.mjs"));
|
||||||
|
|
||||||
|
/** @type {import("next").NextConfig} */
|
||||||
|
const config = {
|
||||||
|
reactStrictMode: true,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If you have the "experimental: { appDir: true }" setting enabled, then you
|
||||||
|
* must comment the below `i18n` config out.
|
||||||
|
*
|
||||||
|
* @see https://github.com/vercel/next.js/issues/41980
|
||||||
|
*/
|
||||||
|
i18n: {
|
||||||
|
locales: ["en"],
|
||||||
|
defaultLocale: "en",
|
||||||
|
},
|
||||||
|
images: {
|
||||||
|
domains: ["avatars.githubusercontent.com", "lh3.googleusercontent.com"],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const nextConfig = withPWA({
|
||||||
|
dest: "public",
|
||||||
|
})(config);
|
||||||
|
export default nextConfig;
|
57
package.json
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
{
|
||||||
|
"name": "sprintpadawan",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Plan. Sprint. Repeat.",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"build": "next build",
|
||||||
|
"dev": "next dev",
|
||||||
|
"postinstall": "prisma generate",
|
||||||
|
"lint": "next lint",
|
||||||
|
"start": "next start"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@ably-labs/react-hooks": "^2.1.1",
|
||||||
|
"@next-auth/prisma-adapter": "^1.0.6",
|
||||||
|
"@prisma/client": "4.14.0",
|
||||||
|
"@tailwindcss/typography": "^0.5.9",
|
||||||
|
"@tanstack/react-query": "^4.29.5",
|
||||||
|
"@trpc/client": "10.26.0",
|
||||||
|
"@trpc/next": "10.26.0",
|
||||||
|
"@trpc/react-query": "10.26.0",
|
||||||
|
"@trpc/server": "10.26.0",
|
||||||
|
"@types/json2csv": "^5.0.3",
|
||||||
|
"@types/next-pwa": "^5.6.2",
|
||||||
|
"@vercel/analytics": "^1.0.1",
|
||||||
|
"ably": "^1.2.39",
|
||||||
|
"autoprefixer": "^10.4.14",
|
||||||
|
"daisyui": "^2.51.6",
|
||||||
|
"ioredis": "^5.3.2",
|
||||||
|
"json2csv": "6.0.0-alpha.2",
|
||||||
|
"next": "^13.4.2",
|
||||||
|
"next-auth": "^4.22.1",
|
||||||
|
"next-pwa": "^5.6.0",
|
||||||
|
"postcss": "^8.4.23",
|
||||||
|
"react": "18.2.0",
|
||||||
|
"react-dom": "18.2.0",
|
||||||
|
"react-icons": "^4.8.0",
|
||||||
|
"superjson": "1.12.3",
|
||||||
|
"tailwindcss": "^3.3.2",
|
||||||
|
"zod": "^3.21.4"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/eslint": "^8.37.0",
|
||||||
|
"@types/node": "^20.1.4",
|
||||||
|
"@types/react": "^18.2.6",
|
||||||
|
"@types/react-dom": "^18.2.4",
|
||||||
|
"@typescript-eslint/eslint-plugin": "^5.59.5",
|
||||||
|
"@typescript-eslint/parser": "^5.59.5",
|
||||||
|
"eslint": "^8.40.0",
|
||||||
|
"eslint-config-next": "^13.4.2",
|
||||||
|
"prisma": "4.14.0",
|
||||||
|
"typescript": "^5.0.4"
|
||||||
|
},
|
||||||
|
"ct3aMetadata": {
|
||||||
|
"initVersion": "7.5.9"
|
||||||
|
}
|
||||||
|
}
|
5895
pnpm-lock.yaml
generated
Normal file
6
postcss.config.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
module.exports = {
|
||||||
|
plugins: {
|
||||||
|
tailwindcss: {},
|
||||||
|
autoprefixer: {},
|
||||||
|
},
|
||||||
|
}
|
114
prisma/schema.prisma
Normal file
|
@ -0,0 +1,114 @@
|
||||||
|
// This is your Prisma schema file,
|
||||||
|
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
||||||
|
|
||||||
|
enum RoleValue {
|
||||||
|
USER
|
||||||
|
ADMIN
|
||||||
|
}
|
||||||
|
|
||||||
|
generator client {
|
||||||
|
provider = "prisma-client-js"
|
||||||
|
previewFeatures = ["jsonProtocol"]
|
||||||
|
}
|
||||||
|
|
||||||
|
datasource db {
|
||||||
|
provider = "postgresql"
|
||||||
|
url = env("DATABASE_URL")
|
||||||
|
}
|
||||||
|
|
||||||
|
model Account {
|
||||||
|
id String @id @default(cuid())
|
||||||
|
createdAt DateTime @default(now())
|
||||||
|
userId String
|
||||||
|
type String
|
||||||
|
provider String
|
||||||
|
providerAccountId String
|
||||||
|
refresh_token String? @db.Text
|
||||||
|
access_token String? @db.Text
|
||||||
|
expires_at Int?
|
||||||
|
token_type String?
|
||||||
|
scope String?
|
||||||
|
id_token String? @db.Text
|
||||||
|
session_state String?
|
||||||
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||||
|
|
||||||
|
@@unique([provider, providerAccountId])
|
||||||
|
@@index([userId])
|
||||||
|
}
|
||||||
|
|
||||||
|
model Session {
|
||||||
|
id String @id @default(cuid())
|
||||||
|
createdAt DateTime @default(now())
|
||||||
|
sessionToken String @unique
|
||||||
|
userId String
|
||||||
|
expires DateTime
|
||||||
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||||
|
|
||||||
|
@@index([userId])
|
||||||
|
}
|
||||||
|
|
||||||
|
model User {
|
||||||
|
id String @id @default(cuid())
|
||||||
|
role RoleValue @default(USER)
|
||||||
|
createdAt DateTime @default(now())
|
||||||
|
name String?
|
||||||
|
email String? @unique
|
||||||
|
emailVerified DateTime?
|
||||||
|
image String?
|
||||||
|
accounts Account[]
|
||||||
|
sessions Session[]
|
||||||
|
rooms Room[]
|
||||||
|
votes Vote[]
|
||||||
|
logs Log[]
|
||||||
|
}
|
||||||
|
|
||||||
|
model VerificationToken {
|
||||||
|
identifier String
|
||||||
|
token String @unique
|
||||||
|
expires DateTime
|
||||||
|
|
||||||
|
@@unique([identifier, token])
|
||||||
|
}
|
||||||
|
|
||||||
|
model Room {
|
||||||
|
id String @id @default(cuid()) @unique
|
||||||
|
createdAt DateTime @default(now())
|
||||||
|
userId String
|
||||||
|
roomName String
|
||||||
|
storyName String
|
||||||
|
visible Boolean
|
||||||
|
votes Vote[]
|
||||||
|
scale String
|
||||||
|
logs Log[]
|
||||||
|
owner User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||||
|
|
||||||
|
@@index([userId])
|
||||||
|
}
|
||||||
|
|
||||||
|
model Vote {
|
||||||
|
id String @id @default(cuid()) @unique
|
||||||
|
createdAt DateTime @default(now())
|
||||||
|
userId String
|
||||||
|
roomId String
|
||||||
|
value String
|
||||||
|
owner User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||||
|
room Room @relation(fields: [roomId], references: [id], onDelete: Cascade)
|
||||||
|
@@unique([userId, roomId])
|
||||||
|
@@index([roomId])
|
||||||
|
}
|
||||||
|
|
||||||
|
model Log {
|
||||||
|
id String @id @default(cuid()) @unique
|
||||||
|
createdAt DateTime @default(now())
|
||||||
|
userId String
|
||||||
|
roomId String
|
||||||
|
scale String
|
||||||
|
votes Json
|
||||||
|
roomName String
|
||||||
|
storyName String
|
||||||
|
owner User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||||
|
room Room @relation(fields: [roomId], references: [id], onDelete: Cascade)
|
||||||
|
|
||||||
|
@@index([userId])
|
||||||
|
@@index([roomId])
|
||||||
|
}
|
BIN
public/android-chrome-192x192.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
public/android-chrome-512x512.png
Normal file
After Width: | Height: | Size: 50 KiB |
BIN
public/apple-touch-icon.png
Normal file
After Width: | Height: | Size: 8.4 KiB |
9
public/browserconfig.xml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<browserconfig>
|
||||||
|
<msapplication>
|
||||||
|
<tile>
|
||||||
|
<square150x150logo src="/mstile-150x150.png"/>
|
||||||
|
<TileColor>#1f2937</TileColor>
|
||||||
|
</tile>
|
||||||
|
</msapplication>
|
||||||
|
</browserconfig>
|
BIN
public/favicon-16x16.png
Normal file
After Width: | Height: | Size: 1 KiB |
BIN
public/favicon-32x32.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
public/favicon.ico
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
public/logo.webp
Normal file
After Width: | Height: | Size: 11 KiB |
27
public/manifest.json
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
{
|
||||||
|
"name": "Sprint Padawan",
|
||||||
|
"short_name": "Sprint Padawan",
|
||||||
|
"icons": [
|
||||||
|
{
|
||||||
|
"src": "/android-chrome-192x192.png",
|
||||||
|
"sizes": "192x192",
|
||||||
|
"type": "image/png",
|
||||||
|
"purpose": "any maskable"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "/android-chrome-512x512.png",
|
||||||
|
"sizes": "512x512",
|
||||||
|
"type": "image/png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "/icons/icon-512x512.png",
|
||||||
|
"sizes": "512x512",
|
||||||
|
"type": "image/png"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"theme_color": "#1F2937",
|
||||||
|
"background_color": "#1F2937",
|
||||||
|
"start_url": "/",
|
||||||
|
"display": "standalone",
|
||||||
|
"orientation": "portrait"
|
||||||
|
}
|
BIN
public/mstile-150x150.png
Normal file
After Width: | Height: | Size: 8.4 KiB |
24
public/safari-pinned-tab.svg
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<?xml version="1.0" standalone="no"?>
|
||||||
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
|
||||||
|
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
||||||
|
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="512.000000pt" height="512.000000pt" viewBox="0 0 512.000000 512.000000"
|
||||||
|
preserveAspectRatio="xMidYMid meet">
|
||||||
|
<metadata>
|
||||||
|
Created by potrace 1.14, written by Peter Selinger 2001-2017
|
||||||
|
</metadata>
|
||||||
|
<g transform="translate(0.000000,512.000000) scale(0.100000,-0.100000)"
|
||||||
|
fill="#000000" stroke="none">
|
||||||
|
<path d="M2280 4865 c-527 -60 -877 -209 -1275 -541 -434 -362 -714 -862 -800
|
||||||
|
-1429 -22 -143 -30 -389 -16 -530 13 -145 66 -382 121 -548 244 -729 860
|
||||||
|
-1302 1605 -1492 224 -58 323 -70 580 -70 247 0 347 11 555 62 401 97 797 323
|
||||||
|
1086 619 163 167 204 218 342 427 206 311 299 602 333 1040 41 529 -75 1030
|
||||||
|
-341 1482 -275 464 -721 789 -1266 921 -264 64 -660 89 -924 59z m638 -1051
|
||||||
|
c12 -14 22 -36 22 -49 0 -24 -98 -297 -265 -735 -47 -124 -85 -231 -85 -237 0
|
||||||
|
-10 74 -13 339 -13 l338 0 27 -26 c30 -31 34 -69 9 -104 -10 -14 -191 -241
|
||||||
|
-403 -505 -212 -264 -454 -566 -538 -671 -84 -106 -159 -195 -168 -198 -57
|
||||||
|
-22 -124 17 -124 71 0 15 77 235 171 488 94 253 173 468 176 477 5 15 -22 17
|
||||||
|
-337 20 l-342 3 -24 28 c-13 15 -24 41 -24 56 0 22 113 170 531 692 292 365
|
||||||
|
543 677 558 693 49 52 97 56 139 10z"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 1.3 KiB |
19
public/site.webmanifest
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
"name": "Sprint Padawan",
|
||||||
|
"short_name": "Sprint Padawan",
|
||||||
|
"icons": [
|
||||||
|
{
|
||||||
|
"src": "/android-chrome-192x192.png",
|
||||||
|
"sizes": "192x192",
|
||||||
|
"type": "image/png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "/android-chrome-512x512.png",
|
||||||
|
"sizes": "512x512",
|
||||||
|
"type": "image/png"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"theme_color": "#1f2937",
|
||||||
|
"background_color": "#1f2937",
|
||||||
|
"display": "standalone"
|
||||||
|
}
|
34
src/components/Footer.tsx
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
import { GiTechnoHeart } from "react-icons/gi";
|
||||||
|
import packagejson from "../../package.json";
|
||||||
|
|
||||||
|
const Footer: React.FC = () => {
|
||||||
|
return (
|
||||||
|
<footer className="footer footer-center h-[48px] p-2 bg-base-100 text-base-content">
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
Made with{" "}
|
||||||
|
<GiTechnoHeart className="inline-block text-primary text-lg" /> by{" "}
|
||||||
|
<a
|
||||||
|
className="link link-primary link-hover"
|
||||||
|
href="https://atridad.dev"
|
||||||
|
rel="noreferrer"
|
||||||
|
target="_blank"
|
||||||
|
>
|
||||||
|
Atridad Lahiji
|
||||||
|
</a>{" "}
|
||||||
|
-{" "}
|
||||||
|
<a
|
||||||
|
className="link link-primary link-hover"
|
||||||
|
href={`https://github.com/atridadl/sprintpadawan/releases/tag/${packagejson.version}`}
|
||||||
|
rel="noreferrer"
|
||||||
|
target="_blank"
|
||||||
|
>
|
||||||
|
v{packagejson.version}
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Footer;
|
14
src/components/Loading.tsx
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
const Loading: React.FC = () => {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className="inline-block h-8 w-8 animate-spin rounded-full border-4 border-solid border-current border-r-transparent align-[-0.125em] motion-reduce:animate-[spin_1.5s_linear_infinite] m-4"
|
||||||
|
role="status"
|
||||||
|
>
|
||||||
|
<span className="!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]">
|
||||||
|
Loading...
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Loading;
|
82
src/components/Navbar.tsx
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
import { useSession, signOut } from "next-auth/react";
|
||||||
|
import Link from "next/link";
|
||||||
|
import Image from "next/image";
|
||||||
|
import { env } from "~/env.mjs";
|
||||||
|
|
||||||
|
interface NavbarProps {
|
||||||
|
title: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Navbar: React.FC<NavbarProps> = ({ title }) => {
|
||||||
|
const { data: sessionData } = useSession();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<nav className="navbar bg-base-100">
|
||||||
|
<div className="flex-1">
|
||||||
|
<Link
|
||||||
|
about="Back to home."
|
||||||
|
href="/"
|
||||||
|
className="btn btn-ghost normal-case text-xl"
|
||||||
|
>
|
||||||
|
<Image
|
||||||
|
className="mr-2"
|
||||||
|
src="/logo.webp"
|
||||||
|
alt="Nav Logo"
|
||||||
|
width={32}
|
||||||
|
height={32}
|
||||||
|
priority
|
||||||
|
/>
|
||||||
|
{title}
|
||||||
|
{env.NEXT_PUBLIC_APP_ENV === "development" && " >> DEVELOPMENT"}
|
||||||
|
{env.NEXT_PUBLIC_APP_ENV === "local" && " >> LOCAL"}
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
{sessionData?.user.image && (
|
||||||
|
<div className="flex-none gap-2">
|
||||||
|
<div className="dropdown dropdown-end">
|
||||||
|
<label tabIndex={0} className="btn btn-ghost btn-circle avatar">
|
||||||
|
<div className="w-10 rounded-full">
|
||||||
|
<Image
|
||||||
|
src={sessionData.user.image}
|
||||||
|
alt="Profile picture."
|
||||||
|
height={32}
|
||||||
|
width={32}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</label>
|
||||||
|
<ul
|
||||||
|
tabIndex={0}
|
||||||
|
className="mt-3 p-2 shadow menu menu-compact dropdown-content bg-base-100 rounded-box w-52"
|
||||||
|
>
|
||||||
|
<li>
|
||||||
|
<Link
|
||||||
|
about="Profile Page"
|
||||||
|
href="/profile"
|
||||||
|
className="justify-between"
|
||||||
|
>
|
||||||
|
Profile
|
||||||
|
</Link>
|
||||||
|
</li>
|
||||||
|
{sessionData.user.role === "ADMIN" && (
|
||||||
|
<li>
|
||||||
|
<Link
|
||||||
|
about="Admin Page"
|
||||||
|
href="/admin"
|
||||||
|
className="justify-between"
|
||||||
|
>
|
||||||
|
Admin
|
||||||
|
</Link>
|
||||||
|
</li>
|
||||||
|
)}
|
||||||
|
<li>
|
||||||
|
<a onClick={() => void signOut()}>Sign Out</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</nav>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Navbar;
|
148
src/components/RoomList.tsx
Normal file
|
@ -0,0 +1,148 @@
|
||||||
|
import { useSession } from "next-auth/react";
|
||||||
|
import Link from "next/link";
|
||||||
|
|
||||||
|
import { api } from "~/utils/api";
|
||||||
|
import { IoEnterOutline, IoTrashBinOutline } from "react-icons/io5";
|
||||||
|
import { configureAbly, useChannel } from "@ably-labs/react-hooks";
|
||||||
|
import { env } from "~/env.mjs";
|
||||||
|
import Loading from "./Loading";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
|
const RoomList: React.FC = () => {
|
||||||
|
const { data: sessionData } = useSession();
|
||||||
|
|
||||||
|
configureAbly({
|
||||||
|
key: env.NEXT_PUBLIC_ABLY_PUBLIC_KEY,
|
||||||
|
clientId: sessionData?.user.id,
|
||||||
|
recover: (_, cb) => {
|
||||||
|
cb(true);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const [] = useChannel(
|
||||||
|
`${env.NEXT_PUBLIC_APP_ENV}-${sessionData ? sessionData.user.id : ""}`,
|
||||||
|
() => void refetchRoomsFromDb()
|
||||||
|
);
|
||||||
|
|
||||||
|
const [roomName, setRoomName] = useState<string>("");
|
||||||
|
|
||||||
|
const { data: roomsFromDb, refetch: refetchRoomsFromDb } =
|
||||||
|
api.room.getAll.useQuery(undefined, {
|
||||||
|
enabled: sessionData?.user !== undefined,
|
||||||
|
});
|
||||||
|
|
||||||
|
const createRoom = api.room.create.useMutation({});
|
||||||
|
|
||||||
|
const createRoomHandler = () => {
|
||||||
|
createRoom.mutate({ name: roomName });
|
||||||
|
setRoomName("");
|
||||||
|
(document.querySelector("#roomNameInput") as HTMLInputElement).value = "";
|
||||||
|
(document.querySelector("#new-room-modal") as HTMLInputElement).checked =
|
||||||
|
false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const deleteRoom = api.room.delete.useMutation({});
|
||||||
|
|
||||||
|
const deleteRoomHandler = (roomId: string) => {
|
||||||
|
if (sessionData) {
|
||||||
|
deleteRoom.mutate({ id: roomId });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="prose flex flex-col items-center justify-center">
|
||||||
|
{/* Modal for Adding Rooms */}
|
||||||
|
<input type="checkbox" id="new-room-modal" className="modal-toggle" />
|
||||||
|
<div className="modal modal-bottom sm:modal-middle">
|
||||||
|
<div className="modal-box flex-col flex text-center justify-center items-center">
|
||||||
|
<label
|
||||||
|
htmlFor="new-room-modal"
|
||||||
|
className="btn btn-sm btn-circle absolute right-2 top-2"
|
||||||
|
>
|
||||||
|
✕
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<h3 className="font-bold text-lg">Create a new room!</h3>
|
||||||
|
|
||||||
|
<div className="form-control w-full max-w-xs">
|
||||||
|
<label className="label">
|
||||||
|
<span className="label-text">Room Name</span>
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
id="roomNameInput"
|
||||||
|
type="text"
|
||||||
|
placeholder="Type here"
|
||||||
|
className="input input-bordered w-full max-w-xs"
|
||||||
|
onChange={(event) => {
|
||||||
|
setRoomName(event.target.value);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="modal-action">
|
||||||
|
{roomName.length > 0 && (
|
||||||
|
<label
|
||||||
|
htmlFor="new-room-modal"
|
||||||
|
className="btn btn-primary"
|
||||||
|
onClick={() => createRoomHandler()}
|
||||||
|
>
|
||||||
|
Submit
|
||||||
|
</label>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{roomsFromDb && roomsFromDb.length > 0 && (
|
||||||
|
<div className="overflow-x-auto">
|
||||||
|
<table className="w-full text-center break-all">
|
||||||
|
{/* head */}
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Room Name</th>
|
||||||
|
<th>Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody className="">
|
||||||
|
{roomsFromDb?.map((room) => {
|
||||||
|
return (
|
||||||
|
<tr key={room.id}>
|
||||||
|
<td className="break-all max-w-[200px] md:max-w-[400px]">
|
||||||
|
{room.roomName}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<Link
|
||||||
|
className="m-2 no-underline"
|
||||||
|
href={`/room/${room.id}`}
|
||||||
|
>
|
||||||
|
<IoEnterOutline className="text-xl inline-block hover:text-secondary" />
|
||||||
|
</Link>
|
||||||
|
|
||||||
|
<button
|
||||||
|
className="m-2"
|
||||||
|
onClick={() => deleteRoomHandler(room.id)}
|
||||||
|
>
|
||||||
|
<IoTrashBinOutline className="text-xl inline-block hover:text-error" />
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<label htmlFor="new-room-modal" className="btn btn-secondary">
|
||||||
|
New Room
|
||||||
|
</label>
|
||||||
|
|
||||||
|
{roomsFromDb === undefined && (
|
||||||
|
<div className="flex items-center justify-center">
|
||||||
|
<Loading />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default RoomList;
|
112
src/env.mjs
Normal file
|
@ -0,0 +1,112 @@
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify your server-side environment variables schema here. This way you can ensure the app isn't
|
||||||
|
* built with invalid env vars.
|
||||||
|
*/
|
||||||
|
const server = z.object({
|
||||||
|
DATABASE_URL: z.string().url(),
|
||||||
|
REDIS_URL: z.string().url(),
|
||||||
|
NODE_ENV: z.enum(["development", "test", "production"]),
|
||||||
|
NEXTAUTH_SECRET:
|
||||||
|
process.env.NODE_ENV === "production"
|
||||||
|
? z.string().min(1)
|
||||||
|
: z.string().min(1).optional(),
|
||||||
|
NEXTAUTH_URL: z.preprocess(
|
||||||
|
// This makes Vercel deployments not fail if you don't set NEXTAUTH_URL
|
||||||
|
// Since NextAuth.js automatically uses the VERCEL_URL if present.
|
||||||
|
(str) => process.env.VERCEL_URL ?? str,
|
||||||
|
// VERCEL_URL doesn't include `https` so it cant be validated as a URL
|
||||||
|
process.env.VERCEL ? z.string().min(1) : z.string().url()
|
||||||
|
),
|
||||||
|
// Add `.min(1) on ID and SECRET if you want to make sure they're not empty
|
||||||
|
GITHUB_CLIENT_ID: z.string(),
|
||||||
|
GITHUB_CLIENT_SECRET: z.string(),
|
||||||
|
GOOGLE_CLIENT_ID: z.string(),
|
||||||
|
GOOGLE_CLIENT_SECRET: z.string(),
|
||||||
|
ABLY_PRIVATE_KEY: z.string(),
|
||||||
|
APP_ENV: z.string(),
|
||||||
|
JMAP_TOKEN: z.string(),
|
||||||
|
JMAP_USERNAME: z.string(),
|
||||||
|
JMAP_HOSTNAME: z.string(),
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify your client-side environment variables schema here. This way you can ensure the app isn't
|
||||||
|
* built with invalid env vars. To expose them to the client, prefix them with `NEXT_PUBLIC_`.
|
||||||
|
*/
|
||||||
|
const client = z.object({
|
||||||
|
NEXT_PUBLIC_ABLY_PUBLIC_KEY: z.string(),
|
||||||
|
NEXT_PUBLIC_APP_ENV: z.string(),
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* You can't destruct `process.env` as a regular object in the Next.js edge runtimes (e.g.
|
||||||
|
* middlewares) or client-side so we need to destruct manually.
|
||||||
|
*
|
||||||
|
* @type {Record<keyof z.infer<typeof server> | keyof z.infer<typeof client>, string | undefined>}
|
||||||
|
*/
|
||||||
|
const processEnv = {
|
||||||
|
DATABASE_URL: process.env.DATABASE_URL,
|
||||||
|
REDIS_URL: process.env.REDIS_URL,
|
||||||
|
NODE_ENV: process.env.NODE_ENV,
|
||||||
|
NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET,
|
||||||
|
NEXTAUTH_URL: process.env.NEXTAUTH_URL,
|
||||||
|
GITHUB_CLIENT_ID: process.env.GITHUB_CLIENT_ID,
|
||||||
|
GITHUB_CLIENT_SECRET: process.env.GITHUB_CLIENT_SECRET,
|
||||||
|
GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID,
|
||||||
|
GOOGLE_CLIENT_SECRET: process.env.GOOGLE_CLIENT_SECRET,
|
||||||
|
ABLY_PRIVATE_KEY: process.env.ABLY_PRIVATE_KEY,
|
||||||
|
NEXT_PUBLIC_ABLY_PUBLIC_KEY: process.env.NEXT_PUBLIC_ABLY_PUBLIC_KEY,
|
||||||
|
APP_ENV: process.env.APP_ENV,
|
||||||
|
NEXT_PUBLIC_APP_ENV: process.env.NEXT_PUBLIC_APP_ENV,
|
||||||
|
JMAP_TOKEN: process.env.JMAP_TOKEN,
|
||||||
|
JMAP_USERNAME: process.env.JMAP_USERNAME,
|
||||||
|
JMAP_HOSTNAME: process.env.JMAP_HOSTNAME,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Don't touch the part below
|
||||||
|
// --------------------------
|
||||||
|
|
||||||
|
const merged = server.merge(client);
|
||||||
|
|
||||||
|
/** @typedef {z.input<typeof merged>} MergedInput */
|
||||||
|
/** @typedef {z.infer<typeof merged>} MergedOutput */
|
||||||
|
/** @typedef {z.SafeParseReturnType<MergedInput, MergedOutput>} MergedSafeParseReturn */
|
||||||
|
|
||||||
|
let env = /** @type {MergedOutput} */ (process.env);
|
||||||
|
|
||||||
|
if (!!process.env.SKIP_ENV_VALIDATION == false) {
|
||||||
|
const isServer = typeof window === "undefined";
|
||||||
|
|
||||||
|
const parsed = /** @type {MergedSafeParseReturn} */ (
|
||||||
|
isServer
|
||||||
|
? merged.safeParse(processEnv) // on server we can validate all env vars
|
||||||
|
: client.safeParse(processEnv) // on client we can only validate the ones that are exposed
|
||||||
|
);
|
||||||
|
|
||||||
|
if (parsed.success === false) {
|
||||||
|
console.error(
|
||||||
|
"❌ Invalid environment variables:",
|
||||||
|
parsed.error.flatten().fieldErrors
|
||||||
|
);
|
||||||
|
throw new Error("Invalid environment variables");
|
||||||
|
}
|
||||||
|
|
||||||
|
env = new Proxy(parsed.data, {
|
||||||
|
get(target, prop) {
|
||||||
|
if (typeof prop !== "string") return undefined;
|
||||||
|
// Throw a descriptive error if a server-side env var is accessed on the client
|
||||||
|
// Otherwise it would just be returning `undefined` and be annoying to debug
|
||||||
|
if (!isServer && !prop.startsWith("NEXT_PUBLIC_"))
|
||||||
|
throw new Error(
|
||||||
|
process.env.NODE_ENV === "production"
|
||||||
|
? "❌ Attempted to access a server-side environment variable on the client"
|
||||||
|
: `❌ Attempted to access server-side environment variable '${prop}' on the client`
|
||||||
|
);
|
||||||
|
return target[/** @type {keyof typeof target} */ (prop)];
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export { env };
|
57
src/pages/_app.tsx
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
import { type AppType } from "next/app";
|
||||||
|
import { type Session } from "next-auth";
|
||||||
|
import { SessionProvider } from "next-auth/react";
|
||||||
|
import { Analytics } from "@vercel/analytics/react";
|
||||||
|
|
||||||
|
import { api } from "~/utils/api";
|
||||||
|
|
||||||
|
import "~/styles/globals.css";
|
||||||
|
import Navbar from "~/components/Navbar";
|
||||||
|
import { useRouter } from "next/router";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import Loading from "~/components/Loading";
|
||||||
|
import Footer from "~/components/Footer";
|
||||||
|
|
||||||
|
const MyApp: AppType<{ session: Session | null }> = ({
|
||||||
|
Component,
|
||||||
|
pageProps: { session, ...pageProps },
|
||||||
|
}) => {
|
||||||
|
const [pageLoading, setPageLoading] = useState<boolean>(false);
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
router.events.on("routeChangeStart", () => {
|
||||||
|
setPageLoading(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
router.events.on("routeChangeComplete", () => {
|
||||||
|
setPageLoading(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
router.events.off("routeChangeStart", () => {
|
||||||
|
setPageLoading(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
router.events.off("routeChangeComplete", () => {
|
||||||
|
setPageLoading(false);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}, [router.events]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SessionProvider session={session}>
|
||||||
|
<div className="block h-[100%]">
|
||||||
|
<Navbar title="Sprint Padawan" />
|
||||||
|
<div className="flex flex-row items-center justify-center min-h-[calc(100%-114px)]">
|
||||||
|
{pageLoading ? <Loading /> : <Component {...pageProps} />}
|
||||||
|
</div>
|
||||||
|
<Footer />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Analytics />
|
||||||
|
</SessionProvider>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default api.withTRPC(MyApp);
|
62
src/pages/_document.tsx
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
import { Html, Head, Main, NextScript } from "next/document";
|
||||||
|
|
||||||
|
export default function Document() {
|
||||||
|
return (
|
||||||
|
<Html>
|
||||||
|
<Head>
|
||||||
|
<meta name="application-name" content="Sprint Padawan" />
|
||||||
|
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||||
|
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
|
||||||
|
<meta name="apple-mobile-web-app-title" content="Sprint Padawan" />
|
||||||
|
<meta name="description" content="Plan. Sprint. Repeat." />
|
||||||
|
<meta name="format-detection" content="telephone=no" />
|
||||||
|
<meta name="mobile-web-app-capable" content="yes" />
|
||||||
|
<meta name="msapplication-config" content="/icons/browserconfig.xml" />
|
||||||
|
<meta name="msapplication-TileColor" content="#1F2937" />
|
||||||
|
<meta name="msapplication-tap-highlight" content="no" />
|
||||||
|
<meta name="theme-color" content="#1F2937" />
|
||||||
|
|
||||||
|
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
|
||||||
|
|
||||||
|
<link
|
||||||
|
rel="icon"
|
||||||
|
type="image/png"
|
||||||
|
sizes="32x32"
|
||||||
|
href="/favicon-32x32.png"
|
||||||
|
/>
|
||||||
|
<link
|
||||||
|
rel="icon"
|
||||||
|
type="image/png"
|
||||||
|
sizes="16x16"
|
||||||
|
href="/favicon-16x16.png"
|
||||||
|
/>
|
||||||
|
<link rel="manifest" href="/manifest.json" />
|
||||||
|
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5" />
|
||||||
|
<link rel="shortcut icon" href="/favicon.ico" />
|
||||||
|
|
||||||
|
<meta name="twitter:card" content="summary" />
|
||||||
|
<meta name="twitter:url" content="https://sprintpadawan.dev" />
|
||||||
|
<meta name="twitter:title" content="Sprint Padawan" />
|
||||||
|
<meta name="twitter:description" content="Plan. Sprint. Repeat." />
|
||||||
|
<meta
|
||||||
|
name="twitter:image"
|
||||||
|
content="https://sprintpadawan.dev/android-chrome-192x192.png"
|
||||||
|
/>
|
||||||
|
<meta name="twitter:creator" content="@atridadl" />
|
||||||
|
<meta property="og:type" content="website" />
|
||||||
|
<meta property="og:title" content="Sprint Padawan" />
|
||||||
|
<meta property="og:description" content="Plan. Sprint. Repeat." />
|
||||||
|
<meta property="og:site_name" content="Sprint Padawan" />
|
||||||
|
<meta property="og:url" content="https://sprintpadawan.dev" />
|
||||||
|
<meta
|
||||||
|
property="og:image"
|
||||||
|
content="https://sprintpadawan.dev/icons/apple-touch-icon.png"
|
||||||
|
/>
|
||||||
|
</Head>
|
||||||
|
<body>
|
||||||
|
<Main />
|
||||||
|
<NextScript />
|
||||||
|
</body>
|
||||||
|
</Html>
|
||||||
|
);
|
||||||
|
}
|
256
src/pages/admin/index.tsx
Normal file
|
@ -0,0 +1,256 @@
|
||||||
|
import { type NextPage } from "next";
|
||||||
|
import Head from "next/head";
|
||||||
|
import { type GetServerSideProps } from "next";
|
||||||
|
|
||||||
|
import { getServerAuthSession } from "../../server/auth";
|
||||||
|
import { api } from "~/utils/api";
|
||||||
|
import Loading from "~/components/Loading";
|
||||||
|
import { IoTrashBinOutline } from "react-icons/io5";
|
||||||
|
import { AiOutlineClear } from "react-icons/ai";
|
||||||
|
import { FaShieldAlt } from "react-icons/fa";
|
||||||
|
import type { Role } from "~/utils/types";
|
||||||
|
|
||||||
|
export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||||
|
const session = await getServerAuthSession(ctx);
|
||||||
|
|
||||||
|
// Redirect to home if not logged in
|
||||||
|
if (!session) {
|
||||||
|
return {
|
||||||
|
redirect: {
|
||||||
|
destination: "/",
|
||||||
|
permanent: false,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (session.user.role !== "ADMIN") {
|
||||||
|
ctx.res.statusCode = 403;
|
||||||
|
return {
|
||||||
|
redirect: {
|
||||||
|
destination: "/",
|
||||||
|
permanent: false,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// Return session if logged in
|
||||||
|
return {
|
||||||
|
props: { session },
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const Admin: NextPage = () => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Head>
|
||||||
|
<title>Sprint Padawan - Admin</title>
|
||||||
|
<meta name="description" content="Plan. Sprint. Repeat." />
|
||||||
|
</Head>
|
||||||
|
<div className="flex flex-col items-center justify-center text-center px-4 py-16 ">
|
||||||
|
<div className="flex flex-col items-center prose">
|
||||||
|
<AdminBody />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Admin;
|
||||||
|
|
||||||
|
const AdminBody: React.FC = () => {
|
||||||
|
const {
|
||||||
|
data: usersCount,
|
||||||
|
isLoading: usersCountLoading,
|
||||||
|
isFetching: usersCountFetching,
|
||||||
|
refetch: refetchUsersCount,
|
||||||
|
} = api.user.countAll.useQuery();
|
||||||
|
const {
|
||||||
|
data: users,
|
||||||
|
isLoading: usersLoading,
|
||||||
|
isFetching: usersFetching,
|
||||||
|
refetch: refetchUsers,
|
||||||
|
} = api.user.getAll.useQuery();
|
||||||
|
const {
|
||||||
|
data: roomsCount,
|
||||||
|
isLoading: roomsCountLoading,
|
||||||
|
isFetching: roomsCountFetching,
|
||||||
|
refetch: refetchRoomsCount,
|
||||||
|
} = api.room.countAll.useQuery();
|
||||||
|
const {
|
||||||
|
data: votesCount,
|
||||||
|
isLoading: votesCountLoading,
|
||||||
|
isFetching: votesCountFetching,
|
||||||
|
refetch: refetchVotesCount,
|
||||||
|
} = api.vote.countAll.useQuery();
|
||||||
|
|
||||||
|
const deleteUserMutation = api.user.delete.useMutation({
|
||||||
|
onSuccess: async () => {
|
||||||
|
await refetchData();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const clearSessionsMutation = api.session.deleteAll.useMutation({
|
||||||
|
onSuccess: async () => {
|
||||||
|
await refetchData();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const setRoleMutation = api.user.setRole.useMutation({
|
||||||
|
onSuccess: async () => {
|
||||||
|
await refetchData();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const deleteUserHandler = async (userId: string) => {
|
||||||
|
await deleteUserMutation.mutateAsync({ userId });
|
||||||
|
};
|
||||||
|
|
||||||
|
const clearSessionsHandler = async (userId: string) => {
|
||||||
|
await clearSessionsMutation.mutateAsync({ userId });
|
||||||
|
};
|
||||||
|
|
||||||
|
const setUserRoleHandler = async (userId: string, role: Role) => {
|
||||||
|
await setRoleMutation.mutateAsync({ userId, role });
|
||||||
|
};
|
||||||
|
|
||||||
|
const refetchData = async () => {
|
||||||
|
await Promise.all([
|
||||||
|
refetchUsers(),
|
||||||
|
refetchUsersCount(),
|
||||||
|
refetchRoomsCount(),
|
||||||
|
refetchVotesCount(),
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<h1>Admin Panel</h1>
|
||||||
|
|
||||||
|
<div className="stats stats-horizontal shadow bg-neutral m-4">
|
||||||
|
<div className="stat">
|
||||||
|
<div className="stat-title">Users</div>
|
||||||
|
<div className="stat-value">
|
||||||
|
{usersCountLoading || usersCountFetching ? (
|
||||||
|
<Loading />
|
||||||
|
) : (
|
||||||
|
<>{usersCount ? usersCount : "0"}</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="stat">
|
||||||
|
<div className="stat-title">Rooms</div>
|
||||||
|
<div className="stat-value">
|
||||||
|
{roomsCountLoading || roomsCountFetching ? (
|
||||||
|
<Loading />
|
||||||
|
) : (
|
||||||
|
<>{roomsCount ? roomsCount : "0"}</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="stat">
|
||||||
|
<div className="stat-title">Votes</div>
|
||||||
|
<div className="stat-value">
|
||||||
|
{votesCountLoading || votesCountFetching ? (
|
||||||
|
<Loading />
|
||||||
|
) : (
|
||||||
|
<>{votesCount ? votesCount : "0"}</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{usersCountFetching ||
|
||||||
|
usersFetching ||
|
||||||
|
roomsCountFetching ||
|
||||||
|
votesCountFetching ? (
|
||||||
|
<button className="btn btn-primary loading">Fetching...</button>
|
||||||
|
) : (
|
||||||
|
<button className="btn btn-primary" onClick={() => void refetchData()}>
|
||||||
|
Re-fetch
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="card max-w-[80vw] bg-neutral shadow-xl m-4">
|
||||||
|
<div className="card-body">
|
||||||
|
<h2 className="card-title">Users:</h2>
|
||||||
|
|
||||||
|
{usersLoading || usersFetching ? (
|
||||||
|
<Loading />
|
||||||
|
) : (
|
||||||
|
<div className="overflow-x-scroll w-[calc(80vw-4rem)]">
|
||||||
|
<table className="w-full text-center">
|
||||||
|
{/* head */}
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Created At</th>
|
||||||
|
<th># Sessions</th>
|
||||||
|
<th>Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody className="">
|
||||||
|
{users
|
||||||
|
?.sort((user1, user2) =>
|
||||||
|
user2.createdAt > user1.createdAt ? 1 : -1
|
||||||
|
)
|
||||||
|
.map((user) => {
|
||||||
|
return (
|
||||||
|
<tr key={user.id}>
|
||||||
|
<td className="max-w-[100px] break-words">
|
||||||
|
{user.id}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td className="max-w-[100px] break-normal">
|
||||||
|
{user.name}
|
||||||
|
</td>
|
||||||
|
<td className="max-w-[100px] break-normal">
|
||||||
|
{user.createdAt.toLocaleDateString()}
|
||||||
|
</td>
|
||||||
|
<td className="max-w-[100px] break-normal">
|
||||||
|
{user.sessions.length}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<button className="m-2">
|
||||||
|
{user.role === "ADMIN" ? (
|
||||||
|
<FaShieldAlt
|
||||||
|
className="text-xl inline-block text-primary"
|
||||||
|
onClick={() =>
|
||||||
|
void setUserRoleHandler(user.id, "USER")
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<FaShieldAlt
|
||||||
|
className="text-xl inline-block"
|
||||||
|
onClick={() =>
|
||||||
|
void setUserRoleHandler(user.id, "ADMIN")
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="m-2"
|
||||||
|
onClick={() => void clearSessionsHandler(user.id)}
|
||||||
|
>
|
||||||
|
<AiOutlineClear className="text-xl inline-block hover:text-warning" />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="m-2"
|
||||||
|
onClick={() => void deleteUserHandler(user.id)}
|
||||||
|
>
|
||||||
|
<IoTrashBinOutline className="text-xl inline-block hover:text-error" />
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
4
src/pages/api/auth/[...nextauth].ts
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
import NextAuth from "next-auth";
|
||||||
|
import { authOptions } from "~/server/auth";
|
||||||
|
|
||||||
|
export default NextAuth(authOptions);
|
19
src/pages/api/trpc/[trpc].ts
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import { createNextApiHandler } from "@trpc/server/adapters/next";
|
||||||
|
|
||||||
|
import { env } from "~/env.mjs";
|
||||||
|
import { createTRPCContext } from "~/server/api/trpc";
|
||||||
|
import { appRouter } from "~/server/api/root";
|
||||||
|
|
||||||
|
// export API handler
|
||||||
|
export default createNextApiHandler({
|
||||||
|
router: appRouter,
|
||||||
|
createContext: createTRPCContext,
|
||||||
|
onError:
|
||||||
|
env.NODE_ENV === "development"
|
||||||
|
? ({ path, error }) => {
|
||||||
|
console.error(
|
||||||
|
`❌ tRPC failed on ${path ?? "<no-path>"}: ${error.message}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
|
});
|
126
src/pages/index.tsx
Normal file
|
@ -0,0 +1,126 @@
|
||||||
|
import { type NextPage } from "next";
|
||||||
|
import Head from "next/head";
|
||||||
|
import { signIn, useSession } from "next-auth/react";
|
||||||
|
|
||||||
|
import RoomList from "~/components/RoomList";
|
||||||
|
|
||||||
|
import { useState } from "react";
|
||||||
|
import Link from "next/link";
|
||||||
|
import Loading from "~/components/Loading";
|
||||||
|
import { FaShieldAlt } from "react-icons/fa";
|
||||||
|
|
||||||
|
const Home: NextPage = () => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Head>
|
||||||
|
<title>Sprint Padawan</title>
|
||||||
|
<meta name="description" content="Plan. Sprint. Repeat." />
|
||||||
|
</Head>
|
||||||
|
<div className="prose flex flex-col text-center items-center justify-center px-4 py-16">
|
||||||
|
<HomePageBody />
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Home;
|
||||||
|
|
||||||
|
const HomePageBody: React.FC = () => {
|
||||||
|
const { data: sessionData, status: sessionStatus } = useSession();
|
||||||
|
const [joinRoomTextBox, setJoinRoomTextBox] = useState<string>("");
|
||||||
|
const [tabIndex, setTabIndex] = useState<number>(0);
|
||||||
|
|
||||||
|
if (sessionStatus === "authenticated") {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<h1 className="flex flex-row flex-wrap text-center justify-center items-center gap-1 text-md mx-auto">
|
||||||
|
Hi, {sessionData.user.name}!{" "}
|
||||||
|
{sessionData.user.role === "ADMIN" && (
|
||||||
|
<FaShieldAlt className="inline-block text-primary" />
|
||||||
|
)}
|
||||||
|
</h1>
|
||||||
|
<div className="tabs tabs-boxed border-2 border-cyan-500 mb-4">
|
||||||
|
<a
|
||||||
|
className={
|
||||||
|
tabIndex === 0
|
||||||
|
? "tab no-underline tab-active"
|
||||||
|
: "tab no-underline"
|
||||||
|
}
|
||||||
|
onClick={() => setTabIndex(0)}
|
||||||
|
>
|
||||||
|
Join a Room
|
||||||
|
</a>
|
||||||
|
<a
|
||||||
|
className={
|
||||||
|
tabIndex === 1
|
||||||
|
? "tab no-underline tab-active"
|
||||||
|
: "tab no-underline"
|
||||||
|
}
|
||||||
|
onClick={() => setTabIndex(1)}
|
||||||
|
>
|
||||||
|
Room List
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{tabIndex === 0 && (
|
||||||
|
<>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="Enter Room ID"
|
||||||
|
className="input input-bordered input-primary mb-4"
|
||||||
|
onChange={(event) => {
|
||||||
|
console.log(event.target.value);
|
||||||
|
setJoinRoomTextBox(event.target.value);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Link
|
||||||
|
href={
|
||||||
|
joinRoomTextBox.length > 0 ? `/room/${joinRoomTextBox}` : "/"
|
||||||
|
}
|
||||||
|
className="btn btn-secondary"
|
||||||
|
>
|
||||||
|
Join Room
|
||||||
|
</Link>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{tabIndex === 1 && <RoomList />}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<h1 className="text-6xl">
|
||||||
|
Sprint{" "}
|
||||||
|
<span className="bg-gradient-to-br from-pink-600 to-cyan-400 bg-clip-text text-transparent box-decoration-clone">
|
||||||
|
Padawan
|
||||||
|
</span>
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
<h2 className="my-4 text-3xl">
|
||||||
|
A{" "}
|
||||||
|
<span className="bg-gradient-to-br from-pink-600 to-pink-400 bg-clip-text text-transparent box-decoration-clone">
|
||||||
|
scrum poker{" "}
|
||||||
|
</span>{" "}
|
||||||
|
tool that helps{" "}
|
||||||
|
<span className="bg-gradient-to-br from-purple-600 to-purple-400 bg-clip-text text-transparent box-decoration-clone">
|
||||||
|
agile teams{" "}
|
||||||
|
</span>{" "}
|
||||||
|
plan their sprints in{" "}
|
||||||
|
<span className="bg-gradient-to-br from-cyan-600 to-cyan-400 bg-clip-text text-transparent box-decoration-clone">
|
||||||
|
real-time
|
||||||
|
</span>
|
||||||
|
.
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
{sessionStatus === "loading" ? (
|
||||||
|
<Loading />
|
||||||
|
) : (
|
||||||
|
<button className="btn btn-secondary" onClick={() => void signIn()}>
|
||||||
|
Sign In
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
192
src/pages/profile/index.tsx
Normal file
|
@ -0,0 +1,192 @@
|
||||||
|
import { type NextPage } from "next";
|
||||||
|
import Image from "next/image";
|
||||||
|
import Head from "next/head";
|
||||||
|
import { type GetServerSideProps } from "next";
|
||||||
|
|
||||||
|
import { getServerAuthSession } from "../../server/auth";
|
||||||
|
import { api } from "~/utils/api";
|
||||||
|
import { signIn, useSession } from "next-auth/react";
|
||||||
|
import { useRouter } from "next/router";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import Loading from "~/components/Loading";
|
||||||
|
import { FaGithub, FaGoogle } from "react-icons/fa";
|
||||||
|
|
||||||
|
export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||||
|
const session = await getServerAuthSession(ctx);
|
||||||
|
|
||||||
|
// Redirect to home if not logged in
|
||||||
|
if (!session) {
|
||||||
|
return {
|
||||||
|
redirect: {
|
||||||
|
destination: "/",
|
||||||
|
permanent: false,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return session if logged in
|
||||||
|
return {
|
||||||
|
props: { session },
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const Profile: NextPage = () => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Head>
|
||||||
|
<title>Sprint Padawan - Profile</title>
|
||||||
|
<meta name="description" content="Plan. Sprint. Repeat." />
|
||||||
|
</Head>
|
||||||
|
<div className="flex flex-col items-center justify-center text-center gap-12 px-4 py-16 ">
|
||||||
|
<div className="flex flex-col items-center prose">
|
||||||
|
<ProfileBody />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Profile;
|
||||||
|
|
||||||
|
const ProfileBody: React.FC = () => {
|
||||||
|
const { data: sessionData } = useSession();
|
||||||
|
const [nameText, setNameText] = useState<string>("");
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const { data: providers, isLoading: providersLoading } =
|
||||||
|
api.user.getProviders.useQuery();
|
||||||
|
|
||||||
|
const deleteUserMutation = api.user.delete.useMutation({});
|
||||||
|
const saveUserMutation = api.user.save.useMutation({});
|
||||||
|
|
||||||
|
const deleteCurrentUser = async () => {
|
||||||
|
await deleteUserMutation.mutateAsync();
|
||||||
|
(document.querySelector("#delete-user-modal") as HTMLInputElement).checked =
|
||||||
|
false;
|
||||||
|
router.reload();
|
||||||
|
};
|
||||||
|
|
||||||
|
const saveUser = async () => {
|
||||||
|
await saveUserMutation.mutateAsync({
|
||||||
|
name: nameText,
|
||||||
|
});
|
||||||
|
router.reload();
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setNameText(sessionData?.user.name || "");
|
||||||
|
}, [sessionData]);
|
||||||
|
|
||||||
|
if (sessionData) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
id="delete-user-modal"
|
||||||
|
className="modal-toggle"
|
||||||
|
/>
|
||||||
|
<div className="modal modal-bottom sm:modal-middle">
|
||||||
|
<div className="modal-box flex-col flex text-center justify-center items-center">
|
||||||
|
<label
|
||||||
|
htmlFor="delete-user-modal"
|
||||||
|
className="btn btn-sm btn-circle absolute right-2 top-2"
|
||||||
|
>
|
||||||
|
✕
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<h3 className="font-bold text-lg text-error">
|
||||||
|
This action will delete ALL data associated with your account. The
|
||||||
|
same GitHub Account can be used, but none of your existing data
|
||||||
|
will be available. If you are sure, please confirm below:
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<div className="modal-action">
|
||||||
|
<label
|
||||||
|
htmlFor="delete-user-modal"
|
||||||
|
className="btn btn-error"
|
||||||
|
onClick={() => void deleteCurrentUser()}
|
||||||
|
>
|
||||||
|
I am sure!
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="card w-90 bg-neutral shadow-xl">
|
||||||
|
<div className="card-body">
|
||||||
|
<h2 className="card-title">Profile:</h2>
|
||||||
|
{sessionData.user.image && (
|
||||||
|
<Image
|
||||||
|
className="mx-auto"
|
||||||
|
src={sessionData.user.image}
|
||||||
|
alt="Profile picture."
|
||||||
|
height={100}
|
||||||
|
width={100}
|
||||||
|
priority
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{providersLoading ? (
|
||||||
|
<div className="mx-auto">
|
||||||
|
<Loading />
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="mx-auto">
|
||||||
|
<button
|
||||||
|
className={`btn btn-square btn-outline mx-2`}
|
||||||
|
disabled={providers?.includes("github")}
|
||||||
|
onClick={() => void signIn("github")}
|
||||||
|
>
|
||||||
|
<FaGithub />
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
className={`btn btn-square btn-outline mx-2`}
|
||||||
|
disabled={providers?.includes("google")}
|
||||||
|
onClick={() => void signIn("google")}
|
||||||
|
>
|
||||||
|
<FaGoogle />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{sessionData.user.name && (
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="Name"
|
||||||
|
className="input input-bordered"
|
||||||
|
value={nameText}
|
||||||
|
onChange={(event) => setNameText(event.target.value)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{sessionData.user.email && (
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="Email"
|
||||||
|
className="input input-bordered"
|
||||||
|
value={sessionData.user.email}
|
||||||
|
disabled
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<button
|
||||||
|
onClick={() => void saveUser()}
|
||||||
|
className="btn btn-secondary"
|
||||||
|
>
|
||||||
|
Save Account
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{/* <button className="btn btn-error">Delete Account</button> */}
|
||||||
|
|
||||||
|
<label htmlFor="delete-user-modal" className="btn btn-error">
|
||||||
|
Delete Account
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return <h1>Error getting login session!</h1>;
|
||||||
|
}
|
||||||
|
};
|
474
src/pages/room/[id].tsx
Normal file
|
@ -0,0 +1,474 @@
|
||||||
|
import { type NextPage } from "next";
|
||||||
|
import Image from "next/image";
|
||||||
|
import Head from "next/head";
|
||||||
|
import { type GetServerSideProps } from "next";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
|
import { getServerAuthSession } from "../../server/auth";
|
||||||
|
import { useRouter } from "next/router";
|
||||||
|
import { api } from "~/utils/api";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { useSession } from "next-auth/react";
|
||||||
|
import {
|
||||||
|
IoCopyOutline,
|
||||||
|
IoHourglassOutline,
|
||||||
|
IoCheckmarkCircleOutline,
|
||||||
|
IoEyeOutline,
|
||||||
|
IoEyeOffOutline,
|
||||||
|
IoSaveOutline,
|
||||||
|
IoReloadOutline,
|
||||||
|
IoDownloadOutline,
|
||||||
|
} from "react-icons/io5";
|
||||||
|
|
||||||
|
import type { Prisma, Vote } from "@prisma/client";
|
||||||
|
import { configureAbly, useChannel, usePresence } from "@ably-labs/react-hooks";
|
||||||
|
import type { PresenceItem } from "~/utils/types";
|
||||||
|
import { env } from "~/env.mjs";
|
||||||
|
import Loading from "~/components/Loading";
|
||||||
|
import { FaShieldAlt } from "react-icons/fa";
|
||||||
|
import { RiVipCrownFill } from "react-icons/ri";
|
||||||
|
import Link from "next/link";
|
||||||
|
import { downloadCSV } from "~/utils/helpers";
|
||||||
|
|
||||||
|
export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||||
|
const session = await getServerAuthSession(ctx);
|
||||||
|
|
||||||
|
// Redirect to home if not logged in
|
||||||
|
if (!session) {
|
||||||
|
return {
|
||||||
|
redirect: {
|
||||||
|
destination: "/",
|
||||||
|
permanent: false,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return session if logged in
|
||||||
|
return {
|
||||||
|
props: { session },
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
interface ExtendedVote extends Vote {
|
||||||
|
id: string;
|
||||||
|
userId: string;
|
||||||
|
roomId: string;
|
||||||
|
owner: {
|
||||||
|
image: string | null;
|
||||||
|
_count: Prisma.UserCountOutputType;
|
||||||
|
name: string | null;
|
||||||
|
email: string | null;
|
||||||
|
};
|
||||||
|
value: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Room: NextPage = () => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Head>
|
||||||
|
<title>Sprint Padawan</title>
|
||||||
|
<meta name="description" content="Plan. Sprint. Repeat." />
|
||||||
|
</Head>
|
||||||
|
<div className="flex flex-col items-center justify-center text-center gap-2">
|
||||||
|
<RoomBody />
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Room;
|
||||||
|
|
||||||
|
const RoomBody: React.FC = () => {
|
||||||
|
const { data: sessionData } = useSession();
|
||||||
|
const { query } = useRouter();
|
||||||
|
const roomId = z.string().parse(query.id);
|
||||||
|
|
||||||
|
const [storyNameText, setStoryNameText] = useState<string>("");
|
||||||
|
const [roomScale, setRoomScale] = useState<string>("");
|
||||||
|
|
||||||
|
const { data: roomFromDb, refetch: refetchRoomFromDb } =
|
||||||
|
api.room.get.useQuery({ id: roomId });
|
||||||
|
|
||||||
|
const setVoteInDb = api.vote.set.useMutation({});
|
||||||
|
const setRoomInDb = api.room.set.useMutation({});
|
||||||
|
|
||||||
|
configureAbly({
|
||||||
|
key: env.NEXT_PUBLIC_ABLY_PUBLIC_KEY,
|
||||||
|
clientId: sessionData?.user.id,
|
||||||
|
recover: (_, cb) => {
|
||||||
|
cb(true);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const [channel] = useChannel(
|
||||||
|
{
|
||||||
|
channelName: `${env.NEXT_PUBLIC_APP_ENV}-${roomId}`,
|
||||||
|
},
|
||||||
|
() => void refetchRoomFromDb()
|
||||||
|
);
|
||||||
|
|
||||||
|
const [presenceData] = usePresence<PresenceItem>(
|
||||||
|
`${env.NEXT_PUBLIC_APP_ENV}-${roomId}`,
|
||||||
|
{
|
||||||
|
name: sessionData?.user.name || "",
|
||||||
|
image: sessionData?.user.image || "",
|
||||||
|
client_id: sessionData?.user.id || "",
|
||||||
|
role: sessionData?.user.role || "USER",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Subscribe on mount and unsubscribe on unmount
|
||||||
|
useEffect(() => {
|
||||||
|
window.addEventListener("beforeunload", () => channel.presence.leave());
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("beforeunload", () =>
|
||||||
|
channel.presence.leave()
|
||||||
|
);
|
||||||
|
channel.presence.leave();
|
||||||
|
};
|
||||||
|
}, [channel.presence]);
|
||||||
|
|
||||||
|
// Init story name
|
||||||
|
useEffect(() => {
|
||||||
|
if (sessionData && roomFromDb) {
|
||||||
|
setStoryNameText(roomFromDb.storyName || "");
|
||||||
|
setRoomScale(roomFromDb.scale || "ERROR");
|
||||||
|
}
|
||||||
|
}, [roomFromDb, sessionData]);
|
||||||
|
|
||||||
|
// Helper functions
|
||||||
|
const getVoteForCurrentUser = () => {
|
||||||
|
if (roomFromDb && sessionData) {
|
||||||
|
return (
|
||||||
|
roomFromDb &&
|
||||||
|
roomFromDb.votes.find((vote) => vote.userId === sessionData.user.id)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const setVote = (value: string) => {
|
||||||
|
if (roomFromDb) {
|
||||||
|
setVoteInDb.mutate({
|
||||||
|
roomId: roomFromDb.id,
|
||||||
|
value: value,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const saveRoom = (visible: boolean, reset = false, log = false) => {
|
||||||
|
if (roomFromDb) {
|
||||||
|
setRoomInDb.mutate({
|
||||||
|
name: storyNameText,
|
||||||
|
roomId: roomFromDb.id,
|
||||||
|
scale: roomScale,
|
||||||
|
visible: visible,
|
||||||
|
reset: reset,
|
||||||
|
log: log,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const downloadLogs = () => {
|
||||||
|
if (roomFromDb) {
|
||||||
|
// const element = document.createElement("a");
|
||||||
|
const jsonObject = roomFromDb?.logs
|
||||||
|
.map((item) => {
|
||||||
|
return {
|
||||||
|
...item,
|
||||||
|
scale: item.scale,
|
||||||
|
votes: item.votes,
|
||||||
|
roomName: item.roomName,
|
||||||
|
storyName: item.storyName,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.concat({
|
||||||
|
id: "LATEST",
|
||||||
|
createdAt: new Date(),
|
||||||
|
userId: roomFromDb.owner.id,
|
||||||
|
roomId: roomFromDb.id,
|
||||||
|
scale: roomScale,
|
||||||
|
votes: roomFromDb.votes.map((vote) => {
|
||||||
|
return {
|
||||||
|
name: vote.owner.name,
|
||||||
|
value: vote.value,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
roomName: roomFromDb.roomName,
|
||||||
|
storyName: storyNameText,
|
||||||
|
});
|
||||||
|
|
||||||
|
downloadCSV(jsonObject, `sprint-padawan-room-${roomId}.csv`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const copyRoomURLHandler = () => {
|
||||||
|
navigator.clipboard
|
||||||
|
.writeText(window.location.href)
|
||||||
|
.then(() => {
|
||||||
|
console.log(`Copied Room Link to Clipboard!`);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
console.log(`Error Copying Room Link to Clipboard!`);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const voteString = (
|
||||||
|
visible: boolean,
|
||||||
|
votes: ExtendedVote[],
|
||||||
|
presenceItem: PresenceItem
|
||||||
|
) => {
|
||||||
|
const matchedVote = votes.find(
|
||||||
|
(vote) => vote.userId === presenceItem.client_id
|
||||||
|
);
|
||||||
|
|
||||||
|
if (visible) {
|
||||||
|
if (!!matchedVote) {
|
||||||
|
return <p>{matchedVote.value}</p>;
|
||||||
|
} else {
|
||||||
|
return <IoHourglassOutline className="text-xl mx-auto text-red-400" />;
|
||||||
|
}
|
||||||
|
} else if (!!matchedVote) {
|
||||||
|
return (
|
||||||
|
<IoCheckmarkCircleOutline className="text-xl mx-auto text-green-400" />
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
<IoHourglassOutline className="text-xl animate-spin mx-auto text-yellow-400" />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Room is loading
|
||||||
|
if (roomFromDb === undefined) {
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col items-center justify-center text-center">
|
||||||
|
<Loading />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
// Room has been loaded
|
||||||
|
} else if (roomFromDb) {
|
||||||
|
return (
|
||||||
|
<span className="text-center">
|
||||||
|
<div className="text-2xl">{roomFromDb.roomName}</div>
|
||||||
|
<div className="flex flex-row flex-wrap text-center justify-center items-center gap-1 text-md mx-auto">
|
||||||
|
<div>ID:</div>
|
||||||
|
<div>{roomFromDb.id}</div>
|
||||||
|
|
||||||
|
<button>
|
||||||
|
<IoCopyOutline
|
||||||
|
className="mx-1 hover:text-primary"
|
||||||
|
onClick={copyRoomURLHandler}
|
||||||
|
></IoCopyOutline>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{roomFromDb && (
|
||||||
|
<div className="card card-compact bg-neutral shadow-xl mx-auto m-4">
|
||||||
|
<div className="card-body">
|
||||||
|
<h2 className="card-title mx-auto">
|
||||||
|
Story: {roomFromDb.storyName}
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<ul className="p-0 mx-auto flex flex-row flex-wrap justify-center items-center text-ceter gap-4">
|
||||||
|
{presenceData &&
|
||||||
|
presenceData
|
||||||
|
.filter(
|
||||||
|
(value, index, self) =>
|
||||||
|
index ===
|
||||||
|
self.findIndex(
|
||||||
|
(presenceItem) =>
|
||||||
|
presenceItem.clientId === value.clientId
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.map((presenceItem) => {
|
||||||
|
return (
|
||||||
|
<li
|
||||||
|
key={presenceItem.clientId}
|
||||||
|
className="flex flex-row items-center justify-center gap-2"
|
||||||
|
>
|
||||||
|
<div className="w-10 rounded-full avatar mx-auto">
|
||||||
|
<Image
|
||||||
|
src={presenceItem.data.image}
|
||||||
|
alt={`${presenceItem.data.name}'s Profile Picture`}
|
||||||
|
height={32}
|
||||||
|
width={32}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p className="flex flex-row flex-wrap text-center justify-center items-center gap-1 text-md mx-auto">
|
||||||
|
{presenceItem.data.name}{" "}
|
||||||
|
{presenceItem.data.role === "ADMIN" && (
|
||||||
|
<div
|
||||||
|
className="tooltip tooltip-primary"
|
||||||
|
data-tip="Admin"
|
||||||
|
>
|
||||||
|
<FaShieldAlt className="inline-block text-primary" />
|
||||||
|
</div>
|
||||||
|
)}{" "}
|
||||||
|
{presenceItem.clientId === roomFromDb.userId && (
|
||||||
|
<div
|
||||||
|
className="tooltip tooltip-warning"
|
||||||
|
data-tip="Room Owner"
|
||||||
|
>
|
||||||
|
<RiVipCrownFill className="inline-block text-yellow-500" />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{" : "}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
{roomFromDb &&
|
||||||
|
voteString(
|
||||||
|
roomFromDb.visible,
|
||||||
|
roomFromDb.votes,
|
||||||
|
presenceItem.data
|
||||||
|
)}
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<div className="btn-group btn-group-vertical md:btn-group-horizontal mx-auto">
|
||||||
|
{roomFromDb.scale.split(",").map((scaleItem, index) => {
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
key={index}
|
||||||
|
className={
|
||||||
|
getVoteForCurrentUser()?.value === scaleItem
|
||||||
|
? "btn btn-active"
|
||||||
|
: "btn"
|
||||||
|
}
|
||||||
|
onClick={() => setVote(scaleItem)}
|
||||||
|
>
|
||||||
|
{scaleItem}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{sessionData &&
|
||||||
|
!!roomFromDb &&
|
||||||
|
roomFromDb.userId === sessionData.user.id && (
|
||||||
|
<>
|
||||||
|
<div className="card card-compact bg-neutral shadow-xl mx-auto m-4">
|
||||||
|
<div className="card-body flex flex-col flex-wrap">
|
||||||
|
<h2 className="card-title mx-auto">Room Settings</h2>
|
||||||
|
|
||||||
|
<label className="label mx-auto">
|
||||||
|
{"Vote Scale (Comma Separated):"}{" "}
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="Scale (Comma Separated)"
|
||||||
|
className="input input-bordered m-auto"
|
||||||
|
value={roomScale}
|
||||||
|
onChange={(event) => setRoomScale(event.target.value)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<label className="label mx-auto">{"Story Name:"} </label>
|
||||||
|
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="Story Name"
|
||||||
|
className="input input-bordered m-auto"
|
||||||
|
value={storyNameText}
|
||||||
|
onChange={(event) => setStoryNameText(event.target.value)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="flex flex-row flex-wrap text-center items-center justify-center gap-2">
|
||||||
|
<div>
|
||||||
|
<button
|
||||||
|
onClick={() => saveRoom(!roomFromDb.visible, false)}
|
||||||
|
className="btn btn-primary inline-flex"
|
||||||
|
>
|
||||||
|
{roomFromDb.visible ? (
|
||||||
|
<>
|
||||||
|
<IoEyeOffOutline className="text-xl mr-1" />
|
||||||
|
Hide
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<IoEyeOutline className="text-xl mr-1" />
|
||||||
|
Show
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<button
|
||||||
|
onClick={() =>
|
||||||
|
saveRoom(
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
roomFromDb.storyName === storyNameText ||
|
||||||
|
roomFromDb.votes.length === 0
|
||||||
|
? false
|
||||||
|
: true
|
||||||
|
)
|
||||||
|
}
|
||||||
|
className="btn btn-primary inline-flex"
|
||||||
|
disabled={
|
||||||
|
[...new Set(roomScale.split(","))].filter(
|
||||||
|
(item) => item !== ""
|
||||||
|
).length <= 1
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{roomFromDb.storyName === storyNameText ||
|
||||||
|
roomFromDb.votes.length === 0 ? (
|
||||||
|
<>
|
||||||
|
<IoReloadOutline className="text-white text-xl mr-1" />{" "}
|
||||||
|
Reset
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<IoSaveOutline className="text-xl mr-1" /> Save
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{(roomFromDb.logs.length > 0 ||
|
||||||
|
roomFromDb.votes.length > 0) && (
|
||||||
|
<div>
|
||||||
|
<button
|
||||||
|
onClick={() => downloadLogs()}
|
||||||
|
className="btn btn-primary inline-flex hover:animate-pulse"
|
||||||
|
>
|
||||||
|
<>
|
||||||
|
<IoDownloadOutline className="text-xl" />
|
||||||
|
</>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
// Room does not exist
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
<span className="prose text-center">
|
||||||
|
<h1>4️⃣0️⃣4️⃣</h1>
|
||||||
|
<h1>
|
||||||
|
Oops! This room does not appear to exist, or may have been deleted! 😢
|
||||||
|
</h1>
|
||||||
|
<Link
|
||||||
|
about="Back to home."
|
||||||
|
href="/"
|
||||||
|
className="btn btn-secondary normal-case text-xl"
|
||||||
|
>
|
||||||
|
Back to Home
|
||||||
|
</Link>
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
14
src/server/ably.ts
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
import Ably from "ably";
|
||||||
|
import type { EventType } from "../utils/types";
|
||||||
|
import { env } from "~/env.mjs";
|
||||||
|
|
||||||
|
const ably = new Ably.Realtime.Promise(env.ABLY_PRIVATE_KEY);
|
||||||
|
|
||||||
|
export const publishToChannel = async (
|
||||||
|
channel: string,
|
||||||
|
event: EventType,
|
||||||
|
message: string
|
||||||
|
) => {
|
||||||
|
const channelName = ably.channels.get(`${env.APP_ENV}-${channel}`);
|
||||||
|
await channelName.publish(event, message);
|
||||||
|
};
|
20
src/server/api/root.ts
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import { createTRPCRouter } from "~/server/api/trpc";
|
||||||
|
import { roomRouter } from "~/server/api/routers/room";
|
||||||
|
import { voteRouter } from "./routers/vote";
|
||||||
|
import { userRouter } from "./routers/user";
|
||||||
|
import { sessionRouter } from "./routers/session";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the primary router for your server.
|
||||||
|
*
|
||||||
|
* All routers added in /api/routers should be manually added here.
|
||||||
|
*/
|
||||||
|
export const appRouter = createTRPCRouter({
|
||||||
|
room: roomRouter,
|
||||||
|
vote: voteRouter,
|
||||||
|
user: userRouter,
|
||||||
|
session: sessionRouter,
|
||||||
|
});
|
||||||
|
|
||||||
|
// export type definition of API
|
||||||
|
export type AppRouter = typeof appRouter;
|
260
src/server/api/routers/room.ts
Normal file
|
@ -0,0 +1,260 @@
|
||||||
|
import { z } from "zod";
|
||||||
|
import { publishToChannel } from "~/server/ably";
|
||||||
|
|
||||||
|
import {
|
||||||
|
createTRPCRouter,
|
||||||
|
publicProcedure,
|
||||||
|
protectedProcedure,
|
||||||
|
} from "~/server/api/trpc";
|
||||||
|
|
||||||
|
import { writeToCache, fetchFromCache, deleteFromCache } from "~/server/redis";
|
||||||
|
|
||||||
|
export const roomRouter = createTRPCRouter({
|
||||||
|
// Create
|
||||||
|
create: publicProcedure
|
||||||
|
.input(
|
||||||
|
z.object({
|
||||||
|
name: z.string(),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.mutation(async ({ ctx, input }) => {
|
||||||
|
if (ctx.session) {
|
||||||
|
const room = await ctx.prisma.room.create({
|
||||||
|
data: {
|
||||||
|
userId: ctx.session.user.id,
|
||||||
|
roomName: input.name,
|
||||||
|
storyName: "First Story!",
|
||||||
|
scale: "0.5,1,2,3,5,8",
|
||||||
|
visible: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (room) {
|
||||||
|
await deleteFromCache(`kv_roomcount_admin`);
|
||||||
|
await deleteFromCache(`kv_roomlist_${ctx.session.user.id}`);
|
||||||
|
|
||||||
|
await publishToChannel(
|
||||||
|
`${ctx.session.user.id}`,
|
||||||
|
"ROOM_LIST_UPDATE",
|
||||||
|
"CREATE"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// happy path
|
||||||
|
return !!room;
|
||||||
|
}
|
||||||
|
|
||||||
|
// clinically depressed path
|
||||||
|
return false;
|
||||||
|
}),
|
||||||
|
|
||||||
|
// Get One
|
||||||
|
get: protectedProcedure
|
||||||
|
.input(z.object({ id: z.string() }))
|
||||||
|
.query(({ ctx, input }) => {
|
||||||
|
return ctx.prisma.room.findUnique({
|
||||||
|
where: {
|
||||||
|
id: input.id,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
userId: true,
|
||||||
|
logs: true,
|
||||||
|
roomName: true,
|
||||||
|
storyName: true,
|
||||||
|
visible: true,
|
||||||
|
scale: true,
|
||||||
|
votes: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
value: true,
|
||||||
|
roomId: true,
|
||||||
|
userId: true,
|
||||||
|
createdAt: true,
|
||||||
|
owner: {
|
||||||
|
select: {
|
||||||
|
_count: true,
|
||||||
|
name: true,
|
||||||
|
image: true,
|
||||||
|
email: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
owner: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
|
||||||
|
// Get All
|
||||||
|
getAll: protectedProcedure.query(async ({ ctx }) => {
|
||||||
|
const cachedResult = await fetchFromCache<
|
||||||
|
{
|
||||||
|
id: string;
|
||||||
|
createdAt: Date;
|
||||||
|
roomName: string;
|
||||||
|
}[]
|
||||||
|
>(`kv_roomlist_${ctx.session.user.id}`);
|
||||||
|
|
||||||
|
if (cachedResult) {
|
||||||
|
return cachedResult;
|
||||||
|
} else {
|
||||||
|
const roomList = await ctx.prisma.room.findMany({
|
||||||
|
where: {
|
||||||
|
userId: ctx.session.user.id,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
createdAt: true,
|
||||||
|
roomName: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await writeToCache(
|
||||||
|
`kv_roomlist_${ctx.session.user.id}`,
|
||||||
|
JSON.stringify(roomList),
|
||||||
|
69
|
||||||
|
);
|
||||||
|
|
||||||
|
return roomList;
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
countAll: protectedProcedure.query(async ({ ctx }) => {
|
||||||
|
const cachedResult = await fetchFromCache<number>(`kv_roomcount_admin`);
|
||||||
|
|
||||||
|
if (cachedResult) {
|
||||||
|
return cachedResult;
|
||||||
|
} else {
|
||||||
|
const roomsCount = await ctx.prisma.room.count();
|
||||||
|
|
||||||
|
await writeToCache(`kv_roomcount_admin`, roomsCount, 69);
|
||||||
|
|
||||||
|
return roomsCount;
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
// Update One
|
||||||
|
set: protectedProcedure
|
||||||
|
.input(
|
||||||
|
z.object({
|
||||||
|
name: z.string(),
|
||||||
|
visible: z.boolean(),
|
||||||
|
scale: z.string(),
|
||||||
|
roomId: z.string(),
|
||||||
|
reset: z.boolean(),
|
||||||
|
log: z.boolean(),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.mutation(async ({ ctx, input }) => {
|
||||||
|
if (input.reset) {
|
||||||
|
if (input.log) {
|
||||||
|
const oldRoom = await ctx.prisma.room.findUnique({
|
||||||
|
where: {
|
||||||
|
id: input.roomId,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
roomName: true,
|
||||||
|
storyName: true,
|
||||||
|
scale: true,
|
||||||
|
votes: {
|
||||||
|
select: {
|
||||||
|
owner: {
|
||||||
|
select: {
|
||||||
|
name: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
oldRoom &&
|
||||||
|
(await ctx.prisma.log.create({
|
||||||
|
data: {
|
||||||
|
userId: ctx.session.user.id,
|
||||||
|
roomId: input.roomId,
|
||||||
|
scale: oldRoom.scale,
|
||||||
|
votes: oldRoom.votes.map((vote) => {
|
||||||
|
return {
|
||||||
|
name: vote.owner.name,
|
||||||
|
value: vote.value,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
roomName: oldRoom.roomName,
|
||||||
|
storyName: oldRoom.storyName,
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
await ctx.prisma.vote.deleteMany({
|
||||||
|
where: {
|
||||||
|
roomId: input.roomId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const newRoom = await ctx.prisma.room.update({
|
||||||
|
where: {
|
||||||
|
id: input.roomId,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
storyName: input.name,
|
||||||
|
userId: ctx.session.user.id,
|
||||||
|
visible: input.visible,
|
||||||
|
scale: [...new Set(input.scale.split(","))]
|
||||||
|
.filter((item) => item !== "")
|
||||||
|
.toString(),
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
roomName: true,
|
||||||
|
storyName: true,
|
||||||
|
visible: true,
|
||||||
|
scale: true,
|
||||||
|
votes: {
|
||||||
|
select: {
|
||||||
|
owner: {
|
||||||
|
select: {
|
||||||
|
name: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (newRoom) {
|
||||||
|
await publishToChannel(`${newRoom.id}`, "ROOM_UPDATE", "UPDATE");
|
||||||
|
}
|
||||||
|
|
||||||
|
return !!newRoom;
|
||||||
|
}),
|
||||||
|
|
||||||
|
// Delete One
|
||||||
|
delete: protectedProcedure
|
||||||
|
.input(z.object({ id: z.string() }))
|
||||||
|
.mutation(async ({ ctx, input }) => {
|
||||||
|
const deletedRoom = await ctx.prisma.room.delete({
|
||||||
|
where: {
|
||||||
|
id: input.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (deletedRoom) {
|
||||||
|
await deleteFromCache(`kv_roomcount_admin`);
|
||||||
|
await deleteFromCache(`kv_votecount_admin`);
|
||||||
|
await deleteFromCache(`kv_roomlist_${ctx.session.user.id}`);
|
||||||
|
|
||||||
|
await publishToChannel(
|
||||||
|
`${ctx.session.user.id}`,
|
||||||
|
"ROOM_LIST_UPDATE",
|
||||||
|
"DELETE"
|
||||||
|
);
|
||||||
|
|
||||||
|
await publishToChannel(`${deletedRoom.id}`, "ROOM_UPDATE", "DELETE");
|
||||||
|
}
|
||||||
|
|
||||||
|
return !!deletedRoom;
|
||||||
|
}),
|
||||||
|
});
|
25
src/server/api/routers/session.ts
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
import { z } from "zod";
|
||||||
|
import { createTRPCRouter, protectedProcedure } from "~/server/api/trpc";
|
||||||
|
import { deleteFromCache } from "~/server/redis";
|
||||||
|
|
||||||
|
export const sessionRouter = createTRPCRouter({
|
||||||
|
deleteAll: protectedProcedure
|
||||||
|
.input(
|
||||||
|
z.object({
|
||||||
|
userId: z.string(),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.mutation(async ({ ctx, input }) => {
|
||||||
|
const sessions = await ctx.prisma.session.deleteMany({
|
||||||
|
where: {
|
||||||
|
userId: input.userId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!!sessions) {
|
||||||
|
await deleteFromCache(`kv_userlist_admin`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return !!sessions;
|
||||||
|
}),
|
||||||
|
});
|
162
src/server/api/routers/user.ts
Normal file
|
@ -0,0 +1,162 @@
|
||||||
|
import type { User } from "@prisma/client";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { createTRPCRouter, protectedProcedure } from "~/server/api/trpc";
|
||||||
|
import { sendMail } from "~/server/jmap";
|
||||||
|
import { fetchFromCache, writeToCache, deleteFromCache } from "~/server/redis";
|
||||||
|
import type { Role } from "~/utils/types";
|
||||||
|
|
||||||
|
export const userRouter = createTRPCRouter({
|
||||||
|
countAll: protectedProcedure.query(async ({ ctx }) => {
|
||||||
|
const cachedResult = await fetchFromCache<number>(`kv_usercount_admin`);
|
||||||
|
|
||||||
|
if (cachedResult) {
|
||||||
|
return cachedResult;
|
||||||
|
} else {
|
||||||
|
const usersCount = await ctx.prisma.user.count();
|
||||||
|
|
||||||
|
await writeToCache(`kv_usercount_admin`, usersCount, 69);
|
||||||
|
|
||||||
|
return usersCount;
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
getProviders: protectedProcedure.query(async ({ ctx }) => {
|
||||||
|
const providers = await ctx.prisma.user.findUnique({
|
||||||
|
where: {
|
||||||
|
id: ctx.session.user.id,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
accounts: {
|
||||||
|
select: {
|
||||||
|
provider: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return providers?.accounts.map((account) => {
|
||||||
|
return account.provider;
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
getAll: protectedProcedure.query(async ({ ctx }) => {
|
||||||
|
const cachedResult = await fetchFromCache<
|
||||||
|
{
|
||||||
|
sessions: {
|
||||||
|
id: string;
|
||||||
|
}[];
|
||||||
|
id: string;
|
||||||
|
createdAt: Date;
|
||||||
|
role: Role;
|
||||||
|
name: string | null;
|
||||||
|
email: string | null;
|
||||||
|
}[]
|
||||||
|
>(`kv_userlist_admin`);
|
||||||
|
|
||||||
|
if (cachedResult) {
|
||||||
|
return cachedResult.map((user) => {
|
||||||
|
return {
|
||||||
|
...user,
|
||||||
|
createdAt: new Date(user.createdAt),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const users = await ctx.prisma.user.findMany({
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
role: true,
|
||||||
|
createdAt: true,
|
||||||
|
email: true,
|
||||||
|
sessions: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await writeToCache(`kv_userlist_admin`, JSON.stringify(users), 69);
|
||||||
|
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
delete: protectedProcedure
|
||||||
|
.input(
|
||||||
|
z
|
||||||
|
.object({
|
||||||
|
userId: z.string(),
|
||||||
|
})
|
||||||
|
.optional()
|
||||||
|
)
|
||||||
|
.mutation(async ({ ctx, input }) => {
|
||||||
|
let user: User;
|
||||||
|
if (input?.userId && ctx.session.user.role === "ADMIN") {
|
||||||
|
user = await ctx.prisma.user.delete({
|
||||||
|
where: {
|
||||||
|
id: input.userId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
user = await ctx.prisma.user.delete({
|
||||||
|
where: {
|
||||||
|
id: ctx.session.user.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!!user && user.name && user.email) {
|
||||||
|
const subject = "Sorry to see you go... 😭";
|
||||||
|
|
||||||
|
const body =
|
||||||
|
`Hi ${user.name}! \n\n` +
|
||||||
|
"We're sorry to see you go! \n" +
|
||||||
|
"Your data has been deleted, including all room history, user data, votes, etc. \n" +
|
||||||
|
"-- \n" +
|
||||||
|
"Sprint Padawan Admin - Atridad \n";
|
||||||
|
|
||||||
|
await sendMail(subject, body, user.email);
|
||||||
|
await deleteFromCache(`kv_usercount_admin`);
|
||||||
|
await deleteFromCache(`kv_userlist_admin`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return !!user;
|
||||||
|
}),
|
||||||
|
save: protectedProcedure
|
||||||
|
.input(
|
||||||
|
z.object({
|
||||||
|
name: z.string(),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.mutation(async ({ ctx, input }) => {
|
||||||
|
const user = await ctx.prisma.user.update({
|
||||||
|
where: {
|
||||||
|
id: ctx.session.user.id,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
name: input.name,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return !!user;
|
||||||
|
}),
|
||||||
|
setRole: protectedProcedure
|
||||||
|
.input(
|
||||||
|
z.object({
|
||||||
|
userId: z.string(),
|
||||||
|
role: z.union([z.literal("ADMIN"), z.literal("USER")]),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.mutation(async ({ ctx, input }) => {
|
||||||
|
const user = await ctx.prisma.user.update({
|
||||||
|
where: {
|
||||||
|
id: input.userId,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
role: input.role,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await deleteFromCache(`kv_userlist_admin`);
|
||||||
|
|
||||||
|
return !!user;
|
||||||
|
}),
|
||||||
|
});
|
62
src/server/api/routers/vote.ts
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
import { z } from "zod";
|
||||||
|
import { publishToChannel } from "~/server/ably";
|
||||||
|
|
||||||
|
import { createTRPCRouter, protectedProcedure } from "~/server/api/trpc";
|
||||||
|
import { deleteFromCache, fetchFromCache, writeToCache } from "~/server/redis";
|
||||||
|
|
||||||
|
export const voteRouter = createTRPCRouter({
|
||||||
|
countAll: protectedProcedure.query(async ({ ctx }) => {
|
||||||
|
const cachedResult = await fetchFromCache<number>(`kv_votecount_admin`);
|
||||||
|
|
||||||
|
if (cachedResult) {
|
||||||
|
return cachedResult;
|
||||||
|
} else {
|
||||||
|
const votesCount = await ctx.prisma.vote.count();
|
||||||
|
|
||||||
|
await writeToCache(`kv_votecount_admin`, votesCount, 69);
|
||||||
|
|
||||||
|
return votesCount;
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
set: protectedProcedure
|
||||||
|
.input(z.object({ value: z.string(), roomId: z.string() }))
|
||||||
|
.mutation(async ({ ctx, input }) => {
|
||||||
|
const vote = await ctx.prisma.vote.upsert({
|
||||||
|
where: {
|
||||||
|
userId_roomId: {
|
||||||
|
roomId: input.roomId,
|
||||||
|
userId: ctx.session.user.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
create: {
|
||||||
|
value: input.value,
|
||||||
|
userId: ctx.session.user.id,
|
||||||
|
roomId: input.roomId,
|
||||||
|
},
|
||||||
|
update: {
|
||||||
|
value: input.value,
|
||||||
|
userId: ctx.session.user.id,
|
||||||
|
roomId: input.roomId,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
value: true,
|
||||||
|
userId: true,
|
||||||
|
roomId: true,
|
||||||
|
id: true,
|
||||||
|
owner: {
|
||||||
|
select: {
|
||||||
|
name: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (vote) {
|
||||||
|
await deleteFromCache(`kv_votecount_admin`);
|
||||||
|
|
||||||
|
await publishToChannel(`${vote.roomId}`, "VOTE_UPDATE", "UPDATE");
|
||||||
|
}
|
||||||
|
|
||||||
|
return !!vote;
|
||||||
|
}),
|
||||||
|
});
|
120
src/server/api/trpc.ts
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
/**
|
||||||
|
* YOU PROBABLY DON'T NEED TO EDIT THIS FILE, UNLESS:
|
||||||
|
* 1. You want to modify request context (see Part 1).
|
||||||
|
* 2. You want to create a new middleware or type of procedure (see Part 3).
|
||||||
|
*
|
||||||
|
* TL;DR - This is where all the tRPC server stuff is created and plugged in. The pieces you will
|
||||||
|
* need to use are documented accordingly near the end.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1. CONTEXT
|
||||||
|
*
|
||||||
|
* This section defines the "contexts" that are available in the backend API.
|
||||||
|
*
|
||||||
|
* These allow you to access things when processing a request, like the database, the session, etc.
|
||||||
|
*/
|
||||||
|
import { type CreateNextContextOptions } from "@trpc/server/adapters/next";
|
||||||
|
import { type Session } from "next-auth";
|
||||||
|
|
||||||
|
import { getServerAuthSession } from "~/server/auth";
|
||||||
|
import { prisma } from "~/server/db";
|
||||||
|
|
||||||
|
type CreateContextOptions = {
|
||||||
|
session: Session | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This helper generates the "internals" for a tRPC context. If you need to use it, you can export
|
||||||
|
* it from here.
|
||||||
|
*
|
||||||
|
* Examples of things you may need it for:
|
||||||
|
* - testing, so we don't have to mock Next.js' req/res
|
||||||
|
* - tRPC's `createSSGHelpers`, where we don't have req/res
|
||||||
|
*
|
||||||
|
* @see https://create.t3.gg/en/usage/trpc#-servertrpccontextts
|
||||||
|
*/
|
||||||
|
const createInnerTRPCContext = (opts: CreateContextOptions) => {
|
||||||
|
return {
|
||||||
|
session: opts.session,
|
||||||
|
prisma,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the actual context you will use in your router. It will be used to process every request
|
||||||
|
* that goes through your tRPC endpoint.
|
||||||
|
*
|
||||||
|
* @see https://trpc.io/docs/context
|
||||||
|
*/
|
||||||
|
export const createTRPCContext = async (opts: CreateNextContextOptions) => {
|
||||||
|
const { req, res } = opts;
|
||||||
|
|
||||||
|
// Get the session from the server using the getServerSession wrapper function
|
||||||
|
const session = await getServerAuthSession({ req, res });
|
||||||
|
|
||||||
|
return createInnerTRPCContext({
|
||||||
|
session,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 2. INITIALIZATION
|
||||||
|
*
|
||||||
|
* This is where the tRPC API is initialized, connecting the context and transformer.
|
||||||
|
*/
|
||||||
|
import { initTRPC, TRPCError } from "@trpc/server";
|
||||||
|
import superjson from "superjson";
|
||||||
|
|
||||||
|
const t = initTRPC.context<typeof createTRPCContext>().create({
|
||||||
|
transformer: superjson,
|
||||||
|
errorFormatter({ shape }) {
|
||||||
|
return shape;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 3. ROUTER & PROCEDURE (THE IMPORTANT BIT)
|
||||||
|
*
|
||||||
|
* These are the pieces you use to build your tRPC API. You should import these a lot in the
|
||||||
|
* "/src/server/api/routers" directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is how you create new routers and sub-routers in your tRPC API.
|
||||||
|
*
|
||||||
|
* @see https://trpc.io/docs/router
|
||||||
|
*/
|
||||||
|
export const createTRPCRouter = t.router;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public (unauthenticated) procedure
|
||||||
|
*
|
||||||
|
* This is the base piece you use to build new queries and mutations on your tRPC API. It does not
|
||||||
|
* guarantee that a user querying is authorized, but you can still access user session data if they
|
||||||
|
* are logged in.
|
||||||
|
*/
|
||||||
|
export const publicProcedure = t.procedure;
|
||||||
|
|
||||||
|
/** Reusable middleware that enforces users are logged in before running the procedure. */
|
||||||
|
const enforceUserIsAuthed = t.middleware(({ ctx, next }) => {
|
||||||
|
if (!ctx.session || !ctx.session.user) {
|
||||||
|
throw new TRPCError({ code: "UNAUTHORIZED" });
|
||||||
|
}
|
||||||
|
return next({
|
||||||
|
ctx: {
|
||||||
|
// infers the `session` as non-nullable
|
||||||
|
session: { ...ctx.session, user: ctx.session.user },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Protected (authenticated) procedure
|
||||||
|
*
|
||||||
|
* If you want a query or mutation to ONLY be accessible to logged in users, use this. It verifies
|
||||||
|
* the session is valid and guarantees `ctx.session.user` is not null.
|
||||||
|
*
|
||||||
|
* @see https://trpc.io/docs/procedures
|
||||||
|
*/
|
||||||
|
export const protectedProcedure = t.procedure.use(enforceUserIsAuthed);
|
106
src/server/auth.ts
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
import { type GetServerSidePropsContext } from "next";
|
||||||
|
import {
|
||||||
|
getServerSession,
|
||||||
|
type NextAuthOptions,
|
||||||
|
type DefaultSession,
|
||||||
|
} from "next-auth";
|
||||||
|
import GithubProvider from "next-auth/providers/github";
|
||||||
|
import GoogleProvider from "next-auth/providers/google";
|
||||||
|
import { PrismaAdapter } from "@next-auth/prisma-adapter";
|
||||||
|
import { env } from "~/env.mjs";
|
||||||
|
import { prisma } from "~/server/db";
|
||||||
|
import type { Role } from "~/utils/types";
|
||||||
|
import { sendMail } from "./jmap";
|
||||||
|
import { deleteFromCache } from "./redis";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Module augmentation for `next-auth` types. Allows us to add custom properties to the `session`
|
||||||
|
* object and keep type safety.
|
||||||
|
*
|
||||||
|
* @see https://next-auth.js.org/getting-started/typescript#module-augmentation
|
||||||
|
*/
|
||||||
|
declare module "next-auth" {
|
||||||
|
interface Session extends DefaultSession {
|
||||||
|
user: {
|
||||||
|
id: string;
|
||||||
|
role: Role;
|
||||||
|
} & DefaultSession["user"];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface User {
|
||||||
|
role: Role;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options for NextAuth.js used to configure adapters, providers, callbacks, etc.
|
||||||
|
*
|
||||||
|
* @see https://next-auth.js.org/configuration/options
|
||||||
|
*/
|
||||||
|
export const authOptions: NextAuthOptions = {
|
||||||
|
callbacks: {
|
||||||
|
session({ session, user }) {
|
||||||
|
if (session.user) {
|
||||||
|
session.user.id = user.id;
|
||||||
|
session.user.role = user.role;
|
||||||
|
}
|
||||||
|
return session;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
events: {
|
||||||
|
async createUser({ user }) {
|
||||||
|
if (user && user.name && user.email) {
|
||||||
|
const subject = "🎉 Welcome to Sprint Padawan! 🎉";
|
||||||
|
|
||||||
|
const body =
|
||||||
|
`Hi ${user.name}! \n\n` +
|
||||||
|
"Thank you for signing up for Sprint Padawan! \n" +
|
||||||
|
"If at any point you encounter issues, please let me know at support@sprintpadawan.dev. \n" +
|
||||||
|
"-- \n" +
|
||||||
|
"Sprint Padawan Admin - Atridad \n";
|
||||||
|
|
||||||
|
await sendMail(subject, body, user.email);
|
||||||
|
await deleteFromCache(`kv_userlist_admin`);
|
||||||
|
await deleteFromCache(`kv_usercount_admin`);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async signIn({}) {
|
||||||
|
await deleteFromCache(`kv_userlist_admin`);
|
||||||
|
},
|
||||||
|
async signOut({}) {
|
||||||
|
await deleteFromCache(`kv_userlist_admin`);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
adapter: PrismaAdapter(prisma),
|
||||||
|
providers: [
|
||||||
|
GithubProvider({
|
||||||
|
clientId: env.GITHUB_CLIENT_ID,
|
||||||
|
clientSecret: env.GITHUB_CLIENT_SECRET,
|
||||||
|
}),
|
||||||
|
GoogleProvider({
|
||||||
|
clientId: env.GOOGLE_CLIENT_ID,
|
||||||
|
clientSecret: env.GOOGLE_CLIENT_SECRET,
|
||||||
|
}),
|
||||||
|
/**
|
||||||
|
* ...add more providers here.
|
||||||
|
*
|
||||||
|
* Most other providers require a bit more work than the Discord provider. For example, the
|
||||||
|
* GitHub provider requires you to add the `refresh_token_expires_in` field to the Account
|
||||||
|
* model. Refer to the NextAuth.js docs for the provider you want to use. Example:
|
||||||
|
*
|
||||||
|
* @see https://next-auth.js.org/providers/github
|
||||||
|
*/
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper for `getServerSession` so that you don't need to import the `authOptions` in every file.
|
||||||
|
*
|
||||||
|
* @see https://next-auth.js.org/configuration/nextjs
|
||||||
|
*/
|
||||||
|
export const getServerAuthSession = (ctx: {
|
||||||
|
req: GetServerSidePropsContext["req"];
|
||||||
|
res: GetServerSidePropsContext["res"];
|
||||||
|
}) => {
|
||||||
|
return getServerSession(ctx.req, ctx.res, authOptions);
|
||||||
|
};
|
14
src/server/db.ts
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
import { PrismaClient } from "@prisma/client";
|
||||||
|
|
||||||
|
import { env } from "~/env.mjs";
|
||||||
|
|
||||||
|
const globalForPrisma = globalThis as unknown as { prisma: PrismaClient };
|
||||||
|
|
||||||
|
export const prisma =
|
||||||
|
globalForPrisma.prisma ||
|
||||||
|
new PrismaClient({
|
||||||
|
log:
|
||||||
|
env.NODE_ENV === "development" ? ["query", "error", "warn"] : ["error"],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
|
118
src/server/jmap.ts
Normal file
|
@ -0,0 +1,118 @@
|
||||||
|
/* eslint-disable */
|
||||||
|
import { env } from "~/env.mjs";
|
||||||
|
|
||||||
|
const hostname = env.JMAP_HOSTNAME || "api.fastmail.com";
|
||||||
|
const username = env.JMAP_USERNAME;
|
||||||
|
|
||||||
|
const authUrl = `https://${hostname}/.well-known/jmap`;
|
||||||
|
const headers = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: `Bearer ${env.JMAP_TOKEN}`,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getSession = async () => {
|
||||||
|
const response = await fetch(authUrl, {
|
||||||
|
method: "GET",
|
||||||
|
headers,
|
||||||
|
});
|
||||||
|
return response.json();
|
||||||
|
};
|
||||||
|
|
||||||
|
export const mailboxQuery = async (apiUrl: string, accountId: string) => {
|
||||||
|
const response = await fetch(apiUrl, {
|
||||||
|
method: "POST",
|
||||||
|
headers,
|
||||||
|
body: JSON.stringify({
|
||||||
|
using: ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
|
||||||
|
methodCalls: [
|
||||||
|
["Mailbox/query", { accountId, filter: { name: "Drafts" } }, "a"],
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
return await data["methodResponses"][0][1].ids[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const identityQuery = async (apiUrl: string, accountId: string) => {
|
||||||
|
const response = await fetch(apiUrl, {
|
||||||
|
method: "POST",
|
||||||
|
headers,
|
||||||
|
body: JSON.stringify({
|
||||||
|
using: [
|
||||||
|
"urn:ietf:params:jmap:core",
|
||||||
|
"urn:ietf:params:jmap:mail",
|
||||||
|
"urn:ietf:params:jmap:submission",
|
||||||
|
],
|
||||||
|
methodCalls: [["Identity/get", { accountId, ids: null }, "a"]],
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
return await data["methodResponses"][0][1].list.filter(
|
||||||
|
// eslint-disable-line
|
||||||
|
(identity: any) => identity.email === username
|
||||||
|
)[0].id;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const draftResponse = async (
|
||||||
|
apiUrl: string,
|
||||||
|
accountId: string,
|
||||||
|
draftId: string,
|
||||||
|
identityId: string,
|
||||||
|
subject: string,
|
||||||
|
messageBody: string,
|
||||||
|
sendTo: string
|
||||||
|
) => {
|
||||||
|
const draftObject = {
|
||||||
|
from: [{ email: username }],
|
||||||
|
to: [{ email: sendTo }],
|
||||||
|
subject,
|
||||||
|
keywords: { $draft: true },
|
||||||
|
mailboxIds: { [draftId]: true },
|
||||||
|
bodyValues: { body: { value: messageBody, charset: "utf-8" } },
|
||||||
|
textBody: [{ partId: "body", type: "text/plain" }],
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await fetch(apiUrl, {
|
||||||
|
method: "POST",
|
||||||
|
headers,
|
||||||
|
body: JSON.stringify({
|
||||||
|
using: [
|
||||||
|
"urn:ietf:params:jmap:core",
|
||||||
|
"urn:ietf:params:jmap:mail",
|
||||||
|
"urn:ietf:params:jmap:submission",
|
||||||
|
],
|
||||||
|
methodCalls: [
|
||||||
|
["Email/set", { accountId, create: { draft: draftObject } }, "a"],
|
||||||
|
[
|
||||||
|
"EmailSubmission/set",
|
||||||
|
{
|
||||||
|
accountId,
|
||||||
|
onSuccessDestroyEmail: ["#sendIt"],
|
||||||
|
create: { sendIt: { emailId: "#draft", identityId } },
|
||||||
|
},
|
||||||
|
"b",
|
||||||
|
],
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
console.log(JSON.stringify(data, null, 2));
|
||||||
|
};
|
||||||
|
|
||||||
|
export const sendMail = async (
|
||||||
|
subject: string,
|
||||||
|
body: string,
|
||||||
|
sendTo: string
|
||||||
|
) => {
|
||||||
|
const session = await getSession();
|
||||||
|
const apiUrl = session.apiUrl;
|
||||||
|
const accountId = session.primaryAccounts["urn:ietf:params:jmap:mail"];
|
||||||
|
|
||||||
|
const draftId = await mailboxQuery(apiUrl, accountId);
|
||||||
|
|
||||||
|
const identityId = await identityQuery(apiUrl, accountId);
|
||||||
|
draftResponse(apiUrl, accountId, draftId, identityId, subject, body, sendTo);
|
||||||
|
};
|
47
src/server/redis.ts
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
import { Redis } from "ioredis";
|
||||||
|
import { env } from "~/env.mjs";
|
||||||
|
|
||||||
|
export const redis = new Redis(env.REDIS_URL);
|
||||||
|
|
||||||
|
export const writeToCache = async (
|
||||||
|
key: string,
|
||||||
|
value: string | number | Buffer,
|
||||||
|
timeout?: number
|
||||||
|
): Promise<boolean> => {
|
||||||
|
try {
|
||||||
|
if (!!timeout) {
|
||||||
|
await redis.set(`${env.APP_ENV}_${key}`, value, "EX", timeout);
|
||||||
|
} else {
|
||||||
|
await redis.set(`${env.APP_ENV}_${key}`, value);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const fetchFromCache = async <T>(key: string): Promise<T | null> => {
|
||||||
|
try {
|
||||||
|
// This is bad please don't ever do this.
|
||||||
|
const cachedValue: Awaited<T> | null = JSON.parse(
|
||||||
|
(await redis.get(`${env.APP_ENV}_${key}`)) || ""
|
||||||
|
) as Awaited<T> | null;
|
||||||
|
if (!cachedValue && cachedValue !== 0) {
|
||||||
|
throw new Error("Cache Miss");
|
||||||
|
}
|
||||||
|
console.log(`CACHE HIT FOR KEY ${key}: `, cachedValue);
|
||||||
|
return cachedValue;
|
||||||
|
} catch {
|
||||||
|
console.log(`CACHE MISS FOR KEY ${key}!`);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const deleteFromCache = async (key: string) => {
|
||||||
|
try {
|
||||||
|
await redis.del(`${env.APP_ENV}_${key}`);
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
12
src/styles/globals.css
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
@tailwind base;
|
||||||
|
@tailwind components;
|
||||||
|
@tailwind utilities;
|
||||||
|
|
||||||
|
html,
|
||||||
|
container,
|
||||||
|
body #__next {
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
overflow-y: auto;
|
||||||
|
position: fixed;
|
||||||
|
}
|
68
src/utils/api.ts
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
/**
|
||||||
|
* This is the client-side entrypoint for your tRPC API. It is used to create the `api` object which
|
||||||
|
* contains the Next.js App-wrapper, as well as your type-safe React Query hooks.
|
||||||
|
*
|
||||||
|
* We also create a few inference helpers for input and output types.
|
||||||
|
*/
|
||||||
|
import { httpBatchLink, loggerLink } from "@trpc/client";
|
||||||
|
import { createTRPCNext } from "@trpc/next";
|
||||||
|
import { type inferRouterInputs, type inferRouterOutputs } from "@trpc/server";
|
||||||
|
import superjson from "superjson";
|
||||||
|
|
||||||
|
import { type AppRouter } from "~/server/api/root";
|
||||||
|
|
||||||
|
const getBaseUrl = () => {
|
||||||
|
if (typeof window !== "undefined") return ""; // browser should use relative url
|
||||||
|
if (process.env.VERCEL_URL) return `https://${process.env.VERCEL_URL}`; // SSR should use vercel url
|
||||||
|
return `http://localhost:${process.env.PORT ?? 3000}`; // dev SSR should use localhost
|
||||||
|
};
|
||||||
|
|
||||||
|
/** A set of type-safe react-query hooks for your tRPC API. */
|
||||||
|
export const api = createTRPCNext<AppRouter>({
|
||||||
|
config() {
|
||||||
|
return {
|
||||||
|
/**
|
||||||
|
* Transformer used for data de-serialization from the server.
|
||||||
|
*
|
||||||
|
* @see https://trpc.io/docs/data-transformers
|
||||||
|
*/
|
||||||
|
transformer: superjson,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Links used to determine request flow from client to server.
|
||||||
|
*
|
||||||
|
* @see https://trpc.io/docs/links
|
||||||
|
*/
|
||||||
|
links: [
|
||||||
|
loggerLink({
|
||||||
|
enabled: (opts) =>
|
||||||
|
process.env.NODE_ENV === "development" ||
|
||||||
|
(opts.direction === "down" && opts.result instanceof Error),
|
||||||
|
}),
|
||||||
|
httpBatchLink({
|
||||||
|
url: `${getBaseUrl()}/api/trpc`,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
};
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Whether tRPC should await queries when server rendering pages.
|
||||||
|
*
|
||||||
|
* @see https://trpc.io/docs/nextjs#ssr-boolean-default-false
|
||||||
|
*/
|
||||||
|
ssr: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inference helper for inputs.
|
||||||
|
*
|
||||||
|
* @example type HelloInput = RouterInputs['example']['hello']
|
||||||
|
*/
|
||||||
|
export type RouterInputs = inferRouterInputs<AppRouter>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inference helper for outputs.
|
||||||
|
*
|
||||||
|
* @example type HelloOutput = RouterOutputs['example']['hello']
|
||||||
|
*/
|
||||||
|
export type RouterOutputs = inferRouterOutputs<AppRouter>;
|
17
src/utils/helpers.ts
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import { parse } from "json2csv";
|
||||||
|
|
||||||
|
export function downloadCSV(
|
||||||
|
data: Record<string, unknown>[],
|
||||||
|
filename: string
|
||||||
|
): void {
|
||||||
|
const csv = parse(data);
|
||||||
|
const blob = new Blob([csv], { type: "text/csv;charset=utf-8;" });
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
const link = document.createElement("a");
|
||||||
|
link.setAttribute("href", url);
|
||||||
|
link.setAttribute("download", filename);
|
||||||
|
link.style.visibility = "hidden";
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
document.body.removeChild(link);
|
||||||
|
}
|
21
src/utils/types.ts
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
type BetterEnum<T> = T[keyof T];
|
||||||
|
|
||||||
|
const EventTypes = {
|
||||||
|
ROOM_LIST_UPDATE: "ROOM_LIST_UPDATE",
|
||||||
|
ROOM_UPDATE: "ROOM_UPDATE",
|
||||||
|
VOTE_UPDATE: "VOTE_UPDATE",
|
||||||
|
} as const;
|
||||||
|
export type EventType = BetterEnum<typeof EventTypes>;
|
||||||
|
|
||||||
|
const RoleValues = {
|
||||||
|
ADMIN: "ADMIN",
|
||||||
|
USER: "USER",
|
||||||
|
} as const;
|
||||||
|
export type Role = BetterEnum<typeof RoleValues>;
|
||||||
|
|
||||||
|
export interface PresenceItem {
|
||||||
|
name: string;
|
||||||
|
image: string;
|
||||||
|
client_id: string;
|
||||||
|
role: Role;
|
||||||
|
}
|
31
tailwind.config.js
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
module.exports = {
|
||||||
|
content: [
|
||||||
|
"./app/**/*.{js,ts,jsx,tsx}",
|
||||||
|
"./pages/**/*.{js,ts,jsx,tsx}",
|
||||||
|
"./components/**/*.{js,ts,jsx,tsx}",
|
||||||
|
|
||||||
|
// Or if using `src` directory:
|
||||||
|
"./src/**/*.{js,ts,jsx,tsx}",
|
||||||
|
],
|
||||||
|
theme: {
|
||||||
|
extend: {},
|
||||||
|
},
|
||||||
|
plugins: [require("@tailwindcss/typography"), require("daisyui")],
|
||||||
|
daisyui: {
|
||||||
|
themes: [
|
||||||
|
{
|
||||||
|
mytheme: {
|
||||||
|
primary: "#d946ef",
|
||||||
|
secondary: "#67e8f9",
|
||||||
|
accent: "#a855f7",
|
||||||
|
neutral: "#1D1820",
|
||||||
|
"base-100": "#1f2937",
|
||||||
|
info: "#60a5fa",
|
||||||
|
success: "#5BD7BC",
|
||||||
|
warning: "#E08610",
|
||||||
|
error: "#EE3F53",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
33
tsconfig.json
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "es2017",
|
||||||
|
"lib": ["dom", "dom.iterable", "esnext"],
|
||||||
|
"allowJs": true,
|
||||||
|
"checkJs": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"strict": true,
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"noEmit": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"module": "esnext",
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"isolatedModules": true,
|
||||||
|
"jsx": "preserve",
|
||||||
|
"incremental": true,
|
||||||
|
"noUncheckedIndexedAccess": true,
|
||||||
|
"baseUrl": ".",
|
||||||
|
"paths": {
|
||||||
|
"~/*": ["./src/*"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
".eslintrc.cjs",
|
||||||
|
"next-env.d.ts",
|
||||||
|
"**/*.ts",
|
||||||
|
"**/*.tsx",
|
||||||
|
"**/*.cjs",
|
||||||
|
"**/*.mjs"
|
||||||
|
],
|
||||||
|
"exclude": ["node_modules"]
|
||||||
|
}
|