Compare commits
No commits in common. "main" and "v0.3" have entirely different histories.
363 changed files with 16835 additions and 13068 deletions
|
|
@ -47,6 +47,9 @@ Dockerfile*
|
||||||
docker-compose*.yml
|
docker-compose*.yml
|
||||||
.dockerignore
|
.dockerignore
|
||||||
|
|
||||||
|
# Frontend old
|
||||||
|
frontend-old/
|
||||||
|
|
||||||
# Build artifacts
|
# Build artifacts
|
||||||
public/build/
|
public/build/
|
||||||
public/hot
|
public/hot
|
||||||
|
|
|
||||||
25
.env.testing
25
.env.testing
|
|
@ -1,25 +0,0 @@
|
||||||
APP_NAME=DishPlanner
|
|
||||||
APP_ENV=testing
|
|
||||||
APP_KEY=base64:2ADW3imsmRMo+UDw3GR6852wQu37/aNK1ooxEdaJIC0=
|
|
||||||
APP_DEBUG=true
|
|
||||||
APP_URL=http://localhost
|
|
||||||
|
|
||||||
APP_MAINTENANCE_DRIVER=file
|
|
||||||
|
|
||||||
BCRYPT_ROUNDS=4
|
|
||||||
|
|
||||||
LOG_CHANNEL=stack
|
|
||||||
LOG_STACK=single
|
|
||||||
|
|
||||||
DB_CONNECTION=sqlite
|
|
||||||
DB_DATABASE=:memory:
|
|
||||||
|
|
||||||
SESSION_DRIVER=array
|
|
||||||
|
|
||||||
BROADCAST_CONNECTION=log
|
|
||||||
FILESYSTEM_DISK=local
|
|
||||||
QUEUE_CONNECTION=sync
|
|
||||||
|
|
||||||
CACHE_STORE=array
|
|
||||||
|
|
||||||
MAIL_MAILER=array
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
name: Build and Push Docker Image
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [main]
|
|
||||||
tags: ['v*']
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: docker
|
|
||||||
container:
|
|
||||||
image: catthehacker/ubuntu:act-latest
|
|
||||||
steps:
|
|
||||||
- uses: https://data.forgejo.org/actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: https://data.forgejo.org/docker/setup-buildx-action@v3
|
|
||||||
|
|
||||||
- name: Login to Forgejo Registry
|
|
||||||
uses: https://data.forgejo.org/docker/login-action@v3
|
|
||||||
with:
|
|
||||||
registry: forge.lvl0.xyz
|
|
||||||
username: ${{ github.actor }}
|
|
||||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
||||||
|
|
||||||
- name: Determine tags
|
|
||||||
id: meta
|
|
||||||
run: |
|
|
||||||
if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
|
|
||||||
TAG="${{ github.ref_name }}"
|
|
||||||
echo "tags=forge.lvl0.xyz/lvl0/dishplanner:${TAG},forge.lvl0.xyz/lvl0/dishplanner:latest" >> $GITHUB_OUTPUT
|
|
||||||
else
|
|
||||||
echo "tags=forge.lvl0.xyz/lvl0/dishplanner:latest" >> $GITHUB_OUTPUT
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Build and push
|
|
||||||
uses: https://data.forgejo.org/docker/build-push-action@v5
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
file: Dockerfile
|
|
||||||
push: true
|
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
|
||||||
|
|
@ -1,68 +0,0 @@
|
||||||
name: CI
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: ['release/*']
|
|
||||||
pull_request:
|
|
||||||
branches: [main, 'release/*']
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
ci-image:
|
|
||||||
runs-on: docker
|
|
||||||
container:
|
|
||||||
image: catthehacker/ubuntu:act-latest
|
|
||||||
outputs:
|
|
||||||
tag: ${{ steps.meta.outputs.tag }}
|
|
||||||
steps:
|
|
||||||
- uses: https://data.forgejo.org/actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: https://data.forgejo.org/docker/setup-buildx-action@v3
|
|
||||||
|
|
||||||
- name: Login to Forgejo Registry
|
|
||||||
uses: https://data.forgejo.org/docker/login-action@v3
|
|
||||||
with:
|
|
||||||
registry: forge.lvl0.xyz
|
|
||||||
username: ${{ github.actor }}
|
|
||||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
||||||
|
|
||||||
- name: Compute image tag from lockfile
|
|
||||||
id: meta
|
|
||||||
run: |
|
|
||||||
HASH="$(sha256sum composer.lock | cut -c1-12)"
|
|
||||||
echo "tag=php8.3-${HASH}" >> "$GITHUB_OUTPUT"
|
|
||||||
|
|
||||||
- name: Build and push CI image
|
|
||||||
uses: https://data.forgejo.org/docker/build-push-action@v5
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
file: docker/build/Dockerfile.ci
|
|
||||||
push: true
|
|
||||||
tags: forge.lvl0.xyz/lvl0/dishplanner-ci:${{ steps.meta.outputs.tag }}
|
|
||||||
cache-from: type=registry,ref=forge.lvl0.xyz/lvl0/dishplanner-ci:buildcache
|
|
||||||
cache-to: type=registry,ref=forge.lvl0.xyz/lvl0/dishplanner-ci:buildcache,mode=max
|
|
||||||
|
|
||||||
ci:
|
|
||||||
needs: ci-image
|
|
||||||
runs-on: docker
|
|
||||||
container:
|
|
||||||
image: forge.lvl0.xyz/lvl0/dishplanner-ci:${{ needs.ci-image.outputs.tag }}
|
|
||||||
steps:
|
|
||||||
- uses: https://data.forgejo.org/actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Prepare environment
|
|
||||||
run: cp .env.testing .env
|
|
||||||
|
|
||||||
- name: Restore dependencies
|
|
||||||
run: |
|
|
||||||
cp -a /opt/deps/vendor ./vendor
|
|
||||||
composer install --no-interaction --no-progress
|
|
||||||
|
|
||||||
- name: Lint
|
|
||||||
run: vendor/bin/pint --test
|
|
||||||
|
|
||||||
- name: Static analysis
|
|
||||||
run: vendor/bin/phpstan analyse --memory-limit=1G
|
|
||||||
|
|
||||||
- name: Tests
|
|
||||||
run: php -d memory_limit=512M vendor/bin/phpunit
|
|
||||||
2
.gitattributes
vendored
2
.gitattributes
vendored
|
|
@ -6,4 +6,6 @@
|
||||||
*.md diff=markdown
|
*.md diff=markdown
|
||||||
*.php diff=php
|
*.php diff=php
|
||||||
|
|
||||||
|
/.github export-ignore
|
||||||
CHANGELOG.md export-ignore
|
CHANGELOG.md export-ignore
|
||||||
|
.styleci.yml export-ignore
|
||||||
|
|
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,3 +1,4 @@
|
||||||
|
/composer.lock
|
||||||
/.phpunit.cache
|
/.phpunit.cache
|
||||||
/coverage
|
/coverage
|
||||||
/node_modules
|
/node_modules
|
||||||
|
|
@ -23,4 +24,3 @@ yarn-error.log
|
||||||
/.vscode
|
/.vscode
|
||||||
/.zed
|
/.zed
|
||||||
/.vite
|
/.vite
|
||||||
/.codewhale
|
|
||||||
|
|
|
||||||
50
CHANGELOG.md
50
CHANGELOG.md
|
|
@ -1,50 +0,0 @@
|
||||||
# Changelog
|
|
||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
|
||||||
|
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
||||||
|
|
||||||
## [0.8.0] - 2026-08-17
|
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
- **Forgejo CI pipeline** (#45) — added a CI workflow that runs Laravel Pint code-style checks, PHPStan static analysis, and the PHPUnit suite against SQLite in memory.
|
|
||||||
- **Static analysis** — added PHPStan via `larastan/larastan` and `phpstan/phpstan-mockery`, with `phpstan.neon` and a baseline.
|
|
||||||
- **Code style** — added Laravel Pint configuration (`pint.json`).
|
|
||||||
- **CI and app image build workflows** (#46) — automated Docker image builds for the app and the CI base image, published to the Forgejo registry.
|
|
||||||
- **CI base image** (#46) — added `docker/build/Dockerfile.ci`, a Debian-based PHP 8.3 CLI image with the project's PHP dependencies pre-loaded so CI doesn't pay a per-run Composer install.
|
|
||||||
- **Contributing guide** (#47) — added `CONTRIBUTING.md`.
|
|
||||||
- **Nix shell completion** (#44) — finished the `nix-shell` development commands.
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
|
|
||||||
- **Dependencies** — `composer.lock` is now committed to the repository.
|
|
||||||
- **Code style** — reformatted the codebase with Laravel Pint.
|
|
||||||
- **Documentation** (#47) — professionalized the `README.md`.
|
|
||||||
- **Git hygiene** — dropped stale `.github`/StyleCI export rules from `.gitattributes`.
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
|
|
||||||
- **CI dependency installation** (#46, #50) — retried `composer install` on transient HTTP 429s, switched to `--prefer-source` and pre-loaded dependencies to avoid `codeload.github.com` rate limits, and added the missing `zip` extension to the CI image.
|
|
||||||
- **Test suite** (#50) — fixed feature tests failing on a missing Vite manifest by disabling Vite resolution during tests.
|
|
||||||
|
|
||||||
## [0.7.0] - 2026-08-17
|
|
||||||
|
|
||||||
### Removed
|
|
||||||
|
|
||||||
- **SaaS mode and subscription billing** (#37) — dropped Laravel Cashier, the `Billable` trait, `SubscriptionController`, the `RequireSubscription`/`RequireSaasMode` middleware, the `/subscription` and `/billing` routes, the billing/subscription views, the Cashier migrations, and the `stripe` service config.
|
|
||||||
- **Demo mode** (#38) — removed the demo middleware, demo-account seeding and purge commands, and demo-only UI.
|
|
||||||
- **`APP_MODE` plumbing** (#39) — removed `AppModeEnum`, the `app/helpers.php` global helper, and the `mode`/`demo_subscribe_url` config keys; the app now runs in a single self-hosted mode.
|
|
||||||
- **Dead code** (#40) — deleted `frontend-old/`, `bin/start-dev`, the unused `welcome.blade.php`, and the stale root-level `build_and_push.sh`/`update.sh` scripts.
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
|
|
||||||
- **License** (#41) — adopted AGPL-3.0 as the single project license (`LICENSE.md`, `composer.json`, `README.md`).
|
|
||||||
- **Registry and remote references** — repointed build, push, and update scripts and docs at `forge.lvl0.xyz/lvl0/dishplanner`, removing the stale LAN-registry and old `backend` naming.
|
|
||||||
- **Documentation** — updated the production and development instructions.
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
|
|
||||||
- Fixed health-check warnings in the development shell.
|
|
||||||
- Fixed schedule regeneration iterating every user instead of the planner's own users.
|
|
||||||
|
|
@ -1,97 +0,0 @@
|
||||||
# Contributing
|
|
||||||
|
|
||||||
Thanks for your interest in DishPlanner. It's a small self-hosted project —
|
|
||||||
issues and pull requests are both welcome.
|
|
||||||
|
|
||||||
## Reporting issues
|
|
||||||
|
|
||||||
Use [Issues](https://forge.lvl0.xyz/lvl0/dishplanner/issues).
|
|
||||||
|
|
||||||
For bugs, include what you expected, what happened, and enough detail to
|
|
||||||
reproduce it. Relevant log output helps; `dev-logs` follows the application log.
|
|
||||||
|
|
||||||
## Development setup
|
|
||||||
|
|
||||||
Requires PHP 8.2+ and a container runtime (Podman or Docker). The development
|
|
||||||
environment runs in containers defined by `docker-compose.yml`.
|
|
||||||
|
|
||||||
On NixOS, or anywhere with Nix installed:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
git clone https://forge.lvl0.xyz/lvl0/dishplanner.git
|
|
||||||
cd dishplanner
|
|
||||||
nix-shell
|
|
||||||
```
|
|
||||||
|
|
||||||
The shell prints the available commands on entry and can start the containers
|
|
||||||
for you:
|
|
||||||
|
|
||||||
| Command | Description |
|
|
||||||
|---------|-------------|
|
|
||||||
| `dev-up` | Start the development environment |
|
|
||||||
| `dev-down` | Stop the development environment |
|
|
||||||
| `dev-restart` | Restart the containers |
|
|
||||||
| `dev-rebuild` | Full rebuild (removes volumes) |
|
|
||||||
| `dev-rebuild-quick` | Quick rebuild (keeps volumes) |
|
|
||||||
| `dev-logs [service]` | Follow logs |
|
|
||||||
| `dev-logs-db` | Tail database logs |
|
|
||||||
| `dev-shell` | Enter the app container |
|
|
||||||
| `dev-artisan <cmd>` | Run an artisan command |
|
|
||||||
| `dev-test [path]` | Run the PHPUnit suite the CI way |
|
|
||||||
| `dev-fix-permissions` | Fix Docker-created file permissions |
|
|
||||||
|
|
||||||
Once running:
|
|
||||||
|
|
||||||
| Service | URL |
|
|
||||||
|---------|-----|
|
|
||||||
| App | http://localhost:8000 |
|
|
||||||
| Vite | http://localhost:5173 |
|
|
||||||
| Mailhog | http://localhost:8025 |
|
|
||||||
| MariaDB | localhost:3306 |
|
|
||||||
|
|
||||||
Without Nix, start the same containers directly from `docker-compose.yml`.
|
|
||||||
Contributions improving the setup instructions for other platforms are welcome.
|
|
||||||
|
|
||||||
## Before opening a pull request
|
|
||||||
|
|
||||||
Three checks run in CI, and all three must pass. Run them locally first, from
|
|
||||||
inside the app container or anywhere the project's dependencies are available:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
vendor/bin/pint --test # code style, Laravel preset
|
|
||||||
vendor/bin/phpstan analyse --memory-limit=1G # static analysis, level 7
|
|
||||||
php -d memory_limit=512M vendor/bin/phpunit # PHPUnit on SQLite in memory
|
|
||||||
```
|
|
||||||
|
|
||||||
Or run the test suite the CI way with `dev-test`.
|
|
||||||
|
|
||||||
Some conventions:
|
|
||||||
|
|
||||||
- **Static analysis.** PHPStan runs at level 7 with a baseline
|
|
||||||
(`phpstan-baseline.neon`) covering pre-existing findings. Don't add baseline
|
|
||||||
entries to silence errors in code you're writing — fix the cause instead. The
|
|
||||||
baseline is for cases where the analyzer or an upstream docblock is wrong,
|
|
||||||
not real bugs.
|
|
||||||
- **Tests.** New behaviour needs a test. Tests run against SQLite in memory and
|
|
||||||
must not reach for the network.
|
|
||||||
- **Dependencies.** `composer.lock` is committed. If you change dependencies,
|
|
||||||
commit the updated lockfile alongside `composer.json`.
|
|
||||||
|
|
||||||
## Commits
|
|
||||||
|
|
||||||
One commit does one thing. Keep each commit passing all three checks so history
|
|
||||||
stays bisectable. Separate renames from behaviour changes, and mechanical edits
|
|
||||||
from logic.
|
|
||||||
|
|
||||||
Commit messages are a single line, referencing the ticket they belong to:
|
|
||||||
|
|
||||||
```
|
|
||||||
45 - Add Forgejo CI workflow
|
|
||||||
```
|
|
||||||
|
|
||||||
No body, no trailers.
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
By contributing, you agree that your contributions are licensed under the
|
|
||||||
[GNU AGPL-3.0](LICENSE.md), the same license as the project.
|
|
||||||
|
|
@ -14,8 +14,7 @@ RUN install-php-extensions \
|
||||||
opcache \
|
opcache \
|
||||||
zip \
|
zip \
|
||||||
gd \
|
gd \
|
||||||
intl \
|
intl
|
||||||
bcmath
|
|
||||||
|
|
||||||
# Install Composer
|
# Install Composer
|
||||||
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
|
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ RUN install-php-extensions \
|
||||||
zip \
|
zip \
|
||||||
gd \
|
gd \
|
||||||
intl \
|
intl \
|
||||||
bcmath \
|
|
||||||
xdebug
|
xdebug
|
||||||
|
|
||||||
# Install Composer
|
# Install Composer
|
||||||
|
|
|
||||||
313
LICENSE.md
313
LICENSE.md
|
|
@ -1,94 +1,106 @@
|
||||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
GNU GENERAL PUBLIC LICENSE
|
||||||
Version 3, 19 November 2007
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
of this license document, but changing it is not allowed.
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
Preamble
|
Preamble
|
||||||
|
|
||||||
The GNU Affero General Public License is a free, copyleft license for
|
The GNU General Public License is a free, copyleft license for
|
||||||
software and other kinds of works, specifically designed to ensure
|
software and other kinds of works.
|
||||||
cooperation with the community in the case of network server software.
|
|
||||||
|
|
||||||
The licenses for most software and other practical works are designed
|
The licenses for most software and other practical works are designed
|
||||||
to take away your freedom to share and change the works. By contrast,
|
to take away your freedom to share and change the works. By contrast,
|
||||||
our General Public Licenses are intended to guarantee your freedom to
|
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
|
share and change all versions of a program--to make sure it remains free
|
||||||
software for all its users.
|
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
|
When we speak of free software, we are referring to freedom, not
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
have the freedom to distribute copies of free software (and charge for
|
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
|
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
|
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.
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
Developers that use our General Public Licenses protect your rights
|
To protect your rights, we need to prevent others from denying you
|
||||||
with two steps: (1) assert copyright on the software, and (2) offer
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
you this License which gives you legal permission to copy, distribute
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
and/or modify the software.
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
A secondary benefit of defending all users' freedom is that
|
For example, if you distribute copies of such a program, whether
|
||||||
improvements made in alternate versions of the program, if they
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
receive widespread use, become available for other developers to
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
incorporate. Many developers of free software are heartened and
|
or can get the source code. And you must show them these terms so they
|
||||||
encouraged by the resulting cooperation. However, in the case of
|
know their rights.
|
||||||
software used on network servers, this result may fail to come about.
|
|
||||||
The GNU General Public License permits making a modified version and
|
|
||||||
letting the public access it on a server without ever releasing its
|
|
||||||
source code to the public.
|
|
||||||
|
|
||||||
The GNU Affero General Public License is designed specifically to
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
ensure that, in such cases, the modified source code becomes available
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
to the community. It requires the operator of a network server to
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
provide the source code of the modified version running there to the
|
|
||||||
users of that server. Therefore, public use of a modified version, on
|
|
||||||
a publicly accessible server, gives the public access to the source
|
|
||||||
code of the modified version.
|
|
||||||
|
|
||||||
An older license, called the Affero General Public License and
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
published by Affero, was designed to accomplish similar goals. This is
|
that there is no warranty for this free software. For both users' and
|
||||||
a different license, not a version of the Affero GPL, but Affero has
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
released a new version of the Affero GPL which permits relicensing under
|
changed, so that their problems will not be attributed erroneously to
|
||||||
this license.
|
authors of previous versions.
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
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.
|
modification follow.
|
||||||
|
|
||||||
TERMS AND CONDITIONS
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
0. Definitions.
|
0. Definitions.
|
||||||
|
|
||||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
works, such as semiconductor masks.
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
"The Program" refers to any copyrightable work licensed under this
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
License. Each licensee is addressed as "you". "Licensees" and
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
"recipients" may be individuals or organizations.
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
To "modify" a work means to copy from or adapt all or part of the work
|
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
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
exact copy. The resulting work is called a "modified version" of the
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
earlier work or a work "based on" the earlier work.
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
A "covered work" means either the unmodified Program or a work based
|
A "covered work" means either the unmodified Program or a work based
|
||||||
on the Program.
|
on the Program.
|
||||||
|
|
||||||
To "propagate" a work means to do anything with it that, without
|
To "propagate" a work means to do anything with it that, without
|
||||||
permission, would make you directly or secondarily liable for
|
permission, would make you directly or secondarily liable for
|
||||||
infringement under applicable copyright law, except executing it on a
|
infringement under applicable copyright law, except executing it on a
|
||||||
computer or modifying a private copy. Propagation includes copying,
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
distribution (with or without modification), making available to the
|
distribution (with or without modification), making available to the
|
||||||
public, and in some countries other activities as well.
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
To "convey" a work means any kind of propagation that enables other
|
To "convey" a work means any kind of propagation that enables other
|
||||||
parties to make or receive copies. Mere interaction with a user through
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
a computer network, with no transfer of a copy, is not conveying.
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
An interactive user interface displays "Appropriate Legal Notices"
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
to the extent that it includes a convenient and prominently visible
|
to the extent that it includes a convenient and prominently visible
|
||||||
feature that (1) displays an appropriate copyright notice, and (2)
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
tells the user that there is no warranty for the work (except to the
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
|
@ -97,18 +109,18 @@
|
||||||
the interface presents a list of user commands or options, such as a
|
the interface presents a list of user commands or options, such as a
|
||||||
menu, a prominent item in the list meets this criterion.
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
1. Source Code.
|
1. Source Code.
|
||||||
|
|
||||||
The "source code" for a work means the preferred form of the work
|
The "source code" for a work means the preferred form of the work
|
||||||
for making modifications to it. "Object code" means any non-source
|
for making modifications to it. "Object code" means any non-source
|
||||||
form of a work.
|
form of a work.
|
||||||
|
|
||||||
A "Standard Interface" means an interface that either is an official
|
A "Standard Interface" means an interface that either is an official
|
||||||
standard defined by a recognized standards body, or, in the case of
|
standard defined by a recognized standards body, or, in the case of
|
||||||
interfaces specified for a particular programming language, one that
|
interfaces specified for a particular programming language, one that
|
||||||
is widely used among developers working in that language.
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
The "System Libraries" of an executable work include anything, other
|
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
|
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
|
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
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
|
@ -119,7 +131,7 @@
|
||||||
(if any) on which the executable work runs, or a compiler used to
|
(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.
|
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 "Corresponding Source" for a work in object code form means all
|
||||||
the source code needed to generate, install, and (for an executable
|
the source code needed to generate, install, and (for an executable
|
||||||
work) run the object code and to modify the work, including scripts to
|
work) run the object code and to modify the work, including scripts to
|
||||||
control those activities. However, it does not include the work's
|
control those activities. However, it does not include the work's
|
||||||
|
|
@ -132,16 +144,16 @@
|
||||||
such as by intimate data communication or control flow between those
|
such as by intimate data communication or control flow between those
|
||||||
subprograms and other parts of the work.
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
The Corresponding Source need not include anything that users
|
The Corresponding Source need not include anything that users
|
||||||
can regenerate automatically from other parts of the Corresponding
|
can regenerate automatically from other parts of the Corresponding
|
||||||
Source.
|
Source.
|
||||||
|
|
||||||
The Corresponding Source for a work in source code form is that
|
The Corresponding Source for a work in source code form is that
|
||||||
same work.
|
same work.
|
||||||
|
|
||||||
2. Basic Permissions.
|
2. Basic Permissions.
|
||||||
|
|
||||||
All rights granted under this License are granted for the term of
|
All rights granted under this License are granted for the term of
|
||||||
copyright on the Program, and are irrevocable provided the stated
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
conditions are met. This License explicitly affirms your unlimited
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
permission to run the unmodified Program. The output from running a
|
permission to run the unmodified Program. The output from running a
|
||||||
|
|
@ -149,7 +161,7 @@
|
||||||
content, constitutes a covered work. This License acknowledges your
|
content, constitutes a covered work. This License acknowledges your
|
||||||
rights of fair use or other equivalent, as provided by copyright law.
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
You may make, run and propagate covered works that you do not
|
You may make, run and propagate covered works that you do not
|
||||||
convey, without conditions so long as your license otherwise remains
|
convey, without conditions so long as your license otherwise remains
|
||||||
in force. You may convey covered works to others for the sole purpose
|
in force. You may convey covered works to others for the sole purpose
|
||||||
of having them make modifications exclusively for you, or provide you
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
|
@ -160,19 +172,19 @@
|
||||||
and control, on terms that prohibit them from making any copies of
|
and control, on terms that prohibit them from making any copies of
|
||||||
your copyrighted material outside their relationship with you.
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
Conveying under any other circumstances is permitted solely under
|
Conveying under any other circumstances is permitted solely under
|
||||||
the conditions stated below. Sublicensing is not allowed; section 10
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
makes it unnecessary.
|
makes it unnecessary.
|
||||||
|
|
||||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
No covered work shall be deemed part of an effective technological
|
No covered work shall be deemed part of an effective technological
|
||||||
measure under any applicable law fulfilling obligations under article
|
measure under any applicable law fulfilling obligations under article
|
||||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
similar laws prohibiting or restricting circumvention of such
|
similar laws prohibiting or restricting circumvention of such
|
||||||
measures.
|
measures.
|
||||||
|
|
||||||
When you convey a covered work, you waive any legal power to forbid
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
circumvention of technological measures to the extent such circumvention
|
circumvention of technological measures to the extent such circumvention
|
||||||
is effected by exercising rights under this License with respect to
|
is effected by exercising rights under this License with respect to
|
||||||
the covered work, and you disclaim any intention to limit operation or
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
|
@ -180,9 +192,9 @@
|
||||||
users, your or third parties' legal rights to forbid circumvention of
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
technological measures.
|
technological measures.
|
||||||
|
|
||||||
4. Conveying Verbatim Copies.
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
You may convey verbatim copies of the Program's source code as you
|
You may convey verbatim copies of the Program's source code as you
|
||||||
receive it, in any medium, provided that you conspicuously and
|
receive it, in any medium, provided that you conspicuously and
|
||||||
appropriately publish on each copy an appropriate copyright notice;
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
keep intact all notices stating that this License and any
|
keep intact all notices stating that this License and any
|
||||||
|
|
@ -190,12 +202,12 @@
|
||||||
keep intact all notices of the absence of any warranty; and give all
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
recipients a copy of this License along with the Program.
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
You may charge any price or no price for each copy that you convey,
|
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.
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
5. Conveying Modified Source Versions.
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
You may convey a work based on the Program, or the modifications to
|
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
|
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:
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
|
@ -220,7 +232,7 @@
|
||||||
interfaces that do not display Appropriate Legal Notices, your
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
work need not make them do so.
|
work need not make them do so.
|
||||||
|
|
||||||
A compilation of a covered work with other separate and independent
|
A compilation of a covered work with other separate and independent
|
||||||
works, which are not by their nature extensions of the covered work,
|
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,
|
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
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
|
@ -230,9 +242,9 @@
|
||||||
in an aggregate does not cause this License to apply to the other
|
in an aggregate does not cause this License to apply to the other
|
||||||
parts of the aggregate.
|
parts of the aggregate.
|
||||||
|
|
||||||
6. Conveying Non-Source Forms.
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
You may convey a covered work in object code form under the terms
|
You may convey a covered work in object code form under the terms
|
||||||
of sections 4 and 5, provided that you also convey the
|
of sections 4 and 5, provided that you also convey the
|
||||||
machine-readable Corresponding Source under the terms of this License,
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
in one of these ways:
|
in one of these ways:
|
||||||
|
|
@ -278,11 +290,11 @@
|
||||||
Source of the work are being offered to the general public at no
|
Source of the work are being offered to the general public at no
|
||||||
charge under subsection 6d.
|
charge under subsection 6d.
|
||||||
|
|
||||||
A separable portion of the object code, whose source code is excluded
|
A separable portion of the object code, whose source code is excluded
|
||||||
from the Corresponding Source as a System Library, need not be
|
from the Corresponding Source as a System Library, need not be
|
||||||
included in conveying the object code work.
|
included in conveying the object code work.
|
||||||
|
|
||||||
A "User Product" is either (1) a "consumer product", which means any
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
tangible personal property which is normally used for personal, family,
|
tangible personal property which is normally used for personal, family,
|
||||||
or household purposes, or (2) anything designed or sold for incorporation
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
into a dwelling. In determining whether a product is a consumer product,
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
|
@ -295,7 +307,7 @@
|
||||||
commercial, industrial or non-consumer uses, unless such uses represent
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
the only significant mode of use of the product.
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
"Installation Information" for a User Product means any methods,
|
"Installation Information" for a User Product means any methods,
|
||||||
procedures, authorization keys, or other information required to install
|
procedures, authorization keys, or other information required to install
|
||||||
and execute modified versions of a covered work in that User Product from
|
and execute modified versions of a covered work in that User Product from
|
||||||
a modified version of its Corresponding Source. The information must
|
a modified version of its Corresponding Source. The information must
|
||||||
|
|
@ -303,7 +315,7 @@
|
||||||
code is in no case prevented or interfered with solely because
|
code is in no case prevented or interfered with solely because
|
||||||
modification has been made.
|
modification has been made.
|
||||||
|
|
||||||
If you convey an object code work under this section in, or with, or
|
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
|
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
|
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
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
|
@ -314,7 +326,7 @@
|
||||||
modified object code on the User Product (for example, the work has
|
modified object code on the User Product (for example, the work has
|
||||||
been installed in ROM).
|
been installed in ROM).
|
||||||
|
|
||||||
The requirement to provide Installation Information does not include a
|
The requirement to provide Installation Information does not include a
|
||||||
requirement to continue to provide support service, warranty, or updates
|
requirement to continue to provide support service, warranty, or updates
|
||||||
for a work that has been modified or installed by the recipient, or for
|
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
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
|
@ -322,15 +334,15 @@
|
||||||
adversely affects the operation of the network or violates the rules and
|
adversely affects the operation of the network or violates the rules and
|
||||||
protocols for communication across the network.
|
protocols for communication across the network.
|
||||||
|
|
||||||
Corresponding Source conveyed, and Installation Information provided,
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
in accord with this section must be in a format that is publicly
|
in accord with this section must be in a format that is publicly
|
||||||
documented (and with an implementation available to the public in
|
documented (and with an implementation available to the public in
|
||||||
source code form), and must require no special password or key for
|
source code form), and must require no special password or key for
|
||||||
unpacking, reading or copying.
|
unpacking, reading or copying.
|
||||||
|
|
||||||
7. Additional Terms.
|
7. Additional Terms.
|
||||||
|
|
||||||
"Additional permissions" are terms that supplement the terms of this
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
License by making exceptions from one or more of its conditions.
|
License by making exceptions from one or more of its conditions.
|
||||||
Additional permissions that are applicable to the entire Program shall
|
Additional permissions that are applicable to the entire Program shall
|
||||||
be treated as though they were included in this License, to the extent
|
be treated as though they were included in this License, to the extent
|
||||||
|
|
@ -339,14 +351,14 @@
|
||||||
under those permissions, but the entire Program remains governed by
|
under those permissions, but the entire Program remains governed by
|
||||||
this License without regard to the additional permissions.
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
When you convey a copy of a covered work, you may at your option
|
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
|
remove any additional permissions from that copy, or from any part of
|
||||||
it. (Additional permissions may be written to require their own
|
it. (Additional permissions may be written to require their own
|
||||||
removal in certain cases when you modify the work.) You may place
|
removal in certain cases when you modify the work.) You may place
|
||||||
additional permissions on material, added by you to a covered work,
|
additional permissions on material, added by you to a covered work,
|
||||||
for which you have or can give appropriate copyright permission.
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, for material you
|
Notwithstanding any other provision of this License, for material you
|
||||||
add to a covered work, you may (if authorized by the copyright holders of
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
that material) supplement the terms of this License with terms:
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
|
@ -373,7 +385,7 @@
|
||||||
any liability that these contractual assumptions directly impose on
|
any liability that these contractual assumptions directly impose on
|
||||||
those licensors and authors.
|
those licensors and authors.
|
||||||
|
|
||||||
All other non-permissive additional terms are considered "further
|
All other non-permissive additional terms are considered "further
|
||||||
restrictions" within the meaning of section 10. If the Program as you
|
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
|
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
|
governed by this License along with a term that is a further
|
||||||
|
|
@ -383,46 +395,46 @@
|
||||||
of that license document, provided that the further restriction does
|
of that license document, provided that the further restriction does
|
||||||
not survive such relicensing or conveying.
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
If you add terms to a covered work in accord with this section, you
|
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
|
must place, in the relevant source files, a statement of the
|
||||||
additional terms that apply to those files, or a notice indicating
|
additional terms that apply to those files, or a notice indicating
|
||||||
where to find the applicable terms.
|
where to find the applicable terms.
|
||||||
|
|
||||||
Additional terms, permissive or non-permissive, may be stated in the
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
form of a separately written license, or stated as exceptions;
|
form of a separately written license, or stated as exceptions;
|
||||||
the above requirements apply either way.
|
the above requirements apply either way.
|
||||||
|
|
||||||
8. Termination.
|
8. Termination.
|
||||||
|
|
||||||
You may not propagate or modify a covered work except as expressly
|
You may not propagate or modify a covered work except as expressly
|
||||||
provided under this License. Any attempt otherwise to propagate or
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
modify it is void, and will automatically terminate your rights under
|
modify it is void, and will automatically terminate your rights under
|
||||||
this License (including any patent licenses granted under the third
|
this License (including any patent licenses granted under the third
|
||||||
paragraph of section 11).
|
paragraph of section 11).
|
||||||
|
|
||||||
However, if you cease all violation of this License, then your
|
However, if you cease all violation of this License, then your
|
||||||
license from a particular copyright holder is reinstated (a)
|
license from a particular copyright holder is reinstated (a)
|
||||||
provisionally, unless and until the copyright holder explicitly and
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
finally terminates your license, and (b) permanently, if the copyright
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
holder fails to notify you of the violation by some reasonable means
|
holder fails to notify you of the violation by some reasonable means
|
||||||
prior to 60 days after the cessation.
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
Moreover, your license from a particular copyright holder is
|
Moreover, your license from a particular copyright holder is
|
||||||
reinstated permanently if the copyright holder notifies you of the
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
violation by some reasonable means, this is the first time you have
|
violation by some reasonable means, this is the first time you have
|
||||||
received notice of violation of this License (for any work) from that
|
received notice of violation of this License (for any work) from that
|
||||||
copyright holder, and you cure the violation prior to 30 days after
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
your receipt of the notice.
|
your receipt of the notice.
|
||||||
|
|
||||||
Termination of your rights under this section does not terminate the
|
Termination of your rights under this section does not terminate the
|
||||||
licenses of parties who have received copies or rights from you under
|
licenses of parties who have received copies or rights from you under
|
||||||
this License. If your rights have been terminated and not permanently
|
this License. If your rights have been terminated and not permanently
|
||||||
reinstated, you do not qualify to receive new licenses for the same
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
material under section 10.
|
material under section 10.
|
||||||
|
|
||||||
9. Acceptance Not Required for Having Copies.
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
You are not required to accept this License in order to receive or
|
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
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
occurring solely as a consequence of using peer-to-peer transmission
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
to receive a copy likewise does not require acceptance. However,
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
|
@ -431,14 +443,14 @@
|
||||||
not accept this License. Therefore, by modifying or propagating a
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
covered work, you indicate your acceptance of this License to do so.
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
10. Automatic Licensing of Downstream Recipients.
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
Each time you convey a covered work, the recipient automatically
|
Each time you convey a covered work, the recipient automatically
|
||||||
receives a license from the original licensors, to run, modify and
|
receives a license from the original licensors, to run, modify and
|
||||||
propagate that work, subject to this License. You are not responsible
|
propagate that work, subject to this License. You are not responsible
|
||||||
for enforcing compliance by third parties with this License.
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
An "entity transaction" is a transaction transferring control of an
|
An "entity transaction" is a transaction transferring control of an
|
||||||
organization, or substantially all assets of one, or subdividing an
|
organization, or substantially all assets of one, or subdividing an
|
||||||
organization, or merging organizations. If propagation of a covered
|
organization, or merging organizations. If propagation of a covered
|
||||||
work results from an entity transaction, each party to that
|
work results from an entity transaction, each party to that
|
||||||
|
|
@ -448,7 +460,7 @@
|
||||||
Corresponding Source of the work from the predecessor in interest, if
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
the predecessor has it or can get it with reasonable efforts.
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
You may not impose any further restrictions on the exercise of the
|
You may not impose any further restrictions on the exercise of the
|
||||||
rights granted or affirmed under this License. For example, you may
|
rights granted or affirmed under this License. For example, you may
|
||||||
not impose a license fee, royalty, or other charge for exercise of
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
rights granted under this License, and you may not initiate litigation
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
|
@ -456,13 +468,13 @@
|
||||||
any patent claim is infringed by making, using, selling, offering for
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
sale, or importing the Program or any portion of it.
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
11. Patents.
|
11. Patents.
|
||||||
|
|
||||||
A "contributor" is a copyright holder who authorizes use under this
|
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
|
License of the Program or a work on which the Program is based. The
|
||||||
work thus licensed is called the contributor's "contributor version".
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
A contributor's "essential patent claims" are all patent claims
|
A contributor's "essential patent claims" are all patent claims
|
||||||
owned or controlled by the contributor, whether already acquired or
|
owned or controlled by the contributor, whether already acquired or
|
||||||
hereafter acquired, that would be infringed by some manner, permitted
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
by this License, of making, using, or selling its contributor version,
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
|
@ -472,19 +484,19 @@
|
||||||
patent sublicenses in a manner consistent with the requirements of
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
this License.
|
this License.
|
||||||
|
|
||||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
patent license under the contributor's essential patent claims, to
|
patent license under the contributor's essential patent claims, to
|
||||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
propagate the contents of its contributor version.
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
In the following three paragraphs, a "patent license" is any express
|
In the following three paragraphs, a "patent license" is any express
|
||||||
agreement or commitment, however denominated, not to enforce a patent
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
(such as an express permission to practice a patent or covenant not to
|
(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
|
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
|
party means to make such an agreement or commitment not to enforce a
|
||||||
patent against the party.
|
patent against the party.
|
||||||
|
|
||||||
If you convey a covered work, knowingly relying on a patent license,
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
and the Corresponding Source of the work is not available for anyone
|
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
|
to copy, free of charge and under the terms of this License, through a
|
||||||
publicly available network server or other readily accessible means,
|
publicly available network server or other readily accessible means,
|
||||||
|
|
@ -498,7 +510,7 @@
|
||||||
in a country, would infringe one or more identifiable patents in that
|
in a country, would infringe one or more identifiable patents in that
|
||||||
country that you have reason to believe are valid.
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
If, pursuant to or in connection with a single transaction or
|
If, pursuant to or in connection with a single transaction or
|
||||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
covered work, and grant a patent license to some of the parties
|
covered work, and grant a patent license to some of the parties
|
||||||
receiving the covered work authorizing them to use, propagate, modify
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
|
@ -506,7 +518,7 @@
|
||||||
you grant is automatically extended to all recipients of the covered
|
you grant is automatically extended to all recipients of the covered
|
||||||
work and works based on it.
|
work and works based on it.
|
||||||
|
|
||||||
A patent license is "discriminatory" if it does not include within
|
A patent license is "discriminatory" if it does not include within
|
||||||
the scope of its coverage, prohibits the exercise of, or is
|
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
|
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
|
specifically granted under this License. You may not convey a covered
|
||||||
|
|
@ -521,13 +533,13 @@
|
||||||
contain the covered work, unless you entered into that arrangement,
|
contain the covered work, unless you entered into that arrangement,
|
||||||
or that patent license was granted, prior to 28 March 2007.
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
Nothing in this License shall be construed as excluding or limiting
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
any implied license or other defenses to infringement that may
|
any implied license or other defenses to infringement that may
|
||||||
otherwise be available to you under applicable patent law.
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
12. No Surrender of Others' Freedom.
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
If conditions are imposed on you (whether by court order, agreement or
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
excuse you from the conditions of this License. If you cannot convey a
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
covered work so as to satisfy simultaneously your obligations under this
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
|
@ -537,56 +549,46 @@
|
||||||
the Program, the only way you could satisfy both those terms and this
|
the Program, the only way you could satisfy both those terms and this
|
||||||
License would be to refrain entirely from conveying the Program.
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, if you modify the
|
Notwithstanding any other provision of this License, you have
|
||||||
Program, your modified version must prominently offer all users
|
|
||||||
interacting with it remotely through a computer network (if your version
|
|
||||||
supports such interaction) an opportunity to receive the Corresponding
|
|
||||||
Source of your version by providing access to the Corresponding Source
|
|
||||||
from a network server at no charge, through some standard or customary
|
|
||||||
means of facilitating copying of software. This Corresponding Source
|
|
||||||
shall include the Corresponding Source for any work covered by version 3
|
|
||||||
of the GNU General Public License that is incorporated pursuant to the
|
|
||||||
following paragraph.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, you have
|
|
||||||
permission to link or combine any covered work with a work licensed
|
permission to link or combine any covered work with a work licensed
|
||||||
under version 3 of the GNU General Public License into a single
|
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
|
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,
|
License will continue to apply to the part which is the covered work,
|
||||||
but the work with which it is combined will remain governed by version
|
but the special requirements of the GNU Affero General Public License,
|
||||||
3 of the GNU General Public License.
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
combination as such.
|
||||||
|
|
||||||
14. Revised Versions of this License.
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
The Free Software Foundation may publish revised and/or new versions of
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
the GNU Affero General Public License from time to time. Such new versions
|
the GNU General Public License from time to time. Such new versions will
|
||||||
will be similar in spirit to the present version, but may differ in detail to
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
address new problems or concerns.
|
address new problems or concerns.
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the
|
Each version is given a distinguishing version number. If the
|
||||||
Program specifies that a certain numbered version of the GNU Affero General
|
Program specifies that a certain numbered version of the GNU General
|
||||||
Public License "or any later version" applies to it, you have the
|
Public License "or any later version" applies to it, you have the
|
||||||
option of following the terms and conditions either of that numbered
|
option of following the terms and conditions either of that numbered
|
||||||
version or of any later version published by the Free Software
|
version or of any later version published by the Free Software
|
||||||
Foundation. If the Program does not specify a version number of the
|
Foundation. If the Program does not specify a version number of the
|
||||||
GNU Affero General Public License, you may choose any version ever published
|
GNU General Public License, you may choose any version ever published
|
||||||
by the Free Software Foundation.
|
by the Free Software Foundation.
|
||||||
|
|
||||||
If the Program specifies that a proxy can decide which future
|
If the Program specifies that a proxy can decide which future
|
||||||
versions of the GNU Affero General Public License can be used, that proxy's
|
versions of the GNU General Public License can be used, that proxy's
|
||||||
public statement of acceptance of a version permanently authorizes you
|
public statement of acceptance of a version permanently authorizes you
|
||||||
to choose that version for the Program.
|
to choose that version for the Program.
|
||||||
|
|
||||||
Later license versions may give you additional or different
|
Later license versions may give you additional or different
|
||||||
permissions. However, no additional obligations are imposed on any
|
permissions. However, no additional obligations are imposed on any
|
||||||
author or copyright holder as a result of your choosing to follow a
|
author or copyright holder as a result of your choosing to follow a
|
||||||
later version.
|
later version.
|
||||||
|
|
||||||
15. Disclaimer of Warranty.
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
|
@ -595,9 +597,9 @@
|
||||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
16. Limitation of Liability.
|
16. Limitation of Liability.
|
||||||
|
|
||||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
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
|
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
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
|
@ -607,9 +609,9 @@
|
||||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
SUCH DAMAGES.
|
SUCH DAMAGES.
|
||||||
|
|
||||||
17. Interpretation of Sections 15 and 16.
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
If the disclaimer of warranty and limitation of liability provided
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
above cannot be given local legal effect according to their terms,
|
above cannot be given local legal effect according to their terms,
|
||||||
reviewing courts shall apply local law that most closely approximates
|
reviewing courts shall apply local law that most closely approximates
|
||||||
an absolute waiver of all civil liability in connection with the
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
|
@ -620,11 +622,11 @@
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
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
|
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.
|
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 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
|
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
|
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.
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
@ -633,29 +635,40 @@
|
||||||
Copyright (C) <year> <name of author>
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Affero General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU Affero General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
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.
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
If your software can interact with users remotely through a computer
|
If the program does terminal interaction, make it output a short
|
||||||
network, you should also make sure that it provides a way for users to
|
notice like this when it starts in an interactive mode:
|
||||||
get its source. For example, if your program is a web application, its
|
|
||||||
interface could display a "Source" link that leads users to an archive
|
|
||||||
of the code. There are many ways you could offer source, and different
|
|
||||||
solutions will be better for different programs; see section 13 for the
|
|
||||||
specific requirements.
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or school,
|
<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.
|
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 AGPL, see
|
For more information on this, and how to apply and follow the GNU GPL, see
|
||||||
<https://www.gnu.org/licenses/>.
|
<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>.
|
||||||
|
|
|
||||||
123
Makefile
Normal file
123
Makefile
Normal file
|
|
@ -0,0 +1,123 @@
|
||||||
|
# Dish Planner - Docker Commands
|
||||||
|
|
||||||
|
.PHONY: help
|
||||||
|
help: ## Show this help message
|
||||||
|
@echo "Dish Planner - Docker Management"
|
||||||
|
@echo ""
|
||||||
|
@echo "Usage: make [command]"
|
||||||
|
@echo ""
|
||||||
|
@echo "Available commands:"
|
||||||
|
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " %-20s %s\n", $$1, $$2}'
|
||||||
|
|
||||||
|
# Development Commands
|
||||||
|
.PHONY: dev
|
||||||
|
dev: ## Start development environment
|
||||||
|
docker compose up -d
|
||||||
|
@echo "Development server running at http://localhost:8000"
|
||||||
|
@echo "Mailhog available at http://localhost:8025"
|
||||||
|
|
||||||
|
.PHONY: dev-build
|
||||||
|
dev-build: ## Build and start development environment
|
||||||
|
docker compose build
|
||||||
|
docker compose up -d
|
||||||
|
|
||||||
|
.PHONY: dev-stop
|
||||||
|
dev-stop: ## Stop development environment
|
||||||
|
docker compose down
|
||||||
|
|
||||||
|
.PHONY: dev-clean
|
||||||
|
dev-clean: ## Stop and remove volumes (CAUTION: removes database)
|
||||||
|
docker compose down -v
|
||||||
|
|
||||||
|
.PHONY: logs
|
||||||
|
logs: ## Show application logs
|
||||||
|
docker compose logs -f app
|
||||||
|
|
||||||
|
.PHONY: logs-db
|
||||||
|
logs-db: ## Show database logs
|
||||||
|
docker compose logs -f db
|
||||||
|
|
||||||
|
# Production Commands
|
||||||
|
.PHONY: prod-build
|
||||||
|
prod-build: ## Build production image for Codeberg
|
||||||
|
./bin/build-push.sh
|
||||||
|
|
||||||
|
.PHONY: prod-build-tag
|
||||||
|
prod-build-tag: ## Build with specific tag (usage: make prod-build-tag TAG=v1.0.0)
|
||||||
|
./bin/build-push.sh $(TAG)
|
||||||
|
|
||||||
|
.PHONY: prod-login
|
||||||
|
prod-login: ## Login to Codeberg registry
|
||||||
|
podman login codeberg.org
|
||||||
|
|
||||||
|
# Laravel Commands
|
||||||
|
.PHONY: artisan
|
||||||
|
artisan: ## Run artisan command (usage: make artisan cmd="migrate")
|
||||||
|
docker compose exec app php artisan $(cmd)
|
||||||
|
|
||||||
|
.PHONY: composer
|
||||||
|
composer: ## Run composer command (usage: make composer cmd="require package")
|
||||||
|
docker compose exec app composer $(cmd)
|
||||||
|
|
||||||
|
.PHONY: npm
|
||||||
|
npm: ## Run npm command (usage: make npm cmd="install package")
|
||||||
|
docker compose exec app npm $(cmd)
|
||||||
|
|
||||||
|
.PHONY: migrate
|
||||||
|
migrate: ## Run database migrations
|
||||||
|
docker compose exec app php artisan migrate
|
||||||
|
|
||||||
|
.PHONY: seed
|
||||||
|
seed: ## Seed the database
|
||||||
|
docker compose exec app php artisan db:seed
|
||||||
|
|
||||||
|
.PHONY: fresh
|
||||||
|
fresh: ## Fresh migrate and seed
|
||||||
|
docker compose exec app php artisan migrate:fresh --seed
|
||||||
|
|
||||||
|
.PHONY: tinker
|
||||||
|
tinker: ## Start Laravel tinker
|
||||||
|
docker compose exec app php artisan tinker
|
||||||
|
|
||||||
|
.PHONY: test
|
||||||
|
test: ## Run tests
|
||||||
|
docker compose exec app php artisan test
|
||||||
|
|
||||||
|
# Utility Commands
|
||||||
|
.PHONY: shell
|
||||||
|
shell: ## Enter app container shell
|
||||||
|
docker compose exec app sh
|
||||||
|
|
||||||
|
.PHONY: db-shell
|
||||||
|
db-shell: ## Enter database shell
|
||||||
|
docker compose exec db mariadb -u dishplanner -pdishplanner dishplanner
|
||||||
|
|
||||||
|
.PHONY: clear
|
||||||
|
clear: ## Clear all Laravel caches
|
||||||
|
docker compose exec app php artisan cache:clear
|
||||||
|
docker compose exec app php artisan config:clear
|
||||||
|
docker compose exec app php artisan route:clear
|
||||||
|
docker compose exec app php artisan view:clear
|
||||||
|
|
||||||
|
.PHONY: optimize
|
||||||
|
optimize: ## Optimize Laravel for production
|
||||||
|
docker compose exec app php artisan config:cache
|
||||||
|
docker compose exec app php artisan route:cache
|
||||||
|
docker compose exec app php artisan view:cache
|
||||||
|
docker compose exec app php artisan livewire:discover
|
||||||
|
|
||||||
|
# Installation
|
||||||
|
.PHONY: install
|
||||||
|
install: ## First time setup
|
||||||
|
@echo "Setting up Dish Planner..."
|
||||||
|
@cp -n .env.example .env || true
|
||||||
|
@echo "Generating application key..."
|
||||||
|
@docker compose build
|
||||||
|
@docker compose up -d
|
||||||
|
@sleep 5
|
||||||
|
@docker compose exec app php artisan key:generate
|
||||||
|
@docker compose exec app php artisan migrate
|
||||||
|
@echo ""
|
||||||
|
@echo "✅ Installation complete!"
|
||||||
|
@echo "Access the app at: http://localhost:8000"
|
||||||
|
@echo "Create your first planner and user to get started."
|
||||||
351
README.md
351
README.md
|
|
@ -1,8 +1,5 @@
|
||||||
# 🍽️ Dish Planner
|
# 🍽️ Dish Planner
|
||||||
|
|
||||||
[](https://forge.lvl0.xyz/lvl0/dishplanner/actions)
|
|
||||||
[](LICENSE.md)
|
|
||||||
|
|
||||||
A Laravel-based meal planning application that helps households organize and schedule their dishes among multiple users. Built with Laravel, Livewire, and FrankenPHP for a modern, single-container deployment.
|
A Laravel-based meal planning application that helps households organize and schedule their dishes among multiple users. Built with Laravel, Livewire, and FrankenPHP for a modern, single-container deployment.
|
||||||
|
|
||||||
## ✨ Features
|
## ✨ Features
|
||||||
|
|
@ -14,125 +11,285 @@ ## ✨ Features
|
||||||
- **Dark theme UI** - Modern interface with purple/pink accents
|
- **Dark theme UI** - Modern interface with purple/pink accents
|
||||||
- **Single container deployment** - Simplified hosting with FrankenPHP
|
- **Single container deployment** - Simplified hosting with FrankenPHP
|
||||||
|
|
||||||
## 🚀 Self-hosting
|
## 🚀 Quick Start
|
||||||
|
|
||||||
The production image is available at `forge.lvl0.xyz/lvl0/dishplanner:latest`. See [CHANGELOG.md](CHANGELOG.md) before upgrading.
|
### Prerequisites
|
||||||
|
- Docker and Docker Compose
|
||||||
|
- Make (optional, for convenience commands)
|
||||||
|
|
||||||
### docker-compose.yml
|
### First Time Setup
|
||||||
|
|
||||||
```yaml
|
```bash
|
||||||
services:
|
# Clone the repository
|
||||||
app:
|
git clone https://github.com/yourusername/dish-planner.git
|
||||||
image: forge.lvl0.xyz/lvl0/dishplanner:latest
|
cd dish-planner
|
||||||
container_name: dishplanner_app
|
|
||||||
restart: always
|
|
||||||
ports:
|
|
||||||
- "8000:8000"
|
|
||||||
environment:
|
|
||||||
APP_KEY: "${APP_KEY}"
|
|
||||||
APP_URL: "${APP_URL}"
|
|
||||||
DB_DATABASE: "${DB_DATABASE}"
|
|
||||||
DB_USERNAME: "${DB_USERNAME}"
|
|
||||||
DB_PASSWORD: "${DB_PASSWORD}"
|
|
||||||
MAIL_HOST: "${MAIL_HOST:-}"
|
|
||||||
MAIL_PORT: "${MAIL_PORT:-587}"
|
|
||||||
MAIL_USERNAME: "${MAIL_USERNAME:-}"
|
|
||||||
MAIL_PASSWORD: "${MAIL_PASSWORD:-}"
|
|
||||||
MAIL_FROM_ADDRESS: "${MAIL_FROM_ADDRESS:-noreply@example.com}"
|
|
||||||
volumes:
|
|
||||||
- app_storage:/app/storage
|
|
||||||
depends_on:
|
|
||||||
- db
|
|
||||||
healthcheck:
|
|
||||||
test: ["CMD", "curl", "-f", "http://localhost:8000/up"]
|
|
||||||
interval: 30s
|
|
||||||
timeout: 10s
|
|
||||||
retries: 3
|
|
||||||
start_period: 40s
|
|
||||||
|
|
||||||
db:
|
# Quick install with Make
|
||||||
image: mariadb:11
|
make install
|
||||||
container_name: dishplanner_db
|
|
||||||
restart: always
|
|
||||||
environment:
|
|
||||||
MYSQL_DATABASE: "${DB_DATABASE}"
|
|
||||||
MYSQL_USER: "${DB_USERNAME}"
|
|
||||||
MYSQL_PASSWORD: "${DB_PASSWORD}"
|
|
||||||
MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"
|
|
||||||
volumes:
|
|
||||||
- db_data:/var/lib/mysql
|
|
||||||
|
|
||||||
volumes:
|
# Or manually:
|
||||||
db_data:
|
cp .env.example .env
|
||||||
app_storage:
|
docker compose build
|
||||||
|
docker compose up -d
|
||||||
|
docker compose exec app php artisan key:generate
|
||||||
|
docker compose exec app php artisan migrate
|
||||||
```
|
```
|
||||||
|
|
||||||
### Environment Variables
|
The application will be available at **http://localhost:8000**
|
||||||
|
|
||||||
| Variable | Required | Description |
|
|
||||||
|----------|----------|-------------|
|
|
||||||
| `APP_KEY` | Yes | Encryption key. Generate with: `echo "base64:$(openssl rand -base64 32)"` |
|
|
||||||
| `APP_URL` | Yes | Your domain (e.g., `https://meals.example.com`) |
|
|
||||||
| `DB_DATABASE` | Yes | Database name |
|
|
||||||
| `DB_USERNAME` | Yes | Database user |
|
|
||||||
| `DB_PASSWORD` | Yes | Database password |
|
|
||||||
| `DB_ROOT_PASSWORD` | Yes | MariaDB root password |
|
|
||||||
| `MAIL_HOST` | No | SMTP host for email notifications |
|
|
||||||
| `MAIL_PORT` | No | SMTP port (default: 587) |
|
|
||||||
| `MAIL_USERNAME` | No | SMTP username |
|
|
||||||
| `MAIL_PASSWORD` | No | SMTP password |
|
|
||||||
| `MAIL_FROM_ADDRESS` | No | From address for emails |
|
|
||||||
|
|
||||||
## 🔧 Development
|
## 🔧 Development
|
||||||
|
|
||||||
### NixOS / Nix
|
### Starting the Development Environment
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone https://forge.lvl0.xyz/lvl0/dishplanner.git
|
# Start all services
|
||||||
cd dishplanner
|
make dev
|
||||||
nix-shell
|
|
||||||
|
# Or with Docker Compose directly
|
||||||
|
docker compose up -d
|
||||||
```
|
```
|
||||||
|
|
||||||
The shell will display available commands and optionally start the containers for you.
|
**Available services:**
|
||||||
|
- **App**: http://localhost:8000 (Laravel + FrankenPHP)
|
||||||
|
- **Vite**: http://localhost:5173 (Asset hot-reload)
|
||||||
|
- **Mailhog**: http://localhost:8025 (Email testing)
|
||||||
|
- **Database**: localhost:3306 (MariaDB)
|
||||||
|
|
||||||
#### Available Commands
|
### Common Development Commands
|
||||||
|
|
||||||
| Command | Description |
|
```bash
|
||||||
|---------|-------------|
|
# View logs
|
||||||
| `dev-up` | Start development environment |
|
make logs # App logs
|
||||||
| `dev-down` | Stop development environment |
|
make logs-db # Database logs
|
||||||
| `dev-restart` | Restart containers |
|
|
||||||
| `dev-rebuild` | Full rebuild (removes volumes) |
|
|
||||||
| `dev-rebuild-quick` | Quick rebuild (keeps volumes) |
|
|
||||||
| `dev-logs [service]` | Follow logs |
|
|
||||||
| `dev-logs-db` | Tail database logs |
|
|
||||||
| `dev-shell` | Enter app container |
|
|
||||||
| `dev-artisan <cmd>` | Run artisan commands |
|
|
||||||
| `dev-test [path]` | Run the PHPUnit suite the CI way |
|
|
||||||
| `dev-fix-permissions` | Fix Docker-created file permissions |
|
|
||||||
|
|
||||||
#### Services
|
# Laravel commands
|
||||||
|
make artisan cmd="migrate" # Run artisan commands
|
||||||
|
make tinker # Start Laravel tinker
|
||||||
|
make test # Run tests
|
||||||
|
|
||||||
| Service | URL |
|
# Database
|
||||||
|---------|-----|
|
make migrate # Run migrations
|
||||||
| App | http://localhost:8000 |
|
make seed # Seed database
|
||||||
| Vite | http://localhost:5173 |
|
make fresh # Fresh migrate with seeds
|
||||||
| Mailhog | http://localhost:8025 |
|
|
||||||
| MariaDB | localhost:3306 |
|
|
||||||
|
|
||||||
### Other Platforms
|
# Testing
|
||||||
|
make test # Run tests
|
||||||
|
composer test:coverage-html # Run tests with coverage report (generates coverage/index.html)
|
||||||
|
|
||||||
Contributions welcome for development setup instructions on other platforms.
|
# Utilities
|
||||||
|
make shell # Enter app container
|
||||||
|
make db-shell # Enter database shell
|
||||||
|
make clear # Clear all caches
|
||||||
|
```
|
||||||
|
|
||||||
## 🤝 Contributing
|
### Project Structure
|
||||||
|
|
||||||
Issues and pull requests are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) for
|
```
|
||||||
the development setup, the checks that run in CI, and the commit conventions.
|
dish-planner/
|
||||||
|
├── app/
|
||||||
|
│ ├── Livewire/ # Livewire components
|
||||||
|
│ │ ├── Auth/ # Authentication
|
||||||
|
│ │ ├── Dishes/ # Dish management
|
||||||
|
│ │ ├── Schedule/ # Schedule calendar
|
||||||
|
│ │ └── Users/ # User management
|
||||||
|
│ └── Models/ # Eloquent models
|
||||||
|
├── resources/
|
||||||
|
│ └── views/
|
||||||
|
│ └── livewire/ # Livewire component views
|
||||||
|
├── docker-compose.yml # Development environment
|
||||||
|
├── docker-compose.prod.yml # Production environment
|
||||||
|
├── Dockerfile # Production image
|
||||||
|
├── Dockerfile.dev # Development image
|
||||||
|
└── Makefile # Convenience commands
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🚢 Production Deployment
|
||||||
|
|
||||||
|
### Building for Production
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Build production image
|
||||||
|
make prod-build
|
||||||
|
|
||||||
|
# Start production environment
|
||||||
|
make prod
|
||||||
|
|
||||||
|
# Or with Docker Compose
|
||||||
|
docker compose -f docker-compose.prod.yml build
|
||||||
|
docker compose -f docker-compose.prod.yml up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
### Production Environment Variables
|
||||||
|
|
||||||
|
Required environment variables for production:
|
||||||
|
|
||||||
|
```env
|
||||||
|
# Required - Generate APP_KEY (see instructions below)
|
||||||
|
APP_KEY=base64:your-generated-key-here
|
||||||
|
APP_URL=https://your-domain.com
|
||||||
|
|
||||||
|
# Database Configuration
|
||||||
|
DB_DATABASE=dishplanner
|
||||||
|
DB_USERNAME=dishplanner
|
||||||
|
DB_PASSWORD=strong-password-here
|
||||||
|
DB_ROOT_PASSWORD=strong-root-password
|
||||||
|
|
||||||
|
# Optional Email Configuration
|
||||||
|
MAIL_HOST=your-smtp-host
|
||||||
|
MAIL_PORT=587
|
||||||
|
MAIL_USERNAME=your-username
|
||||||
|
MAIL_PASSWORD=your-password
|
||||||
|
MAIL_FROM_ADDRESS=noreply@your-domain.com
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Generating APP_KEY
|
||||||
|
|
||||||
|
The APP_KEY is critical for encryption and must be kept consistent across deployments. Generate one using any of these methods:
|
||||||
|
|
||||||
|
**Option 1: Using OpenSSL (Linux/Mac/Windows with Git Bash)**
|
||||||
|
```bash
|
||||||
|
echo "base64:$(openssl rand -base64 32)"
|
||||||
|
```
|
||||||
|
|
||||||
|
**Option 2: Using Node.js (Cross-platform)**
|
||||||
|
```bash
|
||||||
|
node -e "console.log('base64:' + require('crypto').randomBytes(32).toString('base64'))"
|
||||||
|
```
|
||||||
|
|
||||||
|
**Option 3: Using Python (Cross-platform)**
|
||||||
|
```bash
|
||||||
|
python -c "import base64, os; print('base64:' + base64.b64encode(os.urandom(32)).decode())"
|
||||||
|
```
|
||||||
|
|
||||||
|
**Option 4: Online Generator**
|
||||||
|
Generate a random 32-character string at https://randomkeygen.com/ and prepend with `base64:`
|
||||||
|
|
||||||
|
⚠️ **Important**: Save this key securely! If lost, you won't be able to decrypt existing data.
|
||||||
|
|
||||||
|
### Deployment with DockGE
|
||||||
|
|
||||||
|
The production setup is optimized for DockGE deployment with just 2 containers:
|
||||||
|
|
||||||
|
1. **app** - Laravel application with FrankenPHP
|
||||||
|
2. **db** - MariaDB database
|
||||||
|
|
||||||
|
Simply import the `docker-compose.prod.yml` into DockGE and configure your environment variables.
|
||||||
|
|
||||||
|
## 🛠️ Technology Stack
|
||||||
|
|
||||||
|
- **Backend**: Laravel 12 with Livewire 3
|
||||||
|
- **Web Server**: FrankenPHP (PHP 8.3 + Caddy)
|
||||||
|
- **Database**: MariaDB 11
|
||||||
|
- **Frontend**: Blade + Livewire + Alpine.js
|
||||||
|
- **Styling**: TailwindCSS with custom dark theme
|
||||||
|
- **Assets**: Vite for bundling
|
||||||
|
|
||||||
|
## 📦 Docker Architecture
|
||||||
|
|
||||||
|
### Development (`docker-compose.yml`)
|
||||||
|
- **Hot reload** - Volume mounts for live code editing
|
||||||
|
- **Debug tools** - Xdebug configured for debugging
|
||||||
|
- **Email testing** - Mailhog for capturing emails
|
||||||
|
- **Asset watching** - Vite dev server for instant updates
|
||||||
|
|
||||||
|
### Production (`docker-compose.prod.yml`)
|
||||||
|
- **Optimized** - Multi-stage builds with caching
|
||||||
|
- **Secure** - No debug tools, proper permissions
|
||||||
|
- **Health checks** - Automatic container monitoring
|
||||||
|
- **Single container** - FrankenPHP serves everything
|
||||||
|
|
||||||
|
## 🔨 Make Commands Reference
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Development
|
||||||
|
make dev # Start development environment
|
||||||
|
make dev-build # Build and start development
|
||||||
|
make dev-stop # Stop development environment
|
||||||
|
make dev-clean # Stop and remove volumes (CAUTION)
|
||||||
|
|
||||||
|
# Production
|
||||||
|
make prod # Start production environment
|
||||||
|
make prod-build # Build production image
|
||||||
|
make prod-stop # Stop production environment
|
||||||
|
make prod-logs # Show production logs
|
||||||
|
|
||||||
|
# Laravel
|
||||||
|
make artisan cmd="..." # Run artisan command
|
||||||
|
make composer cmd="..." # Run composer command
|
||||||
|
make npm cmd="..." # Run npm command
|
||||||
|
make migrate # Run migrations
|
||||||
|
make seed # Seed database
|
||||||
|
make fresh # Fresh migrate and seed
|
||||||
|
make tinker # Start tinker session
|
||||||
|
make test # Run tests
|
||||||
|
|
||||||
|
# Utilities
|
||||||
|
make shell # Enter app container
|
||||||
|
make db-shell # Enter database shell
|
||||||
|
make logs # Show app logs
|
||||||
|
make logs-db # Show database logs
|
||||||
|
make clear # Clear all caches
|
||||||
|
make optimize # Optimize for production
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🐛 Troubleshooting
|
||||||
|
|
||||||
|
### Container won't start
|
||||||
|
```bash
|
||||||
|
# Check logs
|
||||||
|
docker compose logs app
|
||||||
|
|
||||||
|
# Rebuild containers
|
||||||
|
docker compose build --no-cache
|
||||||
|
docker compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
### Database connection issues
|
||||||
|
```bash
|
||||||
|
# Verify database is running
|
||||||
|
docker compose ps
|
||||||
|
|
||||||
|
# Check database logs
|
||||||
|
docker compose logs db
|
||||||
|
|
||||||
|
# Try manual connection
|
||||||
|
make db-shell
|
||||||
|
```
|
||||||
|
|
||||||
|
### Permission issues
|
||||||
|
```bash
|
||||||
|
# Fix storage permissions
|
||||||
|
docker compose exec app chmod -R 777 storage bootstrap/cache
|
||||||
|
```
|
||||||
|
|
||||||
|
### Clear all caches
|
||||||
|
```bash
|
||||||
|
make clear
|
||||||
|
# Or manually
|
||||||
|
docker compose exec app php artisan cache:clear
|
||||||
|
docker compose exec app php artisan config:clear
|
||||||
|
docker compose exec app php artisan route:clear
|
||||||
|
docker compose exec app php artisan view:clear
|
||||||
|
```
|
||||||
|
|
||||||
## 📄 License
|
## 📄 License
|
||||||
|
|
||||||
This project is open-source software licensed under the [AGPL-3.0 license](LICENSE.md).
|
This project is open-source software licensed under the [MIT license](LICENSE.md).
|
||||||
|
|
||||||
|
## 🤝 Contributing
|
||||||
|
|
||||||
|
Contributions are welcome! Please feel free to submit a Pull Request.
|
||||||
|
|
||||||
|
1. Fork the repository
|
||||||
|
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
|
||||||
|
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
|
||||||
|
4. Push to the branch (`git push origin feature/AmazingFeature`)
|
||||||
|
5. Open a Pull Request
|
||||||
|
|
||||||
## 📞 Support
|
## 📞 Support
|
||||||
|
|
||||||
For issues and questions, please use [Forgejo Issues](https://forge.lvl0.xyz/lvl0/dishplanner/issues).
|
For issues and questions, please use the [GitHub Issues](https://github.com/yourusername/dish-planner/issues) page.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Built with ❤️ using Laravel and Livewire
|
||||||
|
|
@ -17,11 +17,11 @@ public function execute(array $data): User
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
// Validate required fields first
|
// Validate required fields first
|
||||||
if (! isset($data['name']) || empty($data['name'])) {
|
if (!isset($data['name']) || empty($data['name'])) {
|
||||||
throw new InvalidArgumentException('Name is required');
|
throw new InvalidArgumentException('Name is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! isset($data['planner_id']) || empty($data['planner_id'])) {
|
if (!isset($data['planner_id']) || empty($data['planner_id'])) {
|
||||||
throw new InvalidArgumentException('Planner ID is required');
|
throw new InvalidArgumentException('Planner ID is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -38,7 +38,7 @@ public function execute(array $data): User
|
||||||
'planner_id' => $data['planner_id'],
|
'planner_id' => $data['planner_id'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (! $user) {
|
if (!$user) {
|
||||||
throw new Exception('User creation returned null');
|
throw new Exception('User creation returned null');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -50,7 +50,7 @@ public function execute(array $data): User
|
||||||
|
|
||||||
// Verify the user was actually created
|
// Verify the user was actually created
|
||||||
$createdUser = User::find($user->id);
|
$createdUser = User::find($user->id);
|
||||||
if (! $createdUser) {
|
if (!$createdUser) {
|
||||||
throw new Exception('User creation did not persist to database');
|
throw new Exception('User creation did not persist to database');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ public function execute(User $user, array $data): bool
|
||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (! $result) {
|
if (!$result) {
|
||||||
throw new \Exception('User update returned false');
|
throw new \Exception('User update returned false');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ public function handle(): int
|
||||||
|
|
||||||
if ($planners->isEmpty()) {
|
if ($planners->isEmpty()) {
|
||||||
$this->warn('No planners found. Aborting schedule generation.');
|
$this->warn('No planners found. Aborting schedule generation.');
|
||||||
|
|
||||||
return self::FAILURE;
|
return self::FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,8 @@ public function response(
|
||||||
?array $payload = null,
|
?array $payload = null,
|
||||||
array|string|null $errors = null,
|
array|string|null $errors = null,
|
||||||
int $statusCode = 200,
|
int $statusCode = 200,
|
||||||
): JsonResponse {
|
): JsonResponse
|
||||||
|
{
|
||||||
return response()->json(resolve(OutputService::class)->response($success, $payload, $errors), $statusCode);
|
return response()->json(resolve(OutputService::class)->response($success, $payload, $errors), $statusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ public function toArray(Request $request): array
|
||||||
'recurrences' => $this->recurrences->map(fn ($recurrence) => [
|
'recurrences' => $this->recurrences->map(fn ($recurrence) => [
|
||||||
'id' => $recurrence->id,
|
'id' => $recurrence->id,
|
||||||
'type' => $recurrence->recurrence_type,
|
'type' => $recurrence->recurrence_type,
|
||||||
'value' => $recurrence->getValue(),
|
'value' => $recurrence->getValue()
|
||||||
]),
|
]),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,18 +12,14 @@ class DishesList extends Component
|
||||||
use WithPagination;
|
use WithPagination;
|
||||||
|
|
||||||
public $showCreateModal = false;
|
public $showCreateModal = false;
|
||||||
|
|
||||||
public $showEditModal = false;
|
public $showEditModal = false;
|
||||||
|
|
||||||
public $showDeleteModal = false;
|
public $showDeleteModal = false;
|
||||||
|
|
||||||
public $editingDish = null;
|
public $editingDish = null;
|
||||||
|
|
||||||
public $deletingDish = null;
|
public $deletingDish = null;
|
||||||
|
|
||||||
// Form fields
|
// Form fields
|
||||||
public $name = '';
|
public $name = '';
|
||||||
|
|
||||||
public $selectedUsers = [];
|
public $selectedUsers = [];
|
||||||
|
|
||||||
protected $rules = [
|
protected $rules = [
|
||||||
|
|
@ -43,7 +39,7 @@ public function render()
|
||||||
|
|
||||||
return view('livewire.dishes.dishes-list', [
|
return view('livewire.dishes.dishes-list', [
|
||||||
'dishes' => $dishes,
|
'dishes' => $dishes,
|
||||||
'users' => $users,
|
'users' => $users
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,7 +60,7 @@ public function store()
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Attach selected users
|
// Attach selected users
|
||||||
if (! empty($this->selectedUsers)) {
|
if (!empty($this->selectedUsers)) {
|
||||||
$dish->users()->attach($this->selectedUsers);
|
$dish->users()->attach($this->selectedUsers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -130,7 +126,7 @@ public function toggleAllUsers(): void
|
||||||
if (count($this->selectedUsers) === $users->count()) {
|
if (count($this->selectedUsers) === $users->count()) {
|
||||||
$this->selectedUsers = [];
|
$this->selectedUsers = [];
|
||||||
} else {
|
} else {
|
||||||
$this->selectedUsers = $users->pluck('id')->map(fn ($id) => (string) $id)->toArray();
|
$this->selectedUsers = $users->pluck('id')->map(fn($id) => (string) $id)->toArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -19,39 +19,25 @@
|
||||||
class ScheduleCalendar extends Component
|
class ScheduleCalendar extends Component
|
||||||
{
|
{
|
||||||
public $currentMonth;
|
public $currentMonth;
|
||||||
|
|
||||||
public $currentYear;
|
public $currentYear;
|
||||||
|
|
||||||
public $calendarDays = [];
|
public $calendarDays = [];
|
||||||
|
|
||||||
public $showRegenerateModal = false;
|
public $showRegenerateModal = false;
|
||||||
|
|
||||||
public $regenerateDate = null;
|
public $regenerateDate = null;
|
||||||
|
|
||||||
public $regenerateUserId = null;
|
public $regenerateUserId = null;
|
||||||
|
|
||||||
// Edit dish modal
|
// Edit dish modal
|
||||||
public $showEditDishModal = false;
|
public $showEditDishModal = false;
|
||||||
|
|
||||||
public $editDate = null;
|
public $editDate = null;
|
||||||
|
|
||||||
public $editUserId = null;
|
public $editUserId = null;
|
||||||
|
|
||||||
public $selectedDishId = null;
|
public $selectedDishId = null;
|
||||||
|
|
||||||
public $availableDishes = [];
|
public $availableDishes = [];
|
||||||
|
|
||||||
// Add dish modal
|
// Add dish modal
|
||||||
public $showAddDishModal = false;
|
public $showAddDishModal = false;
|
||||||
|
|
||||||
public $addDate = null;
|
public $addDate = null;
|
||||||
|
|
||||||
public $addUserIds = [];
|
public $addUserIds = [];
|
||||||
|
|
||||||
public $addSelectedDishId = null;
|
public $addSelectedDishId = null;
|
||||||
|
|
||||||
public $addAvailableUsers = [];
|
public $addAvailableUsers = [];
|
||||||
|
|
||||||
public $addAvailableDishes = [];
|
public $addAvailableDishes = [];
|
||||||
|
|
||||||
public function mount(): void
|
public function mount(): void
|
||||||
|
|
@ -75,7 +61,7 @@ public function refreshCalendar(): void
|
||||||
|
|
||||||
public function loadCalendar(): void
|
public function loadCalendar(): void
|
||||||
{
|
{
|
||||||
$service = new ScheduleCalendarService;
|
$service = new ScheduleCalendarService();
|
||||||
$this->calendarDays = $service->getCalendarDays(
|
$this->calendarDays = $service->getCalendarDays(
|
||||||
auth()->user(),
|
auth()->user(),
|
||||||
$this->currentMonth,
|
$this->currentMonth,
|
||||||
|
|
@ -107,9 +93,8 @@ public function nextMonth(): void
|
||||||
|
|
||||||
public function regenerateForUserDate($date, $userId): void
|
public function regenerateForUserDate($date, $userId): void
|
||||||
{
|
{
|
||||||
if (! $this->authorizeUser($userId)) {
|
if (!$this->authorizeUser($userId)) {
|
||||||
session()->flash('error', 'Unauthorized action.');
|
session()->flash('error', 'Unauthorized action.');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -121,13 +106,12 @@ public function regenerateForUserDate($date, $userId): void
|
||||||
public function confirmRegenerate(): void
|
public function confirmRegenerate(): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (! $this->authorizeUser($this->regenerateUserId)) {
|
if (!$this->authorizeUser($this->regenerateUserId)) {
|
||||||
session()->flash('error', 'Unauthorized action.');
|
session()->flash('error', 'Unauthorized action.');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$action = new DeleteScheduledUserDishForDateAction;
|
$action = new DeleteScheduledUserDishForDateAction();
|
||||||
$action->execute(
|
$action->execute(
|
||||||
auth()->user(),
|
auth()->user(),
|
||||||
Carbon::parse($this->regenerateDate),
|
Carbon::parse($this->regenerateDate),
|
||||||
|
|
@ -147,13 +131,12 @@ public function confirmRegenerate(): void
|
||||||
public function skipDay($date, $userId): void
|
public function skipDay($date, $userId): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (! $this->authorizeUser($userId)) {
|
if (!$this->authorizeUser($userId)) {
|
||||||
session()->flash('error', 'Unauthorized action.');
|
session()->flash('error', 'Unauthorized action.');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$action = new SkipScheduledUserDishForDateAction;
|
$action = new SkipScheduledUserDishForDateAction();
|
||||||
$action->execute(
|
$action->execute(
|
||||||
auth()->user(),
|
auth()->user(),
|
||||||
Carbon::parse($date),
|
Carbon::parse($date),
|
||||||
|
|
@ -172,7 +155,6 @@ public function skipDay($date, $userId): void
|
||||||
private function authorizeUser(int $userId): bool
|
private function authorizeUser(int $userId): bool
|
||||||
{
|
{
|
||||||
$user = User::find($userId);
|
$user = User::find($userId);
|
||||||
|
|
||||||
return $user && $user->planner_id === auth()->id();
|
return $user && $user->planner_id === auth()->id();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -197,9 +179,8 @@ public function cancel(): void
|
||||||
public function removeDish($date, $userId): void
|
public function removeDish($date, $userId): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (! $this->authorizeUser($userId)) {
|
if (!$this->authorizeUser($userId)) {
|
||||||
session()->flash('error', 'Unauthorized action.');
|
session()->flash('error', 'Unauthorized action.');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -242,7 +223,7 @@ public function toggleAllUsers(): void
|
||||||
if (count($this->addUserIds) === count($this->addAvailableUsers)) {
|
if (count($this->addUserIds) === count($this->addAvailableUsers)) {
|
||||||
$this->addUserIds = [];
|
$this->addUserIds = [];
|
||||||
} else {
|
} else {
|
||||||
$this->addUserIds = $this->addAvailableUsers->pluck('id')->map(fn ($id) => (string) $id)->toArray();
|
$this->addUserIds = $this->addAvailableUsers->pluck('id')->map(fn($id) => (string) $id)->toArray();
|
||||||
}
|
}
|
||||||
$this->updateAvailableDishes();
|
$this->updateAvailableDishes();
|
||||||
}
|
}
|
||||||
|
|
@ -271,13 +252,11 @@ public function saveAddDish(): void
|
||||||
try {
|
try {
|
||||||
if (empty($this->addUserIds)) {
|
if (empty($this->addUserIds)) {
|
||||||
session()->flash('error', 'Please select at least one user.');
|
session()->flash('error', 'Please select at least one user.');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $this->addSelectedDishId) {
|
if (!$this->addSelectedDishId) {
|
||||||
session()->flash('error', 'Please select a dish.');
|
session()->flash('error', 'Please select a dish.');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -294,9 +273,8 @@ public function saveAddDish(): void
|
||||||
$skippedCount = 0;
|
$skippedCount = 0;
|
||||||
|
|
||||||
foreach ($this->addUserIds as $userId) {
|
foreach ($this->addUserIds as $userId) {
|
||||||
if (! $this->authorizeUser((int) $userId)) {
|
if (!$this->authorizeUser((int) $userId)) {
|
||||||
$skippedCount++;
|
$skippedCount++;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -307,7 +285,6 @@ public function saveAddDish(): void
|
||||||
|
|
||||||
if ($existing) {
|
if ($existing) {
|
||||||
$skippedCount++;
|
$skippedCount++;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -316,9 +293,8 @@ public function saveAddDish(): void
|
||||||
->where('dish_id', $this->addSelectedDishId)
|
->where('dish_id', $this->addSelectedDishId)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
if (! $userDish) {
|
if (!$userDish) {
|
||||||
$skippedCount++;
|
$skippedCount++;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -360,9 +336,8 @@ private function closeAddDishModal(): void
|
||||||
|
|
||||||
public function editDish($date, $userId): void
|
public function editDish($date, $userId): void
|
||||||
{
|
{
|
||||||
if (! $this->authorizeUser($userId)) {
|
if (!$this->authorizeUser($userId)) {
|
||||||
session()->flash('error', 'Unauthorized action.');
|
session()->flash('error', 'Unauthorized action.');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -395,15 +370,13 @@ public function editDish($date, $userId): void
|
||||||
public function saveDish(): void
|
public function saveDish(): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (! $this->authorizeUser($this->editUserId)) {
|
if (!$this->authorizeUser($this->editUserId)) {
|
||||||
session()->flash('error', 'Unauthorized action.');
|
session()->flash('error', 'Unauthorized action.');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $this->selectedDishId) {
|
if (!$this->selectedDishId) {
|
||||||
session()->flash('error', 'Please select a dish.');
|
session()->flash('error', 'Please select a dish.');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -421,9 +394,8 @@ public function saveDish(): void
|
||||||
->where('dish_id', $this->selectedDishId)
|
->where('dish_id', $this->selectedDishId)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
if (! $userDish) {
|
if (!$userDish) {
|
||||||
session()->flash('error', 'This dish is not assigned to this user.');
|
session()->flash('error', 'This dish is not assigned to this user.');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -455,8 +427,7 @@ public function saveDish(): void
|
||||||
|
|
||||||
public function getMonthNameProperty(): string
|
public function getMonthNameProperty(): string
|
||||||
{
|
{
|
||||||
$service = new ScheduleCalendarService;
|
$service = new ScheduleCalendarService();
|
||||||
|
|
||||||
return $service->getMonthName($this->currentMonth, $this->currentYear);
|
return $service->getMonthName($this->currentMonth, $this->currentYear);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,27 +7,19 @@
|
||||||
use DishPlanner\Schedule\Actions\ClearScheduleForMonthAction;
|
use DishPlanner\Schedule\Actions\ClearScheduleForMonthAction;
|
||||||
use DishPlanner\Schedule\Actions\GenerateScheduleForMonthAction;
|
use DishPlanner\Schedule\Actions\GenerateScheduleForMonthAction;
|
||||||
use DishPlanner\Schedule\Actions\RegenerateScheduleForDateForUsersAction;
|
use DishPlanner\Schedule\Actions\RegenerateScheduleForDateForUsersAction;
|
||||||
use Illuminate\Contracts\View\Factory;
|
|
||||||
use Illuminate\Contracts\View\View;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
|
||||||
class ScheduleGenerator extends Component
|
class ScheduleGenerator extends Component
|
||||||
{
|
{
|
||||||
private const YEARS_IN_PAST = 1;
|
private const YEARS_IN_PAST = 1;
|
||||||
|
|
||||||
private const YEARS_IN_FUTURE = 5;
|
private const YEARS_IN_FUTURE = 5;
|
||||||
|
|
||||||
public $selectedMonth;
|
public $selectedMonth;
|
||||||
|
|
||||||
public $selectedYear;
|
public $selectedYear;
|
||||||
|
|
||||||
public $selectedUsers = [];
|
public $selectedUsers = [];
|
||||||
|
|
||||||
public $clearExisting = true;
|
public $clearExisting = true;
|
||||||
|
|
||||||
public $showAdvancedOptions = false;
|
public $showAdvancedOptions = false;
|
||||||
|
|
||||||
public $isGenerating = false;
|
public $isGenerating = false;
|
||||||
|
|
||||||
public function mount(): void
|
public function mount(): void
|
||||||
|
|
@ -40,7 +32,7 @@ public function mount(): void
|
||||||
->toArray();
|
->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render(): Factory|View
|
public function render(): \Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
$users = User::where('planner_id', auth()->id())
|
$users = User::where('planner_id', auth()->id())
|
||||||
->orderBy('name')
|
->orderBy('name')
|
||||||
|
|
@ -51,7 +43,7 @@ public function render(): Factory|View
|
||||||
return view('livewire.schedule.schedule-generator', [
|
return view('livewire.schedule.schedule-generator', [
|
||||||
'users' => $users,
|
'users' => $users,
|
||||||
'months' => $this->getMonthNames(),
|
'months' => $this->getMonthNames(),
|
||||||
'years' => $years,
|
'years' => $years
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -60,13 +52,13 @@ public function generate(): void
|
||||||
$this->validate([
|
$this->validate([
|
||||||
'selectedUsers' => 'required|array|min:1',
|
'selectedUsers' => 'required|array|min:1',
|
||||||
'selectedMonth' => 'required|integer|min:1|max:12',
|
'selectedMonth' => 'required|integer|min:1|max:12',
|
||||||
'selectedYear' => 'required|integer|min:'.(now()->year - self::YEARS_IN_PAST).'|max:'.(now()->year + self::YEARS_IN_FUTURE),
|
'selectedYear' => 'required|integer|min:' . (now()->year - self::YEARS_IN_PAST) . '|max:' . (now()->year + self::YEARS_IN_FUTURE),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->isGenerating = true;
|
$this->isGenerating = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$action = new GenerateScheduleForMonthAction;
|
$action = new GenerateScheduleForMonthAction();
|
||||||
$action->execute(
|
$action->execute(
|
||||||
auth()->user(),
|
auth()->user(),
|
||||||
$this->selectedMonth,
|
$this->selectedMonth,
|
||||||
|
|
@ -78,8 +70,8 @@ public function generate(): void
|
||||||
$this->isGenerating = false;
|
$this->isGenerating = false;
|
||||||
$this->dispatch('schedule-generated');
|
$this->dispatch('schedule-generated');
|
||||||
|
|
||||||
session()->flash('success', 'Schedule generated successfully for '.
|
session()->flash('success', 'Schedule generated successfully for ' .
|
||||||
$this->getSelectedMonthName().' '.$this->selectedYear);
|
$this->getSelectedMonthName() . ' ' . $this->selectedYear);
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->isGenerating = false;
|
$this->isGenerating = false;
|
||||||
|
|
@ -91,7 +83,7 @@ public function generate(): void
|
||||||
public function regenerateForDate($date): void
|
public function regenerateForDate($date): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$action = new RegenerateScheduleForDateForUsersAction;
|
$action = new RegenerateScheduleForDateForUsersAction();
|
||||||
$action->execute(
|
$action->execute(
|
||||||
auth()->user(),
|
auth()->user(),
|
||||||
Carbon::parse($date),
|
Carbon::parse($date),
|
||||||
|
|
@ -99,7 +91,7 @@ public function regenerateForDate($date): void
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->dispatch('schedule-generated');
|
$this->dispatch('schedule-generated');
|
||||||
session()->flash('success', 'Schedule regenerated for '.Carbon::parse($date)->format('M d, Y'));
|
session()->flash('success', 'Schedule regenerated for ' . Carbon::parse($date)->format('M d, Y'));
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Log::error('Schedule regeneration failed', ['exception' => $e, 'date' => $date]);
|
Log::error('Schedule regeneration failed', ['exception' => $e, 'date' => $date]);
|
||||||
|
|
@ -110,7 +102,7 @@ public function regenerateForDate($date): void
|
||||||
public function clearMonth(): void
|
public function clearMonth(): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$action = new ClearScheduleForMonthAction;
|
$action = new ClearScheduleForMonthAction();
|
||||||
$action->execute(
|
$action->execute(
|
||||||
auth()->user(),
|
auth()->user(),
|
||||||
$this->selectedMonth,
|
$this->selectedMonth,
|
||||||
|
|
@ -119,8 +111,8 @@ public function clearMonth(): void
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->dispatch('schedule-generated');
|
$this->dispatch('schedule-generated');
|
||||||
session()->flash('success', 'Schedule cleared for '.
|
session()->flash('success', 'Schedule cleared for ' .
|
||||||
$this->getSelectedMonthName().' '.$this->selectedYear);
|
$this->getSelectedMonthName() . ' ' . $this->selectedYear);
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Log::error('Clear month failed', ['exception' => $e]);
|
Log::error('Clear month failed', ['exception' => $e]);
|
||||||
|
|
@ -130,7 +122,7 @@ public function clearMonth(): void
|
||||||
|
|
||||||
public function toggleAdvancedOptions()
|
public function toggleAdvancedOptions()
|
||||||
{
|
{
|
||||||
$this->showAdvancedOptions = ! $this->showAdvancedOptions;
|
$this->showAdvancedOptions = !$this->showAdvancedOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getMonthNames(): array
|
private function getMonthNames(): array
|
||||||
|
|
@ -138,7 +130,7 @@ private function getMonthNames(): array
|
||||||
return [
|
return [
|
||||||
1 => 'January', 2 => 'February', 3 => 'March', 4 => 'April',
|
1 => 'January', 2 => 'February', 3 => 'March', 4 => 'April',
|
||||||
5 => 'May', 6 => 'June', 7 => 'July', 8 => 'August',
|
5 => 'May', 6 => 'June', 7 => 'July', 8 => 'August',
|
||||||
9 => 'September', 10 => 'October', 11 => 'November', 12 => 'December',
|
9 => 'September', 10 => 'October', 11 => 'November', 12 => 'December'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,10 @@
|
||||||
|
|
||||||
namespace App\Livewire\Users;
|
namespace App\Livewire\Users;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
use App\Actions\User\CreateUserAction;
|
use App\Actions\User\CreateUserAction;
|
||||||
use App\Actions\User\DeleteUserAction;
|
use App\Actions\User\DeleteUserAction;
|
||||||
use App\Actions\User\EditUserAction;
|
use App\Actions\User\EditUserAction;
|
||||||
use App\Models\User;
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Contracts\View\View;
|
use Illuminate\Contracts\View\View;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
|
@ -16,13 +16,10 @@ class UsersList extends Component
|
||||||
use WithPagination;
|
use WithPagination;
|
||||||
|
|
||||||
public bool $showCreateModal = false;
|
public bool $showCreateModal = false;
|
||||||
|
|
||||||
public bool $showEditModal = false;
|
public bool $showEditModal = false;
|
||||||
|
|
||||||
public bool $showDeleteModal = false;
|
public bool $showDeleteModal = false;
|
||||||
|
|
||||||
public ?User $editingUser = null;
|
public ?User $editingUser = null;
|
||||||
|
|
||||||
public ?User $deletingUser = null;
|
public ?User $deletingUser = null;
|
||||||
|
|
||||||
// Form fields
|
// Form fields
|
||||||
|
|
@ -39,7 +36,7 @@ public function render(): View
|
||||||
->paginate(10);
|
->paginate(10);
|
||||||
|
|
||||||
return view('livewire.users.users-list', [
|
return view('livewire.users.users-list', [
|
||||||
'users' => $users,
|
'users' => $users
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -55,7 +52,7 @@ public function store(): void
|
||||||
$this->validate();
|
$this->validate();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
(new CreateUserAction)->execute([
|
(new CreateUserAction())->execute([
|
||||||
'name' => $this->name,
|
'name' => $this->name,
|
||||||
'planner_id' => auth()->id(),
|
'planner_id' => auth()->id(),
|
||||||
]);
|
]);
|
||||||
|
|
@ -65,7 +62,7 @@ public function store(): void
|
||||||
|
|
||||||
session()->flash('success', 'User created successfully.');
|
session()->flash('success', 'User created successfully.');
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
session()->flash('error', 'Failed to create user: '.$e->getMessage());
|
session()->flash('error', 'Failed to create user: ' . $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -82,7 +79,7 @@ public function update(): void
|
||||||
$this->validate();
|
$this->validate();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
(new EditUserAction)->execute($this->editingUser, ['name' => $this->name]);
|
(new EditUserAction())->execute($this->editingUser, ['name' => $this->name]);
|
||||||
|
|
||||||
$this->showEditModal = false;
|
$this->showEditModal = false;
|
||||||
$this->reset(['name', 'editingUser']);
|
$this->reset(['name', 'editingUser']);
|
||||||
|
|
@ -92,7 +89,7 @@ public function update(): void
|
||||||
// Force component to re-render with fresh data
|
// Force component to re-render with fresh data
|
||||||
$this->resetPage();
|
$this->resetPage();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
session()->flash('error', 'Failed to update user: '.$e->getMessage());
|
session()->flash('error', 'Failed to update user: ' . $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -105,7 +102,7 @@ public function confirmDelete(User $user): void
|
||||||
public function delete(): void
|
public function delete(): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
(new DeleteUserAction)->execute($this->deletingUser);
|
(new DeleteUserAction())->execute($this->deletingUser);
|
||||||
|
|
||||||
$this->showDeleteModal = false;
|
$this->showDeleteModal = false;
|
||||||
$this->deletingUser = null;
|
$this->deletingUser = null;
|
||||||
|
|
@ -115,7 +112,7 @@ public function delete(): void
|
||||||
// Force component to re-render with fresh data
|
// Force component to re-render with fresh data
|
||||||
$this->resetPage();
|
$this->resetPage();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
session()->flash('error', 'Failed to delete user: '.$e->getMessage());
|
session()->flash('error', 'Failed to delete user: ' . $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@
|
||||||
* @property Carbon $updated_at
|
* @property Carbon $updated_at
|
||||||
* @property Collection<User> $users
|
* @property Collection<User> $users
|
||||||
* @property Collection<UserDish> $userDishes
|
* @property Collection<UserDish> $userDishes
|
||||||
*
|
|
||||||
* @method static create(array $data)
|
* @method static create(array $data)
|
||||||
* @method static findOrFail(int $dish_id)
|
* @method static findOrFail(int $dish_id)
|
||||||
* @method static DishFactory factory($count = null, $state = [])
|
* @method static DishFactory factory($count = null, $state = [])
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
|
|
@ -12,10 +11,7 @@
|
||||||
/**
|
/**
|
||||||
* @property int $id
|
* @property int $id
|
||||||
* @property static PlannerFactory factory($count = null, $state = [])
|
* @property static PlannerFactory factory($count = null, $state = [])
|
||||||
* @property Collection<User> $users
|
|
||||||
*
|
|
||||||
* @method static first()
|
* @method static first()
|
||||||
* @method static create(array $array)
|
|
||||||
*/
|
*/
|
||||||
class Planner extends Authenticatable
|
class Planner extends Authenticatable
|
||||||
{
|
{
|
||||||
|
|
@ -37,9 +33,4 @@ public function schedules(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(Schedule::class);
|
return $this->hasMany(Schedule::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function users(): HasMany
|
|
||||||
{
|
|
||||||
return $this->hasMany(User::class);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,8 @@
|
||||||
* @property Dish $dish
|
* @property Dish $dish
|
||||||
* @property User $user
|
* @property User $user
|
||||||
* @property Carbon $date
|
* @property Carbon $date
|
||||||
* @property bool $is_skipped
|
* @property boolean $is_skipped
|
||||||
* @property Collection<ScheduledUserDish> $scheduledUserDishes
|
* @property Collection<ScheduledUserDish> $scheduledUserDishes
|
||||||
*
|
|
||||||
* @method static create(array $array)
|
* @method static create(array $array)
|
||||||
* @method static Builder where(array|Closure|Expression|string $column, mixed $operator = null, mixed $value = null, string $boolean = 'and')
|
* @method static Builder where(array|Closure|Expression|string $column, mixed $operator = null, mixed $value = null, string $boolean = 'and')
|
||||||
* @method static ScheduleFactory factory($count = null, $state = [])
|
* @method static ScheduleFactory factory($count = null, $state = [])
|
||||||
|
|
@ -39,8 +38,6 @@ class Schedule extends Model
|
||||||
|
|
||||||
public $timestamps = false;
|
public $timestamps = false;
|
||||||
|
|
||||||
protected $dateFormat = 'Y-m-d';
|
|
||||||
|
|
||||||
protected $fillable = ['planner_id', 'date', 'is_skipped'];
|
protected $fillable = ['planner_id', 'date', 'is_skipped'];
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
* @property int $user_dish_id
|
* @property int $user_dish_id
|
||||||
* @property UserDish $userDish
|
* @property UserDish $userDish
|
||||||
* @property bool $is_skipped
|
* @property bool $is_skipped
|
||||||
*
|
|
||||||
* @method static create(array $array)
|
* @method static create(array $array)
|
||||||
* @method static ScheduledUserDishFactory factory($count = null, $state = [])
|
* @method static ScheduledUserDishFactory factory($count = null, $state = [])
|
||||||
* @method static firstOrCreate(array $array, array $array1)
|
* @method static firstOrCreate(array $array, array $array1)
|
||||||
|
|
@ -30,7 +29,7 @@ class ScheduledUserDish extends Model
|
||||||
'schedule_id',
|
'schedule_id',
|
||||||
'user_id',
|
'user_id',
|
||||||
'user_dish_id',
|
'user_dish_id',
|
||||||
'is_skipped',
|
'is_skipped'
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,10 @@
|
||||||
use Database\Factories\UserFactory;
|
use Database\Factories\UserFactory;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property int $id
|
* @property int $id
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
* @property string $name
|
* @property string $name
|
||||||
* @property Collection<Dish> $dishes
|
* @property Collection<Dish> $dishes
|
||||||
* @property Collection<UserDish> $userDishes
|
* @property Collection<UserDish> $userDishes
|
||||||
*
|
|
||||||
* @method static User findOrFail(int $user_id)
|
* @method static User findOrFail(int $user_id)
|
||||||
* @method static UserFactory factory($count = null, $state = [])
|
* @method static UserFactory factory($count = null, $state = [])
|
||||||
* @method static create(array $array)
|
* @method static create(array $array)
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
* @method static UserDish|null find(int|null $user_dish_id)
|
* @method static UserDish|null find(int|null $user_dish_id)
|
||||||
* @method static create(array $array)
|
* @method static create(array $array)
|
||||||
* @method static where(string $string, int $id)
|
* @method static where(string $string, int $id)
|
||||||
*
|
|
||||||
* @property int $id
|
* @property int $id
|
||||||
* @property int $dish_id
|
* @property int $dish_id
|
||||||
* @property int $user_id
|
* @property int $user_id
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ public function getValue(): int
|
||||||
return match ($this->recurrence_type) {
|
return match ($this->recurrence_type) {
|
||||||
WeeklyRecurrence::class => $this->recurrence->weekday->value,
|
WeeklyRecurrence::class => $this->recurrence->weekday->value,
|
||||||
MinimumRecurrence::class => $this->recurrence->days,
|
MinimumRecurrence::class => $this->recurrence->days,
|
||||||
default => throw new InvalidRecurrenceTypeException
|
default => throw new InvalidRecurrenceTypeException()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,10 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property int $weekday
|
* @property int $weekday
|
||||||
*
|
|
||||||
* @method static create(array $array)
|
* @method static create(array $array)
|
||||||
* @method static WeeklyRecurrenceFactory factory($count = null, $state = [])
|
* @method static WeeklyRecurrenceFactory factory($count = null, $state = [])
|
||||||
*/
|
*/
|
||||||
class WeeklyRecurrence extends Model implements FixedRecurrenceInterface, RecurrenceInterface
|
class WeeklyRecurrence extends Model implements RecurrenceInterface, FixedRecurrenceInterface
|
||||||
{
|
{
|
||||||
/** @use HasFactory<WeeklyRecurrenceFactory> */
|
/** @use HasFactory<WeeklyRecurrenceFactory> */
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
use Illuminate\Contracts\Debug\ExceptionHandler;
|
use Illuminate\Contracts\Debug\ExceptionHandler;
|
||||||
use Illuminate\Foundation\Exceptions\Handler as BaseHandler;
|
use Illuminate\Foundation\Exceptions\Handler as BaseHandler;
|
||||||
use Illuminate\Support\Facades\Gate;
|
use Illuminate\Support\Facades\Gate;
|
||||||
|
use Illuminate\Support\Facades\URL;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
|
|
@ -24,8 +25,7 @@ class AppServiceProvider extends ServiceProvider
|
||||||
public function register(): void
|
public function register(): void
|
||||||
{
|
{
|
||||||
$this->app->bind(ExceptionHandler::class, function ($app) {
|
$this->app->bind(ExceptionHandler::class, function ($app) {
|
||||||
return new class($app) extends BaseHandler
|
return new class($app) extends BaseHandler {
|
||||||
{
|
|
||||||
public function render($request, Throwable $e)
|
public function render($request, Throwable $e)
|
||||||
{
|
{
|
||||||
// Handle specific custom exception
|
// Handle specific custom exception
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Services;
|
namespace App\Services;
|
||||||
|
|
||||||
|
|
||||||
class OutputService
|
class OutputService
|
||||||
{
|
{
|
||||||
public function response(bool $success = true, ?array $payload = null, array|string|null $errors = null): array
|
public function response(bool $success = true, ?array $payload = null, array|string|null $errors = null): array
|
||||||
|
|
|
||||||
29
bin/build-push.sh
Executable file
29
bin/build-push.sh
Executable file
|
|
@ -0,0 +1,29 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# Build and push production image to Codeberg
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
REGISTRY="codeberg.org"
|
||||||
|
NAMESPACE="lvl0"
|
||||||
|
IMAGE_NAME="dish-planner"
|
||||||
|
TAG="${1:-latest}"
|
||||||
|
|
||||||
|
echo "🔨 Building production image..."
|
||||||
|
podman build -f Dockerfile -t ${REGISTRY}/${NAMESPACE}/${IMAGE_NAME}:${TAG} .
|
||||||
|
|
||||||
|
echo "📤 Pushing to Codeberg registry..."
|
||||||
|
echo "Please ensure you're logged in to Codeberg:"
|
||||||
|
echo " podman login codeberg.org"
|
||||||
|
|
||||||
|
podman push ${REGISTRY}/${NAMESPACE}/${IMAGE_NAME}:${TAG}
|
||||||
|
|
||||||
|
echo "✅ Done! Image pushed to ${REGISTRY}/${NAMESPACE}/${IMAGE_NAME}:${TAG}"
|
||||||
|
echo ""
|
||||||
|
echo "To deploy in production:"
|
||||||
|
echo "1. Copy docker-compose.prod.yml to your server"
|
||||||
|
echo "2. Set required environment variables:"
|
||||||
|
echo " - APP_KEY (generate with: openssl rand -base64 32)"
|
||||||
|
echo " - APP_URL"
|
||||||
|
echo " - DB_DATABASE, DB_USERNAME, DB_PASSWORD, DB_ROOT_PASSWORD"
|
||||||
|
echo "3. Run: docker-compose -f docker-compose.prod.yml up -d"
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
docker build -t forge.lvl0.xyz/lvl0/dishplanner:latest .
|
docker build -t 192.168.178.152:50114/dishplanner-backend .
|
||||||
docker push forge.lvl0.xyz/lvl0/dishplanner:latest
|
docker push 192.168.178.152:50114/dishplanner-backend
|
||||||
|
|
|
||||||
159
bin/start-dev
Executable file
159
bin/start-dev
Executable file
|
|
@ -0,0 +1,159 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Colors for output
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
# Get script directory and project root
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||||
|
|
||||||
|
# Detect Docker or Podman
|
||||||
|
CONTAINER_CLI=""
|
||||||
|
# Check if docker is actually podman in disguise
|
||||||
|
if command -v docker &> /dev/null && docker --version 2>&1 | grep -q "podman"; then
|
||||||
|
CONTAINER_CLI="podman"
|
||||||
|
echo -e "${GREEN}Using Podman (via docker alias)${NC}"
|
||||||
|
elif command -v docker &> /dev/null && docker info &> /dev/null; then
|
||||||
|
CONTAINER_CLI="docker"
|
||||||
|
echo -e "${GREEN}Using Docker${NC}"
|
||||||
|
elif command -v podman &> /dev/null; then
|
||||||
|
CONTAINER_CLI="podman"
|
||||||
|
echo -e "${GREEN}Using Podman${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${RED}✗ Neither Docker nor Podman found. Please install one of them first.${NC}"
|
||||||
|
echo -e "${YELLOW}Install Docker: https://docs.docker.com/get-docker/${NC}"
|
||||||
|
echo -e "${YELLOW}Install Podman: https://podman.io/getting-started/installation${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "${GREEN}=== Dish Planner Development Setup ===${NC}\n"
|
||||||
|
|
||||||
|
# Check if .env exists in backend
|
||||||
|
if [ ! -f "$PROJECT_ROOT/backend/.env" ]; then
|
||||||
|
echo -e "${YELLOW}Creating backend/.env from .env.example...${NC}"
|
||||||
|
cp "$PROJECT_ROOT/backend/.env.example" "$PROJECT_ROOT/backend/.env"
|
||||||
|
echo -e "${GREEN}✓ Created backend/.env${NC}\n"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Ensure APP_PORT is set for Podman (can't use privileged port 80)
|
||||||
|
if [ "$CONTAINER_CLI" = "podman" ] && ! grep -q "^APP_PORT=" "$PROJECT_ROOT/backend/.env"; then
|
||||||
|
echo -e "${YELLOW}Setting APP_PORT=8000 for Podman (non-privileged port)...${NC}"
|
||||||
|
echo "APP_PORT=8000" >> "$PROJECT_ROOT/backend/.env"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Backend setup
|
||||||
|
echo -e "${GREEN}=== Backend Setup ===${NC}"
|
||||||
|
cd "$PROJECT_ROOT/backend"
|
||||||
|
|
||||||
|
# Install dependencies if vendor doesn't exist
|
||||||
|
if [ ! -d "vendor" ]; then
|
||||||
|
echo -e "${YELLOW}No vendor directory found. Installing dependencies with Docker...${NC}"
|
||||||
|
# Use a standalone PHP/Composer Docker image to install dependencies
|
||||||
|
# This is the recommended Laravel approach for first-time setup
|
||||||
|
# Configure for Docker or Podman
|
||||||
|
VOLUME_OPTS="$PROJECT_ROOT/backend:/var/www/html"
|
||||||
|
USER_OPTS="-u $(id -u):$(id -g)"
|
||||||
|
EXTRA_OPTS=""
|
||||||
|
|
||||||
|
if [ "$CONTAINER_CLI" = "podman" ]; then
|
||||||
|
# Podman on SELinux systems needs :Z and --userns=keep-id to maintain user ID
|
||||||
|
VOLUME_OPTS="$VOLUME_OPTS:Z"
|
||||||
|
USER_OPTS=""
|
||||||
|
EXTRA_OPTS="--userns=keep-id"
|
||||||
|
fi
|
||||||
|
|
||||||
|
$CONTAINER_CLI run --rm \
|
||||||
|
$USER_OPTS \
|
||||||
|
$EXTRA_OPTS \
|
||||||
|
-v "$VOLUME_OPTS" \
|
||||||
|
-w /var/www/html \
|
||||||
|
docker.io/laravelsail/php84-composer:latest \
|
||||||
|
composer install --ignore-platform-reqs
|
||||||
|
|
||||||
|
echo -e "${GREEN}✓ Backend dependencies installed${NC}\n"
|
||||||
|
else
|
||||||
|
echo -e "${GREEN}✓ Backend dependencies already installed${NC}\n"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if database volume exists - if not, we're doing fresh initialization
|
||||||
|
FRESH_DB=false
|
||||||
|
if ! $CONTAINER_CLI volume inspect sail-mysql &>/dev/null && ! $CONTAINER_CLI volume inspect backend_sail-mysql &>/dev/null; then
|
||||||
|
FRESH_DB=true
|
||||||
|
echo -e "${YELLOW}Fresh database initialization detected${NC}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Start containers using compose directly (docker-compose.override.yml is automatically used)
|
||||||
|
echo -e "${YELLOW}Starting backend containers...${NC}"
|
||||||
|
if $CONTAINER_CLI compose up -d 2>&1 | tee /tmp/compose-up.log; then
|
||||||
|
echo -e "${GREEN}✓ Containers started${NC}\n"
|
||||||
|
else
|
||||||
|
echo -e "${RED}✗ Failed to start containers. Check /tmp/compose-up.log for details${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Wait for database to be ready
|
||||||
|
echo -e "${YELLOW}Waiting for database to be ready...${NC}"
|
||||||
|
MAX_ATTEMPTS=30
|
||||||
|
ATTEMPT=0
|
||||||
|
while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do
|
||||||
|
if $CONTAINER_CLI compose exec mysql mysqladmin ping -h localhost --silent 2>/dev/null; then
|
||||||
|
echo -e "${GREEN}✓ Database is ready${NC}"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
ATTEMPT=$((ATTEMPT + 1))
|
||||||
|
echo -e "${YELLOW}Waiting for database... (attempt $ATTEMPT/$MAX_ATTEMPTS)${NC}"
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ $ATTEMPT -eq $MAX_ATTEMPTS ]; then
|
||||||
|
echo -e "${RED}✗ Database failed to become ready${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Give MySQL extra time on fresh initialization to create users
|
||||||
|
if [ "$FRESH_DB" = true ]; then
|
||||||
|
echo -e "${YELLOW}Waiting for fresh database to complete initialization...${NC}"
|
||||||
|
sleep 10
|
||||||
|
else
|
||||||
|
sleep 3
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Run migrations
|
||||||
|
echo -e "${YELLOW}Running database migrations...${NC}"
|
||||||
|
$CONTAINER_CLI compose exec backend php artisan migrate --force
|
||||||
|
|
||||||
|
# Check if database has data
|
||||||
|
echo -e "${YELLOW}Checking if database needs seeding...${NC}"
|
||||||
|
TABLE_COUNT=$($CONTAINER_CLI compose exec backend php artisan tinker --execute="echo \DB::table('users')->count();" 2>/dev/null | tail -1 | tr -d '[:space:]' || echo "0")
|
||||||
|
# Default to 0 if not a number
|
||||||
|
if ! [[ "$TABLE_COUNT" =~ ^[0-9]+$ ]]; then
|
||||||
|
TABLE_COUNT=0
|
||||||
|
fi
|
||||||
|
if [ "$TABLE_COUNT" -eq "0" ]; then
|
||||||
|
echo -e "${YELLOW}Database is empty. Run seeders? (y/n)${NC}"
|
||||||
|
read -r response
|
||||||
|
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
|
||||||
|
$CONTAINER_CLI compose exec backend php artisan db:seed
|
||||||
|
echo -e "${GREEN}✓ Database seeded${NC}\n"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "${GREEN}✓ Backend setup complete${NC}"
|
||||||
|
echo -e "${GREEN}Backend API running at: http://localhost:8000${NC}\n"
|
||||||
|
|
||||||
|
# Display summary
|
||||||
|
echo -e "${GREEN}=== Development Environment Ready ===${NC}"
|
||||||
|
echo -e "${GREEN}Backend API:${NC} http://localhost:8000"
|
||||||
|
echo -e "${GREEN}Frontend:${NC} http://localhost:5173"
|
||||||
|
echo -e "${GREEN}Database:${NC} MySQL on localhost:3306"
|
||||||
|
echo -e ""
|
||||||
|
echo -e "${YELLOW}Note:${NC} Frontend container will install dependencies and start automatically."
|
||||||
|
echo -e "${YELLOW}To view frontend logs:${NC}"
|
||||||
|
echo -e " cd backend && $CONTAINER_CLI compose logs -f frontend"
|
||||||
|
echo -e ""
|
||||||
|
echo -e "${YELLOW}To stop all services:${NC}"
|
||||||
|
echo -e " cd backend && $CONTAINER_CLI compose down"
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
echo "🔄 Pulling latest changes..."
|
echo "🔄 Pulling latest backend changes..."
|
||||||
git pull origin main
|
git pull origin main
|
||||||
|
|
||||||
echo "📦 Installing PHP dependencies..."
|
echo "📦 Installing PHP dependencies..."
|
||||||
|
|
@ -15,4 +15,4 @@ php artisan config:cache
|
||||||
php artisan route:cache
|
php artisan route:cache
|
||||||
php artisan view:cache
|
php artisan view:cache
|
||||||
|
|
||||||
echo "✅ Update complete!"
|
echo "✅ Backend update complete!"
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,17 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Http\Middleware\ForceJsonResponse;
|
use App\Http\Middleware\ForceJsonResponse;
|
||||||
|
use App\Http\Middleware\HandleResourceNotFound;
|
||||||
use App\Services\OutputService;
|
use App\Services\OutputService;
|
||||||
|
use DishPlanner\Dish\Controllers\DishController;
|
||||||
|
use DishPlanner\Schedule\Console\Commands\GenerateScheduleCommand;
|
||||||
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||||
use Illuminate\Foundation\Application;
|
use Illuminate\Foundation\Application;
|
||||||
use Illuminate\Foundation\Configuration\Exceptions;
|
use Illuminate\Foundation\Configuration\Exceptions;
|
||||||
use Illuminate\Foundation\Configuration\Middleware;
|
use Illuminate\Foundation\Configuration\Middleware;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
use Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful;
|
||||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
|
|
@ -60,4 +65,7 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
->withCommands([
|
||||||
|
GenerateScheduleCommand::class,
|
||||||
|
])
|
||||||
->create();
|
->create();
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Providers\AppServiceProvider;
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
AppServiceProvider::class,
|
App\Providers\AppServiceProvider::class,
|
||||||
];
|
];
|
||||||
|
|
|
||||||
29
build-push.sh
Executable file
29
build-push.sh
Executable file
|
|
@ -0,0 +1,29 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# Build and push production image to Codeberg
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
REGISTRY="codeberg.org"
|
||||||
|
NAMESPACE="lvl0"
|
||||||
|
IMAGE_NAME="dish-planner"
|
||||||
|
TAG="${1:-latest}"
|
||||||
|
|
||||||
|
echo "🔨 Building production image..."
|
||||||
|
podman build -f Dockerfile -t ${REGISTRY}/${NAMESPACE}/${IMAGE_NAME}:${TAG} .
|
||||||
|
|
||||||
|
echo "📤 Pushing to Codeberg registry..."
|
||||||
|
echo "Please ensure you're logged in to Codeberg:"
|
||||||
|
echo " podman login codeberg.org"
|
||||||
|
|
||||||
|
podman push ${REGISTRY}/${NAMESPACE}/${IMAGE_NAME}:${TAG}
|
||||||
|
|
||||||
|
echo "✅ Done! Image pushed to ${REGISTRY}/${NAMESPACE}/${IMAGE_NAME}:${TAG}"
|
||||||
|
echo ""
|
||||||
|
echo "To deploy in production:"
|
||||||
|
echo "1. Copy docker-compose.prod.yml to your server"
|
||||||
|
echo "2. Set required environment variables:"
|
||||||
|
echo " - APP_KEY (generate with: openssl rand -base64 32)"
|
||||||
|
echo " - APP_URL"
|
||||||
|
echo " - DB_DATABASE, DB_USERNAME, DB_PASSWORD, DB_ROOT_PASSWORD"
|
||||||
|
echo "3. Run: docker-compose -f docker-compose.prod.yml up -d"
|
||||||
3
build_and_push.sh
Executable file
3
build_and_push.sh
Executable file
|
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/bash
|
||||||
|
docker build -t 192.168.178.152:50114/dishplanner-backend .
|
||||||
|
docker push 192.168.178.152:50114/dishplanner-backend
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
"laravel",
|
"laravel",
|
||||||
"framework"
|
"framework"
|
||||||
],
|
],
|
||||||
"license": "AGPL-3.0-only",
|
"license": "MIT",
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^8.2",
|
"php": "^8.2",
|
||||||
"laravel/framework": "^12.9.2",
|
"laravel/framework": "^12.9.2",
|
||||||
|
|
@ -17,14 +17,12 @@
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"fakerphp/faker": "^1.23",
|
"fakerphp/faker": "^1.23",
|
||||||
"larastan/larastan": "^3.10",
|
|
||||||
"laravel/dusk": "^8.3",
|
"laravel/dusk": "^8.3",
|
||||||
"laravel/pail": "^1.1",
|
"laravel/pail": "^1.1",
|
||||||
"laravel/pint": "^1.13",
|
"laravel/pint": "^1.13",
|
||||||
"laravel/sail": "^1.26",
|
"laravel/sail": "^1.26",
|
||||||
"mockery/mockery": "^1.6",
|
"mockery/mockery": "^1.6",
|
||||||
"nunomaduro/collision": "^8.1",
|
"nunomaduro/collision": "^8.1",
|
||||||
"phpstan/phpstan-mockery": "^2.0",
|
|
||||||
"phpunit/phpunit": "^11.0.1"
|
"phpunit/phpunit": "^11.0.1"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
|
|
|
||||||
8923
composer.lock
generated
8923
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -1,7 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Models\Planner;
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -52,7 +50,7 @@
|
||||||
'providers' => [
|
'providers' => [
|
||||||
'planners' => [
|
'planners' => [
|
||||||
'driver' => 'eloquent',
|
'driver' => 'eloquent',
|
||||||
'model' => Planner::class,
|
'model' => App\Models\Planner::class,
|
||||||
],
|
],
|
||||||
|
|
||||||
// 'users' => [
|
// 'users' => [
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Illuminate\Cookie\Middleware\EncryptCookies;
|
|
||||||
use Illuminate\Foundation\Http\Middleware\ValidateCsrfToken;
|
|
||||||
use Laravel\Sanctum\Http\Middleware\AuthenticateSession;
|
|
||||||
use Laravel\Sanctum\Sanctum;
|
use Laravel\Sanctum\Sanctum;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
@ -78,9 +75,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'middleware' => [
|
'middleware' => [
|
||||||
'authenticate_session' => AuthenticateSession::class,
|
'authenticate_session' => Laravel\Sanctum\Http\Middleware\AuthenticateSession::class,
|
||||||
'encrypt_cookies' => EncryptCookies::class,
|
'encrypt_cookies' => Illuminate\Cookie\Middleware\EncryptCookies::class,
|
||||||
'validate_csrf_token' => ValidateCsrfToken::class,
|
'validate_csrf_token' => Illuminate\Foundation\Http\Middleware\ValidateCsrfToken::class,
|
||||||
],
|
],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@
|
||||||
namespace Database\Factories;
|
namespace Database\Factories;
|
||||||
|
|
||||||
use App\Models\Dish;
|
use App\Models\Dish;
|
||||||
use App\Models\User;
|
|
||||||
use App\Models\UserDish;
|
use App\Models\UserDish;
|
||||||
|
use App\Models\User;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Database\Seeders;
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ public function run(): void
|
||||||
[
|
[
|
||||||
'name' => 'Admin',
|
'name' => 'Admin',
|
||||||
'email' => 'admin@test.com',
|
'email' => 'admin@test.com',
|
||||||
'password' => 'password',
|
'password' => 'password'
|
||||||
],
|
],
|
||||||
])->each(fn (array $data) => Planner::create([
|
])->each(fn (array $data) => Planner::create([
|
||||||
'name' => $data['name'],
|
'name' => $data['name'],
|
||||||
|
|
|
||||||
|
|
@ -41,10 +41,11 @@ private function createScheduleForPeriod(CarbonPeriod $period): void
|
||||||
$planner = Planner::all()->first() ?? Planner::factory()->create();
|
$planner = Planner::all()->first() ?? Planner::factory()->create();
|
||||||
|
|
||||||
collect($period)
|
collect($period)
|
||||||
->each(fn (Carbon $date) => User::query()
|
->each(fn (Carbon $date) =>
|
||||||
|
User::query()
|
||||||
->inRandomOrder()
|
->inRandomOrder()
|
||||||
->get()
|
->get()
|
||||||
->each(fn (User $user) => (new CreateScheduledUserDishAction)
|
->each(fn (User $user) => (new CreateScheduledUserDishAction())
|
||||||
->execute(
|
->execute(
|
||||||
planner: $planner,
|
planner: $planner,
|
||||||
schedule: resolve(ScheduleRepository::class)->findOrCreate($planner, $date),
|
schedule: resolve(ScheduleRepository::class)->findOrCreate($planner, $date),
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ public function run(): void
|
||||||
->each(fn (string $name) => User::factory()->create([
|
->each(fn (string $name) => User::factory()->create([
|
||||||
'planner_id' => $planner->id,
|
'planner_id' => $planner->id,
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
]));
|
]))
|
||||||
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
# Production Docker Compose
|
# Production Docker Compose
|
||||||
services:
|
services:
|
||||||
app:
|
app:
|
||||||
image: forge.lvl0.xyz/lvl0/dishplanner:latest
|
image: codeberg.org/lvl0/dish-planner:latest
|
||||||
container_name: dishplanner_app
|
container_name: dishplanner_app
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
|
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
# CI image: PHP + Composer only, no runtime server or frontend toolchain.
|
|
||||||
# Tests run against SQLite in memory (see .env.testing), so no database client
|
|
||||||
# or cache extension is needed.
|
|
||||||
#
|
|
||||||
# Published as dishplanner-ci:php8.3-<composer.lock hash>. The CI workflow
|
|
||||||
# builds and tags this image from the current lockfile, so a dependency change
|
|
||||||
# automatically yields a fresh, uniquely-tagged image (no manual revision bump).
|
|
||||||
#
|
|
||||||
# Debian-based rather than Alpine to avoid the DNS resolution timeouts against
|
|
||||||
# codeload.github.com that the Alpine base hit during composer install.
|
|
||||||
|
|
||||||
FROM php:8.3-cli
|
|
||||||
|
|
||||||
COPY --from=mlocati/php-extension-installer:2 /usr/bin/install-php-extensions /usr/local/bin/
|
|
||||||
|
|
||||||
RUN install-php-extensions \
|
|
||||||
pdo_sqlite \
|
|
||||||
mbstring \
|
|
||||||
dom \
|
|
||||||
xml \
|
|
||||||
fileinfo \
|
|
||||||
pcntl \
|
|
||||||
zip
|
|
||||||
|
|
||||||
# git is needed by the checkout action; nodejs runs the Forgejo JavaScript
|
|
||||||
# actions (checkout, cache); unzip lets Composer extract dist archives.
|
|
||||||
RUN apt-get update \
|
|
||||||
&& apt-get install -y --no-install-recommends git unzip nodejs \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
|
|
||||||
|
|
||||||
# Bake the project's PHP dependencies (dev included) into the image so CI
|
|
||||||
# restores them with a local copy instead of paying a per-run composer install
|
|
||||||
# over the network. --prefer-source clones via git instead of fetching dist
|
|
||||||
# archives, avoiding the codeload.github.com rate limits the runner hits under
|
|
||||||
# --prefer-dist.
|
|
||||||
#
|
|
||||||
# --no-scripts skips `php artisan package:discover` (the app isn't present
|
|
||||||
# here). CI runs `composer install` after restoring vendor, which regenerates
|
|
||||||
# bootstrap/cache.
|
|
||||||
WORKDIR /opt/deps
|
|
||||||
COPY composer.json composer.lock ./
|
|
||||||
RUN composer install --no-interaction --no-progress --prefer-source --no-scripts
|
|
||||||
4
frontend-old/.dockerignore
Normal file
4
frontend-old/.dockerignore
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
.react-router
|
||||||
|
build
|
||||||
|
node_modules
|
||||||
|
README.md
|
||||||
6
frontend-old/.gitignore
vendored
Normal file
6
frontend-old/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
.DS_Store
|
||||||
|
/node_modules/
|
||||||
|
|
||||||
|
# React Router
|
||||||
|
/.react-router/
|
||||||
|
/build/
|
||||||
22
frontend-old/Dockerfile
Normal file
22
frontend-old/Dockerfile
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
FROM node:20-alpine AS development-dependencies-env
|
||||||
|
COPY . /app
|
||||||
|
WORKDIR /app
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
FROM node:20-alpine AS production-dependencies-env
|
||||||
|
COPY ./package.json package-lock.json /app/
|
||||||
|
WORKDIR /app
|
||||||
|
RUN npm ci --omit=dev
|
||||||
|
|
||||||
|
FROM node:20-alpine AS build-env
|
||||||
|
COPY . /app/
|
||||||
|
COPY --from=development-dependencies-env /app/node_modules /app/node_modules
|
||||||
|
WORKDIR /app
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
FROM node:20-alpine
|
||||||
|
COPY ./package.json package-lock.json /app/
|
||||||
|
COPY --from=production-dependencies-env /app/node_modules /app/node_modules
|
||||||
|
COPY --from=build-env /app/build /app/build
|
||||||
|
WORKDIR /app
|
||||||
|
CMD ["npm", "run", "start"]
|
||||||
87
frontend-old/README.md
Normal file
87
frontend-old/README.md
Normal file
|
|
@ -0,0 +1,87 @@
|
||||||
|
# Welcome to React Router!
|
||||||
|
|
||||||
|
A modern, production-ready template for building full-stack React applications using React Router.
|
||||||
|
|
||||||
|
[](https://stackblitz.com/github/remix-run/react-router-templates/tree/main/default)
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- 🚀 Server-side rendering
|
||||||
|
- ⚡️ Hot Module Replacement (HMR)
|
||||||
|
- 📦 Asset bundling and optimization
|
||||||
|
- 🔄 Data loading and mutations
|
||||||
|
- 🔒 TypeScript by default
|
||||||
|
- 🎉 TailwindCSS for styling
|
||||||
|
- 📖 [React Router docs](https://reactrouter.com/)
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
### Installation
|
||||||
|
|
||||||
|
Install the dependencies:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install
|
||||||
|
```
|
||||||
|
|
||||||
|
### Development
|
||||||
|
|
||||||
|
Start the development server with HMR:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run dev
|
||||||
|
```
|
||||||
|
|
||||||
|
Your application will be available at `http://localhost:5173`.
|
||||||
|
|
||||||
|
## Building for Production
|
||||||
|
|
||||||
|
Create a production build:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run build
|
||||||
|
```
|
||||||
|
|
||||||
|
## Deployment
|
||||||
|
|
||||||
|
### Docker Deployment
|
||||||
|
|
||||||
|
To build and run using Docker:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker build -t my-app .
|
||||||
|
|
||||||
|
# Run the container
|
||||||
|
docker run -p 3000:3000 my-app
|
||||||
|
```
|
||||||
|
|
||||||
|
The containerized application can be deployed to any platform that supports Docker, including:
|
||||||
|
|
||||||
|
- AWS ECS
|
||||||
|
- Google Cloud Run
|
||||||
|
- Azure Container Apps
|
||||||
|
- Digital Ocean App Platform
|
||||||
|
- Fly.io
|
||||||
|
- Railway
|
||||||
|
|
||||||
|
### DIY Deployment
|
||||||
|
|
||||||
|
If you're familiar with deploying Node applications, the built-in app server is production-ready.
|
||||||
|
|
||||||
|
Make sure to deploy the output of `npm run build`
|
||||||
|
|
||||||
|
```
|
||||||
|
├── package.json
|
||||||
|
├── package-lock.json (or pnpm-lock.yaml, or bun.lockb)
|
||||||
|
├── build/
|
||||||
|
│ ├── client/ # Static assets
|
||||||
|
│ └── server/ # Server-side code
|
||||||
|
```
|
||||||
|
|
||||||
|
## Styling
|
||||||
|
|
||||||
|
This template comes with [Tailwind CSS](https://tailwindcss.com/) already configured for a simple default starting experience. You can use whatever CSS framework you prefer.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Built with ❤️ using React Router.
|
||||||
18
frontend-old/app/app.css
Normal file
18
frontend-old/app/app.css
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300..700&family=Syncopate:wght@400;700&display=swap');
|
||||||
|
@import "tailwindcss";
|
||||||
|
|
||||||
|
@import "./styles/main.css";
|
||||||
|
|
||||||
|
@theme {
|
||||||
|
--font-sans: "Inter", ui-sans-serif, system-ui, sans-serif,
|
||||||
|
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
|
||||||
|
}
|
||||||
|
|
||||||
|
html,
|
||||||
|
body {
|
||||||
|
@apply bg-white dark:bg-gray-950;
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
color-scheme: dark;
|
||||||
|
}
|
||||||
|
}
|
||||||
15
frontend-old/app/components/Spinner.tsx
Normal file
15
frontend-old/app/components/Spinner.tsx
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
const Spinner = () => {
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex justify-center items-center">
|
||||||
|
<svg className="animate-spin h-5 w-5 text-gray-600" xmlns="http://www.w3.org/2000/svg" fill="none"
|
||||||
|
viewBox="0 0 24 24">
|
||||||
|
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"></circle>
|
||||||
|
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8v4a4 4 0 00-4 4H4z"></path>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Spinner
|
||||||
48
frontend-old/app/components/features/OnboardingBanner.tsx
Normal file
48
frontend-old/app/components/features/OnboardingBanner.tsx
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
import { Link } from "react-router"
|
||||||
|
import useRoutes from "@/hooks/useRoutes"
|
||||||
|
import { UserType } from "@/types/UserType"
|
||||||
|
import { DishType } from "@/types/DishType"
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
dishes: DishType[],
|
||||||
|
users: UserType[]
|
||||||
|
}
|
||||||
|
|
||||||
|
const OnboardingBanner = ({ dishes, users }: Props) => {
|
||||||
|
const routes = useRoutes();
|
||||||
|
|
||||||
|
const steps = [
|
||||||
|
{
|
||||||
|
label: "Create a user",
|
||||||
|
href: routes.user.create(),
|
||||||
|
count: users.length
|
||||||
|
}, {
|
||||||
|
label: "Create a dish",
|
||||||
|
href: routes.dish.create(),
|
||||||
|
count: dishes.length
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="border-2 border-secondary p-6 text-lg">
|
||||||
|
<div className="text-xl">Welcome to DishPlanner</div>
|
||||||
|
<div className="my-5">To get you started, please follow these steps to set up your account. This will ensure a better
|
||||||
|
experience.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{
|
||||||
|
steps.map((step, index) => (
|
||||||
|
<div className="w-full text-center text-2xl my-5" key={index}>
|
||||||
|
{
|
||||||
|
step.count === 0
|
||||||
|
? <Link to={ step.href } className="underline">{ step.label }</Link>
|
||||||
|
: <div className="line-through">{ step.label }</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default OnboardingBanner;
|
||||||
98
frontend-old/app/components/features/auth/LoginForm.tsx
Normal file
98
frontend-old/app/components/features/auth/LoginForm.tsx
Normal file
|
|
@ -0,0 +1,98 @@
|
||||||
|
|
||||||
|
import React, { useEffect, useState } from 'react';
|
||||||
|
import { Link, useLocation, useNavigate } from 'react-router';
|
||||||
|
import { useAuth } from '@/context/AuthContext';
|
||||||
|
import { login } from "@/utils/api/auth";
|
||||||
|
import useRoutes from "@/hooks/useRoutes";
|
||||||
|
import SolidButton from "@/components/ui/Buttons/SolidButton";
|
||||||
|
import Alert from "@/components/ui/Alert";
|
||||||
|
|
||||||
|
const LoginForm = () => {
|
||||||
|
const { login: authLogin } = useAuth();
|
||||||
|
const routes = useRoutes();
|
||||||
|
const [email, setEmail] = useState('');
|
||||||
|
const [password, setPassword] = useState('');
|
||||||
|
const [error, setError] = useState('');
|
||||||
|
const [alertSuccess, setAlertSuccess] = useState<string[]>([])
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const location = useLocation();
|
||||||
|
const searchParams = new URLSearchParams(location.search);
|
||||||
|
const isRegistered = searchParams.get('registered') === 'true';
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isRegistered) {
|
||||||
|
setAlertSuccess(['Registration successful!',' You can now log in.']);
|
||||||
|
|
||||||
|
const timer = setTimeout(() => {
|
||||||
|
const params = new URLSearchParams(searchParams.toString());
|
||||||
|
params.delete('registered');
|
||||||
|
const newUrl = `${window.location.pathname}?${params.toString()}`;
|
||||||
|
|
||||||
|
navigate(newUrl, { replace: true });
|
||||||
|
}, 3000);
|
||||||
|
|
||||||
|
return () => clearTimeout(timer)
|
||||||
|
}
|
||||||
|
}, [isRegistered, navigate, searchParams])
|
||||||
|
|
||||||
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
try {
|
||||||
|
await login(email, password);
|
||||||
|
authLogin();
|
||||||
|
navigate('/', { replace: true });
|
||||||
|
} catch (err) {
|
||||||
|
const errorMessage =
|
||||||
|
err instanceof Error
|
||||||
|
? err.message
|
||||||
|
: 'Login failed';
|
||||||
|
setError(errorMessage);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ marginTop: '15vh' }} className="lg:w-1/3 lg:mx-auto">
|
||||||
|
<div className="pt-2 text-2xl font-syncopate text-primary">
|
||||||
|
DISH PLANNER
|
||||||
|
</div>
|
||||||
|
<div className="border-2 border-secondary rounded-lg px-5 pt-5 pb-3 lg:pt-10 lg:pb-7">
|
||||||
|
{ alertSuccess.length > 0 &&
|
||||||
|
<Alert type="success" className="mb-4 px-5 py-2 capitalize text-center">
|
||||||
|
{alertSuccess.map((msg, index) => (
|
||||||
|
<React.Fragment key={index}>
|
||||||
|
{msg}
|
||||||
|
<br />
|
||||||
|
</React.Fragment>
|
||||||
|
))}
|
||||||
|
</Alert>
|
||||||
|
}
|
||||||
|
<form onSubmit={handleSubmit} className="max-w-sm mx-auto flex flex-col">
|
||||||
|
{error && <p className="text-red-600 mb-4">{error}</p>}
|
||||||
|
<input
|
||||||
|
type="email"
|
||||||
|
placeholder="Email"
|
||||||
|
value={email}
|
||||||
|
onChange={e => setEmail(e.target.value)}
|
||||||
|
required
|
||||||
|
className="w-full p-2 mb-4 border rounded border-secondary bg-gray-600 text-secondary"
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
placeholder="Password"
|
||||||
|
value={password}
|
||||||
|
onChange={e => setPassword(e.target.value)}
|
||||||
|
required
|
||||||
|
className="w-full p-2 mb-4 border rounded text-secondary border-secondary bg-gray-600"
|
||||||
|
/>
|
||||||
|
<SolidButton type="submit">Login</SolidButton>
|
||||||
|
<Link to={routes.auth.register()} className="lowercase hover:underline text-center mt-1 text-secondary underline">
|
||||||
|
Create an account
|
||||||
|
</Link>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default LoginForm
|
||||||
107
frontend-old/app/components/features/auth/RegisterForm.tsx
Normal file
107
frontend-old/app/components/features/auth/RegisterForm.tsx
Normal file
|
|
@ -0,0 +1,107 @@
|
||||||
|
import React, { useState } from 'react';
|
||||||
|
import { register } from "@/utils/api/auth";
|
||||||
|
import useRoutes from "@/hooks/useRoutes";
|
||||||
|
import SectionTitle from "@/components/ui/SectionTitle";
|
||||||
|
import SolidButton from "@/components/ui/Buttons/SolidButton";
|
||||||
|
import { Link, useNavigate } from "react-router"
|
||||||
|
|
||||||
|
const RegisterForm = () => {
|
||||||
|
const routes = useRoutes();
|
||||||
|
const [name, setName] = useState('');
|
||||||
|
const [email, setEmail] = useState('');
|
||||||
|
const [password, setPassword] = useState('');
|
||||||
|
const [passwordAgain, setPasswordAgain] = useState('');
|
||||||
|
const [error, setError] = useState('');
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const [isRegistered, setIsRegistered] = useState(false);
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
if (password !== passwordAgain) {
|
||||||
|
setError("Passwords do not match.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
setIsLoading(true);
|
||||||
|
|
||||||
|
await register(name, email, password, passwordAgain);
|
||||||
|
// navigate('/login?registered=true', { replace: true });
|
||||||
|
} catch (err) {
|
||||||
|
const errorMessage =
|
||||||
|
err instanceof Error
|
||||||
|
? err.message
|
||||||
|
: 'Registration\n failed';
|
||||||
|
setError(errorMessage);
|
||||||
|
} finally {
|
||||||
|
setIsRegistered(true);
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (isRegistered) {
|
||||||
|
return <div className="border-2 border-secondary rounded-lg p-5 mt-0">
|
||||||
|
<SectionTitle>Registration successful!</SectionTitle>
|
||||||
|
Please continue to the <Link to={ routes.auth.login() }>login page</Link>.
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ marginTop: '15vh' }} className="lg:w-1/3 lg:mx-auto">
|
||||||
|
<div className="pt-2 text-2xl font-syncopate text-primary">
|
||||||
|
DISH PLANNER
|
||||||
|
</div>
|
||||||
|
<div className="border-2 border-secondary rounded-lg p-5 mt-0 lg:pt-10 lg:pb-7">
|
||||||
|
<form onSubmit={ handleSubmit } className="max-w-sm mx-auto space-y-4 flex flex-col">
|
||||||
|
<h2 className="text-xl font-bold text-secondary text-right">Register</h2>
|
||||||
|
{ error && <p className="text-red-600">{ error }</p> }
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="Name"
|
||||||
|
value={ name }
|
||||||
|
onChange={ e => setName(e.target.value) }
|
||||||
|
required
|
||||||
|
className="w-full p-2 border rounded border-secondary bg-gray-600 text-secondary"
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="email"
|
||||||
|
placeholder="Email"
|
||||||
|
value={ email }
|
||||||
|
onChange={ e => setEmail(e.target.value) }
|
||||||
|
required
|
||||||
|
className="w-full p-2 border rounded border-secondary bg-gray-600 text-secondary"
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
placeholder="Password"
|
||||||
|
value={ password }
|
||||||
|
onChange={ e => setPassword(e.target.value) }
|
||||||
|
required
|
||||||
|
className="w-full p-2 border rounded border-secondary bg-gray-600 text-secondary"
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
placeholder="Password Again"
|
||||||
|
value={ passwordAgain }
|
||||||
|
onChange={ e => setPasswordAgain(e.target.value) }
|
||||||
|
required
|
||||||
|
className="w-full p-2 border rounded border-secondary bg-gray-600 text-secondary"
|
||||||
|
/>
|
||||||
|
<SolidButton
|
||||||
|
type="submit"
|
||||||
|
className={ isLoading ? "opacity-50 cursor-not-allowed" : "background-red" }
|
||||||
|
>
|
||||||
|
Create Account
|
||||||
|
</SolidButton>
|
||||||
|
<Link to={routes.auth.login()} className="lowercase mt-2 hover:underline text-center text-secondary underline">
|
||||||
|
Back to Login
|
||||||
|
</Link>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default RegisterForm
|
||||||
|
|
@ -0,0 +1,101 @@
|
||||||
|
import React, { useState } from "react";
|
||||||
|
import { DishType } from "@/types/DishType";
|
||||||
|
import { UserType } from "@/types/UserType";
|
||||||
|
import { useFetchUsers } from "@/hooks/useFetchUsers";
|
||||||
|
import Spinner from "@/components/Spinner";
|
||||||
|
import {addUserToDish} from "@/utils/api/dishApi";
|
||||||
|
import OutlineButton from "@/components/ui/Buttons/OutlineButton";
|
||||||
|
import SolidButton from "@/components/ui/Buttons/SolidButton";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
dish: DishType;
|
||||||
|
reloadDish: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const AddUserToDishForm = ({ dish, reloadDish }: Props) => {
|
||||||
|
const [showAdd, setShowAdd] = useState<boolean>(false);
|
||||||
|
const [selectedUser, setSelectedUser] = useState<string>("-1");
|
||||||
|
const { users, isLoading: isUsersLoading } = useFetchUsers();
|
||||||
|
|
||||||
|
const handleSubmit = (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
if (selectedUser === "-1") {
|
||||||
|
alert("Please select a valid user.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const userToAdd = users.find((user: UserType) => user.id === parseInt(selectedUser));
|
||||||
|
|
||||||
|
if (!userToAdd) {
|
||||||
|
alert("User not found.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
addUserToDish(dish.id, userToAdd.id)
|
||||||
|
.then(() => {
|
||||||
|
setShowAdd(false);
|
||||||
|
setSelectedUser("-1");
|
||||||
|
reloadDish();
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
alert("Failed to add user, please try again.");
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
if (isUsersLoading) {
|
||||||
|
return <Spinner />;
|
||||||
|
}
|
||||||
|
|
||||||
|
const remainingUsers = users.filter(
|
||||||
|
(user: UserType) =>
|
||||||
|
!dish.users.find((dishUser: UserType) => dishUser.id === user.id)
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<OutlineButton
|
||||||
|
className="mb-2 flex-none w-fit ml-auto"
|
||||||
|
onClick={() => setShowAdd(!showAdd)}
|
||||||
|
disabled={remainingUsers.length === 0}
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
Add User
|
||||||
|
</OutlineButton>
|
||||||
|
|
||||||
|
{ showAdd && (
|
||||||
|
<div className="mt-2 mb-5 w-full">
|
||||||
|
<form onSubmit={handleSubmit}>
|
||||||
|
<div className="flex">
|
||||||
|
<div className="flex-grow pt-2">
|
||||||
|
<select
|
||||||
|
value={selectedUser}
|
||||||
|
onChange={(e) => setSelectedUser(e.target.value)}
|
||||||
|
className="p-2 border rounded w-full background-secondary border-secondary"
|
||||||
|
>
|
||||||
|
<option value="-1">Select user</option>
|
||||||
|
{remainingUsers.map((user: UserType) => (
|
||||||
|
<option key={user.id} value={user.id}>
|
||||||
|
{user.name}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex-none py-2 pr-2 pl-4">
|
||||||
|
<SolidButton type="submit"
|
||||||
|
size="small"
|
||||||
|
className="mt-1"
|
||||||
|
>
|
||||||
|
Add User
|
||||||
|
</SolidButton>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AddUserToDishForm;
|
||||||
|
|
@ -0,0 +1,95 @@
|
||||||
|
import React, { useState } from "react";
|
||||||
|
import { useNavigate } from "react-router";
|
||||||
|
import { createDish } from "~/utils/api/dishApi";
|
||||||
|
import PageTitle from "~/components/ui/PageTitle";
|
||||||
|
import Alert from "~/components/ui/Alert";
|
||||||
|
import SolidButton from "~/components/ui/Buttons/SolidButton";
|
||||||
|
import OutlineLinkButton from "~/components/ui/Buttons/OutlineLinkButton";
|
||||||
|
import { ChevronLeftIcon } from "@heroicons/react/16/solid";
|
||||||
|
import Hr from "~/components/ui/Hr"
|
||||||
|
|
||||||
|
const CreateDishForm = () => {
|
||||||
|
const navigate = useNavigate()
|
||||||
|
const [name, setName] = useState<string>("");
|
||||||
|
const [error, setError] = useState<string>("");
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
const validateForm = () => {
|
||||||
|
if (!name.trim()) {
|
||||||
|
setError("Dish name cannot be empty.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const submitForm = async (e: React.FormEvent<HTMLFormElement>) => {
|
||||||
|
e.preventDefault()
|
||||||
|
|
||||||
|
// Validate client-side input
|
||||||
|
if (!validateForm()) return;
|
||||||
|
|
||||||
|
setError("");
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await createDish(name);
|
||||||
|
if (result) {
|
||||||
|
navigate('/dishes')
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
setError(error instanceof Error ? error.message : "An unexpected error occurred.");
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="px-5">
|
||||||
|
<div className="flex mb-3">
|
||||||
|
<PageTitle>Create Dish</PageTitle>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form className="space-y-4" onSubmit={ submitForm }>
|
||||||
|
{ error && (
|
||||||
|
<Alert type="error">{ error }</Alert>
|
||||||
|
) }
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label htmlFor="name" className="block text-sm font-medium">Dish Name</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="name"
|
||||||
|
name="name"
|
||||||
|
value={ name }
|
||||||
|
onChange={ (e) => setName(e.target.value) } // Update the name state on change
|
||||||
|
className="w-full p-2 mb-4 border rounded bg-gray-600 border-secondary text-secondary focus:bg-gray-900"
|
||||||
|
placeholder="Enter dish name"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<SolidButton
|
||||||
|
type="submit"
|
||||||
|
disabled={ loading }
|
||||||
|
className={ loading ? "bg-gray-400" : '' }
|
||||||
|
>
|
||||||
|
{ loading ? "Saving..." : "Save Changes" }
|
||||||
|
</SolidButton>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<Hr />
|
||||||
|
|
||||||
|
<OutlineLinkButton
|
||||||
|
href="/dishes"
|
||||||
|
className="mt-4 pl-0 mr-0"
|
||||||
|
icon={ <ChevronLeftIcon/> }
|
||||||
|
>
|
||||||
|
Back to dishes
|
||||||
|
</OutlineLinkButton>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CreateDishForm;
|
||||||
39
frontend-old/app/components/features/dishes/Dish.tsx
Normal file
39
frontend-old/app/components/features/dishes/Dish.tsx
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
import {DishType} from "~/types/DishType";
|
||||||
|
|
||||||
|
import {PencilIcon, TrashIcon} from '@heroicons/react/24/solid'
|
||||||
|
import { Link } from "react-router";
|
||||||
|
import useRoutes from "~/hooks/useRoutes";
|
||||||
|
import {UserType} from "~/types/UserType";
|
||||||
|
import Card from "~/components/layout/Card";
|
||||||
|
|
||||||
|
const Dish = ({ dish }: { dish: DishType}) => {
|
||||||
|
const routes = useRoutes();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card>
|
||||||
|
<div className="flex-1 flex items-center">
|
||||||
|
<p className="text-bold text-xl font-bold">{ dish.name }</p>
|
||||||
|
<span className="mx-2"></span>
|
||||||
|
{
|
||||||
|
dish.users.map((user: UserType) => (
|
||||||
|
<div key={user.id} className="text-accent-yellow mx-1">{user.name.slice(0, 1)}</div>
|
||||||
|
))
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<div className="flex-none flex gap-2">
|
||||||
|
<Link to={routes.dish.edit(dish)}>
|
||||||
|
<div className="border border-foreground p-2 rounded">
|
||||||
|
<PencilIcon width="14" />
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
|
<Link to={routes.dish.delete(dish)}>
|
||||||
|
<div className="border border-red-500 p-2 rounded">
|
||||||
|
<TrashIcon width="14" className="text-red-500" />
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Dish
|
||||||
22
frontend-old/app/components/features/dishes/DishCard.tsx
Normal file
22
frontend-old/app/components/features/dishes/DishCard.tsx
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
import {UserType} from "@/types/UserType";
|
||||||
|
import {DishType} from "@/types/DishType";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
user: UserType,
|
||||||
|
dish: DishType,
|
||||||
|
}
|
||||||
|
|
||||||
|
const DishCard = ({ user, dish }: Props) => {
|
||||||
|
return (
|
||||||
|
<div className="w-full flex py-2 text-xl font-bold text-primary">
|
||||||
|
<div className="user-badge flex-none w-16 text-center pr-5">
|
||||||
|
{ user.name.slice(0, 1) }
|
||||||
|
</div>
|
||||||
|
<div className="dish-name flex-1">
|
||||||
|
{ dish ? dish.name : '-' }
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default DishCard
|
||||||
87
frontend-old/app/components/features/dishes/EditDishForm.tsx
Normal file
87
frontend-old/app/components/features/dishes/EditDishForm.tsx
Normal file
|
|
@ -0,0 +1,87 @@
|
||||||
|
import React, {useState} from "react";
|
||||||
|
import { useNavigate } from "react-router";
|
||||||
|
import Alert from "~/components/ui/Alert";
|
||||||
|
import {updateDish} from "~/utils/api/dishApi";
|
||||||
|
import {DishType} from "~/types/DishType";
|
||||||
|
import useRoutes from "~/hooks/useRoutes";
|
||||||
|
import Spinner from "~/components/Spinner";
|
||||||
|
import Button from "~/components/ui/Button"
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
dish: DishType
|
||||||
|
}
|
||||||
|
|
||||||
|
const EditDishForm = ({ dish }: Props) => {
|
||||||
|
const [name, setName] = useState<string>(dish.name);
|
||||||
|
const [error, setError] = useState<string>("");
|
||||||
|
const navigate = useNavigate()
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const routes = useRoutes();
|
||||||
|
|
||||||
|
const validateForm = () => {
|
||||||
|
if (!name.trim()) {
|
||||||
|
setError("Dish name cannot be empty.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const submitForm = async (e: React.FormEvent<HTMLFormElement>) => {
|
||||||
|
e.preventDefault()
|
||||||
|
|
||||||
|
if (!validateForm()) return;
|
||||||
|
|
||||||
|
setError("");
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await updateDish(dish.id, name);
|
||||||
|
if (result) {
|
||||||
|
navigate(routes.dish.index())
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
setError(error instanceof Error ? error.message : "An unexpected error occurred");
|
||||||
|
} finally {
|
||||||
|
setLoading(false); // Reset loading state
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (loading) {
|
||||||
|
return <Spinner />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form className="space-y-4" onSubmit={submitForm}>
|
||||||
|
{
|
||||||
|
error != '' && <Alert type="error" >{ error }</Alert>
|
||||||
|
}
|
||||||
|
|
||||||
|
{/* Dish name input */}
|
||||||
|
<div>
|
||||||
|
<label htmlFor="name" className="block text-sm font-medium">Dish Name</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="name"
|
||||||
|
name="name"
|
||||||
|
value={name}
|
||||||
|
onChange={(e) => setName(e.target.value)} // Update the name state on change
|
||||||
|
className="p-2 border rounded w-full bg-gray-500 border-secondary background-secondary"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Save button */}
|
||||||
|
<Button
|
||||||
|
type="submit"
|
||||||
|
disabled={loading}
|
||||||
|
className={loading ? "bg-gray-400" : ''}
|
||||||
|
variant="primary"
|
||||||
|
appearance="solid"
|
||||||
|
>
|
||||||
|
{loading ? "Saving..." : "Save"}
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default EditDishForm;
|
||||||
|
|
@ -0,0 +1,119 @@
|
||||||
|
import React from "react";
|
||||||
|
import SectionTitle from "@/components/ui/SectionTitle";
|
||||||
|
import {syncUserDishRecurrences} from "@/utils/api/usersApi";
|
||||||
|
import Spinner from "@/components/Spinner";
|
||||||
|
import {UserDishType} from "@/types/ScheduledUserDishType";
|
||||||
|
import {RecurrenceType} from "@/types/RecurrenceType";
|
||||||
|
import SolidButton from "@/components/ui/Buttons/SolidButton";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
userDish: UserDishType
|
||||||
|
onSubmit: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
const EditDishUserCardEditForm = ({ userDish, onSubmit}: Props) => {
|
||||||
|
const weeklyRecurrence = userDish.recurrences.find((recurrence) => recurrence.type === 'App\\Models\\WeeklyRecurrence')
|
||||||
|
const minimumRecurrence = userDish.recurrences.find((recurrence) => recurrence.type === 'App\\Models\\MinimumRecurrence')
|
||||||
|
|
||||||
|
const wv = weeklyRecurrence ? weeklyRecurrence.value : undefined
|
||||||
|
const mv = minimumRecurrence ? minimumRecurrence.value : undefined
|
||||||
|
|
||||||
|
const [isWeeklyOn, setIsWeeklyOn] = React.useState(weeklyRecurrence !== undefined);
|
||||||
|
const [isMinimumOn, setIsMinimumOn] = React.useState(minimumRecurrence !== undefined);
|
||||||
|
const [weekday, setWeekday] = React.useState<number>(wv ?? 0);
|
||||||
|
const [minimumValue, setMinimumValue] = React.useState<number>(mv ?? 7);
|
||||||
|
const [loading, setLoading] = React.useState(false);
|
||||||
|
|
||||||
|
const handleSubmit = () => {
|
||||||
|
const recurrences = []
|
||||||
|
|
||||||
|
if (isWeeklyOn) {
|
||||||
|
recurrences.push({
|
||||||
|
type: 'App\\Models\\WeeklyRecurrence',
|
||||||
|
value: weekday,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isMinimumOn) {
|
||||||
|
recurrences.push({
|
||||||
|
type: 'App\\Models\\MinimumRecurrence',
|
||||||
|
value: minimumValue,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setLoading(true)
|
||||||
|
syncUserDishRecurrences(userDish.dish.id, userDish.user.id, recurrences as RecurrenceType[])
|
||||||
|
.then((data) => console.log('request data', data))
|
||||||
|
.finally(() => {
|
||||||
|
setLoading(false)
|
||||||
|
onSubmit()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (loading) {
|
||||||
|
return <Spinner />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form action={handleSubmit}>
|
||||||
|
<SectionTitle>Recurrences</SectionTitle>
|
||||||
|
|
||||||
|
<div className="flex">
|
||||||
|
<div className="flex-none">
|
||||||
|
<input type="checkbox"
|
||||||
|
id="weekly"
|
||||||
|
name="weekly"
|
||||||
|
value="weekly"
|
||||||
|
checked={isWeeklyOn}
|
||||||
|
onChange={() => setIsWeeklyOn(!isWeeklyOn)}
|
||||||
|
className="w-4 h-4 border border-gray-300 rounded-sm bg-gray-50 focus:ring-3 focus:ring-blue-300 dark:bg-gray-700 dark:border-gray-600 dark:focus:ring-blue-600 dark:ring-offset-gray-800 dark:focus:ring-offset-gray-800"
|
||||||
|
/>
|
||||||
|
<label htmlFor="weekly" className="ml-2">Weekly</label>
|
||||||
|
</div>
|
||||||
|
{
|
||||||
|
isWeeklyOn && (
|
||||||
|
<div className="flex-grow ml-2">
|
||||||
|
<label htmlFor="weekday" className="mr-2">on</label>
|
||||||
|
<select value={weekday} onChange={(e) => setWeekday(parseInt(e.currentTarget.value))} className="background-secondary border-secondary border-2">
|
||||||
|
<option value="0">Sunday</option>
|
||||||
|
<option value="1">Monday</option>
|
||||||
|
<option value="2">Tuesday</option>
|
||||||
|
<option value="3">Wednesday</option>
|
||||||
|
<option value="4">Thursday</option>
|
||||||
|
<option value="5">Friday</option>
|
||||||
|
<option value="6">Saturday</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex mt-2">
|
||||||
|
<div className="flex-none">
|
||||||
|
<input type="checkbox"
|
||||||
|
id="minimum"
|
||||||
|
name="minimum"
|
||||||
|
value="minimum"
|
||||||
|
checked={isMinimumOn}
|
||||||
|
onChange={() => setIsMinimumOn(!isMinimumOn)}
|
||||||
|
className="w-4 h-4 border border-gray-300 rounded-sm bg-gray-500 focus:ring-3 focus:ring-blue-300 dark:bg-gray-700 dark:border-gray-600 dark:focus:ring-blue-600 dark:ring-offset-gray-800 dark:focus:ring-offset-gray-800"
|
||||||
|
/>
|
||||||
|
<label htmlFor="minimum" className="ml-2">Minimum</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{
|
||||||
|
isMinimumOn && (
|
||||||
|
<div className="flex-grow ml-2">
|
||||||
|
<input type="number" value={minimumValue} onChange={(e) => setMinimumValue(parseInt(e.currentTarget.value))} min="0" max="365" className="background-secondary border-secondary border-2 w-12 px-2" />
|
||||||
|
<label htmlFor="minimum">Days</label>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<SolidButton type="submit">Save</SolidButton>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default EditDishUserCardEditForm;
|
||||||
|
|
@ -0,0 +1,53 @@
|
||||||
|
import {RecurrenceType} from "@/types/RecurrenceType";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
recurrences: RecurrenceType[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const RecurrenceLabels = ({recurrences}: Props) => {
|
||||||
|
const weeklyRecurrences = recurrences.filter(recurrence => recurrence.type === 'App\\Models\\WeeklyRecurrence');
|
||||||
|
const minimumRecurrences = recurrences.filter(recurrence => recurrence.type === 'App\\Models\\MinimumRecurrence');
|
||||||
|
|
||||||
|
const renderWeeklyRecurrence = () => {
|
||||||
|
if (weeklyRecurrences == undefined || weeklyRecurrences.length == 0) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
const weekdayString = (() => {
|
||||||
|
switch (weeklyRecurrences[0].value) {
|
||||||
|
case 0: return "Sunday"
|
||||||
|
case 1: return "Monday"
|
||||||
|
case 2: return "Tuesday";
|
||||||
|
case 3: return "Wednesday";
|
||||||
|
case 4: return "Thursday";
|
||||||
|
case 5: return "Friday";
|
||||||
|
case 6: return "Saturday";
|
||||||
|
default: return "Invalid day";
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="text-xs p-1 inline mx-1 text-accent-yellow">
|
||||||
|
{ weekdayString() }
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
const renderMinimumRecurrence = () => {
|
||||||
|
if (minimumRecurrences == undefined || minimumRecurrences.length == 0) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="text-xs p-1 inline mx-1 text-accent-yellow">
|
||||||
|
min: { minimumRecurrences[0].value }
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return <>
|
||||||
|
{ renderWeeklyRecurrence() }
|
||||||
|
{ renderMinimumRecurrence() }
|
||||||
|
</>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default RecurrenceLabels;
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
import React from "react";
|
||||||
|
import { DishType } from "@/types/DishType";
|
||||||
|
import { UserType } from "@/types/UserType";
|
||||||
|
import UserDishCard from "@/components/features/dishes/UserDishCard";
|
||||||
|
import SectionTitle from "@/components/ui/SectionTitle";
|
||||||
|
import AddUserToDishForm from "@/components/features/dishes/AddUserToDishForm";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
dish: DishType;
|
||||||
|
reloadDish: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SyncUsersForm = ({ dish, reloadDish }: Props) => {
|
||||||
|
return (
|
||||||
|
<div className="my-2 w-full flex flex-col">
|
||||||
|
<SectionTitle className="mt-2">Users</SectionTitle>
|
||||||
|
|
||||||
|
<AddUserToDishForm dish={dish} reloadDish={reloadDish} />
|
||||||
|
|
||||||
|
{dish.users.map((user: UserType) => (
|
||||||
|
<UserDishCard
|
||||||
|
key={user.id}
|
||||||
|
user={user}
|
||||||
|
dish={dish}
|
||||||
|
reloadDish={reloadDish}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SyncUsersForm;
|
||||||
83
frontend-old/app/components/features/dishes/UserDishCard.tsx
Normal file
83
frontend-old/app/components/features/dishes/UserDishCard.tsx
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
import React, {useEffect} from "react";
|
||||||
|
import {DishType} from "~/types/DishType";
|
||||||
|
import {UserType} from "~/types/UserType";
|
||||||
|
import { Link } from "react-router";
|
||||||
|
import {PencilIcon, TrashIcon} from "@heroicons/react/24/solid";
|
||||||
|
import {removeUserFromDish} from "~/utils/api/dishApi";
|
||||||
|
import EditDishUserCardEditForm from "~/components/features/dishes/EditDishUserCardEditForm";
|
||||||
|
import {getUserDishForUserAndDish} from "~/utils/api/usersApi";
|
||||||
|
import Spinner from "~/components/Spinner";
|
||||||
|
import RecurrenceLabels from "~/components/features/dishes/RecurrenceLabels";
|
||||||
|
import {UserDishType} from "~/types/ScheduledUserDishType";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
dish: DishType
|
||||||
|
user: UserType
|
||||||
|
reloadDish: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
const UserDishCard = ({dish, user, reloadDish}: Props) => {
|
||||||
|
const [userDish, setUserDish] = React.useState<UserDishType|null>(null);
|
||||||
|
const [userDishLoading, setUserDishLoading] = React.useState(true);
|
||||||
|
const [isEditMode, setIsEditMode] = React.useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
getUserDishForUserAndDish(user.id, dish.id)
|
||||||
|
.then((userDish) => setUserDish(userDish))
|
||||||
|
.finally(() => setUserDishLoading(false))
|
||||||
|
}, [dish, user]);
|
||||||
|
|
||||||
|
const handleRemove = () => {
|
||||||
|
removeUserFromDish(dish.id, user.id)
|
||||||
|
.then(() => reloadDish())
|
||||||
|
.catch(() => {
|
||||||
|
alert("Failed to remove user, please try again.");
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
if (userDishLoading || !userDish) {
|
||||||
|
return <Spinner />
|
||||||
|
}
|
||||||
|
|
||||||
|
const onUserCardSubmit = () => {
|
||||||
|
setIsEditMode(false);
|
||||||
|
reloadDish()
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="my-2 w-full px-3 py-2 text-xl font-bold border border-secondary rounded">
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<div className="flex-none pt-1">
|
||||||
|
{user.name}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex-grow pt-1">
|
||||||
|
<RecurrenceLabels recurrences={userDish.recurrences} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex-none w-8">
|
||||||
|
<Link onClick={() => setIsEditMode(!isEditMode)} to="#">
|
||||||
|
<div className="border border-foreground p-2 rounded">
|
||||||
|
<PencilIcon width="14"/>
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
<div className="flex-none w-8">
|
||||||
|
<Link onClick={handleRemove} to="#">
|
||||||
|
<div className="border border-red-500 p-2 rounded">
|
||||||
|
<TrashIcon width="14" className="text-red-500"/>
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{isEditMode && (
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<EditDishUserCardEditForm userDish={userDish} onSubmit={onUserCardSubmit} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default UserDishCard;
|
||||||
|
|
@ -0,0 +1,69 @@
|
||||||
|
import { Link } from "react-router";
|
||||||
|
import React from "react";
|
||||||
|
import useRoutes from "~/hooks/useRoutes";
|
||||||
|
import classNames from "classnames";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
isOpen: boolean;
|
||||||
|
setIsOpen: (isOpen: boolean) => void;
|
||||||
|
handleLogout: (e: React.MouseEvent) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const divStyles = classNames(
|
||||||
|
'absolute', 'text-xxl', 'rounded-b', 'top-full mt-1', 'left-0', 'right-0', '', 'py-2',
|
||||||
|
'bg-gray-600', 'border-secondary', 'shadow-md', 'flex', 'flex-col', 'space-y-3',
|
||||||
|
'md:hidden'
|
||||||
|
)
|
||||||
|
|
||||||
|
const linkStyles = classNames(
|
||||||
|
'border-b-2', 'border-secondary', 'uppercase',
|
||||||
|
'text-primary', 'hover:background-secondary', 'pb-2', 'pl-5',
|
||||||
|
'space-grotesk', 'text-xl'
|
||||||
|
)
|
||||||
|
|
||||||
|
const MobileDropdownMenu = ({ isOpen, setIsOpen, handleLogout }: Props) => {
|
||||||
|
const routes = useRoutes();
|
||||||
|
|
||||||
|
if (!isOpen) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={divStyles}>
|
||||||
|
<Link
|
||||||
|
to={routes.home()}
|
||||||
|
className={linkStyles}
|
||||||
|
onClick={() => setIsOpen(false)}
|
||||||
|
>
|
||||||
|
Home
|
||||||
|
</Link>
|
||||||
|
<Link
|
||||||
|
to={routes.dish.index()}
|
||||||
|
className={linkStyles}
|
||||||
|
onClick={() => setIsOpen(false)}
|
||||||
|
>
|
||||||
|
Dishes
|
||||||
|
</Link>
|
||||||
|
<Link
|
||||||
|
to={routes.user.index()}
|
||||||
|
className={linkStyles}
|
||||||
|
onClick={() => setIsOpen(false)}
|
||||||
|
>
|
||||||
|
Users
|
||||||
|
</Link>
|
||||||
|
<Link
|
||||||
|
to={routes.schedule.history()}
|
||||||
|
className={linkStyles}
|
||||||
|
onClick={() => setIsOpen(false)}
|
||||||
|
>
|
||||||
|
History
|
||||||
|
</Link>
|
||||||
|
<Link
|
||||||
|
to={routes.auth.login()}
|
||||||
|
onClick={handleLogout}
|
||||||
|
className={linkStyles}>
|
||||||
|
Logout
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default MobileDropdownMenu
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
"use client"
|
||||||
|
|
||||||
|
import {useEffect, useState} from "react";
|
||||||
|
import {DateTime} from "luxon";
|
||||||
|
import ScheduleCalendar from "@/components/features/schedule/ScheduleCalendar";
|
||||||
|
import PageTitle from "@/components/ui/PageTitle";
|
||||||
|
import {ScheduleType} from "@/types/ScheduleType";
|
||||||
|
import Spinner from "@/components/Spinner";
|
||||||
|
import {listSchedule} from "@/utils/api/scheduleApi";
|
||||||
|
|
||||||
|
const HistoricalDishes = () => {
|
||||||
|
const [schedule, setSchedule] = useState<ScheduleType[]>([]);
|
||||||
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
|
||||||
|
const yesterday = DateTime.now().minus({ days: 1 }).toFormat('yyyy-LL-dd');
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
listSchedule(undefined, yesterday)
|
||||||
|
.then((dishes: ScheduleType[]) => dishes
|
||||||
|
.sort((a: ScheduleType, b: ScheduleType) => new Date(b.date).getTime() - new Date(a.date).getTime())
|
||||||
|
)
|
||||||
|
.then((dishes) => setSchedule(dishes))
|
||||||
|
.finally(() => setIsLoading(false))
|
||||||
|
}, [yesterday]);
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return <Spinner />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!schedule || Object.keys(schedule).length === 0) {
|
||||||
|
return (
|
||||||
|
<div className="w-full text-center text-2xl border-white border-2 rounded-xl mt-4">
|
||||||
|
No dishes scheduled
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return <div className="justify-items-center">
|
||||||
|
<PageTitle>History</PageTitle>
|
||||||
|
<ScheduleCalendar schedule={schedule as ScheduleType[]} />
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
export default HistoricalDishes
|
||||||
|
|
@ -0,0 +1,72 @@
|
||||||
|
import ScheduleDayCard from "@/components/features/schedule/dayCard/ScheduleDayCard";
|
||||||
|
import { FilledScheduleType, ScheduleType } from "@/types/ScheduleType";
|
||||||
|
import {useFetchUsers} from "@/hooks/useFetchUsers";
|
||||||
|
import Spinner from "@/components/Spinner";
|
||||||
|
|
||||||
|
const generateDates = (startDate: string, days: number): string[] => {
|
||||||
|
const dates = [];
|
||||||
|
const start = new Date(startDate);
|
||||||
|
|
||||||
|
for (let i = 0; i < days; i++) {
|
||||||
|
const currentDate = new Date(start);
|
||||||
|
currentDate.setDate(start.getDate() + i);
|
||||||
|
dates.push(currentDate.toISOString().split('T')[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return dates;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const fillCalendar = (schedules: ScheduleType[]): FilledScheduleType[] => {
|
||||||
|
/*
|
||||||
|
Array(14)
|
||||||
|
0:
|
||||||
|
date: "2025-05-05"
|
||||||
|
id: 2
|
||||||
|
is_skipped: false
|
||||||
|
scheduled_user_dishes: []
|
||||||
|
*/
|
||||||
|
|
||||||
|
const dates = generateDates((new Date()).toISOString().split('T')[0], 31)
|
||||||
|
|
||||||
|
return dates.map((date): FilledScheduleType => {
|
||||||
|
console.log(date)
|
||||||
|
|
||||||
|
const schedule = schedules.find((schedule: ScheduleType) => schedule.date == date)
|
||||||
|
|
||||||
|
if (schedule) {
|
||||||
|
return schedule
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
date,
|
||||||
|
scheduled_user_dishes: []
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
schedule: ScheduleType[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const ScheduleCalendar = ({ schedule }: Props) => {
|
||||||
|
const {users, isLoading: areUsersLoading} = useFetchUsers();
|
||||||
|
|
||||||
|
if (areUsersLoading) return <Spinner />
|
||||||
|
|
||||||
|
const fullCalendar = fillCalendar(schedule)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="w-full flex flex-col items-start">
|
||||||
|
{ fullCalendar.map((schedule, index) => (
|
||||||
|
<ScheduleDayCard
|
||||||
|
key={index}
|
||||||
|
schedule={schedule}
|
||||||
|
users={users}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ScheduleCalendar
|
||||||
|
|
@ -0,0 +1,142 @@
|
||||||
|
"use client";
|
||||||
|
|
||||||
|
import React, { useEffect, useState } from "react";
|
||||||
|
import { ScheduleType } from "@/types/ScheduleType";
|
||||||
|
import Spinner from "@/components/Spinner";
|
||||||
|
import PageTitle from "@/components/ui/PageTitle";
|
||||||
|
import { getScheduleForDate, scheduleUserDish, updateScheduleForDate } from "@/utils/api/scheduleApi";
|
||||||
|
import { UserDishType } from "@/types/ScheduledUserDishType";
|
||||||
|
import Label from "@/components/ui/Label";
|
||||||
|
import SectionTitle from "@/components/ui/SectionTitle";
|
||||||
|
import { useFetchUsers } from "@/hooks/useFetchUsers";
|
||||||
|
import { listUserDishes } from "@/utils/api/userDishApi";
|
||||||
|
import scheduleBuilder from "@/utils/scheduleBuilder";
|
||||||
|
import transformDate from "@/utils/dateBuilder";
|
||||||
|
import { ChevronLeftIcon } from "@heroicons/react/16/solid";
|
||||||
|
import Hr from "@/components/ui/Hr"
|
||||||
|
import Button from "@/components/ui/Button"
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
date: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ScheduleEditForm = ({ date }: Props) => {
|
||||||
|
const [schedule, setSchedule] = useState<ScheduleType>()
|
||||||
|
const [userDishes, setUserDishes] = useState<UserDishType[]>([])
|
||||||
|
const [isScheduleLoading, setIsScheduleLoading] = useState(true);
|
||||||
|
const [areUserDishesLoading, setAreUserDishesLoading] = useState(true);
|
||||||
|
const { users } = useFetchUsers();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
getScheduleForDate(date)
|
||||||
|
.then((sched: ScheduleType) => setSchedule(sched))
|
||||||
|
.finally(() => setIsScheduleLoading(false))
|
||||||
|
}, [date]);
|
||||||
|
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
listUserDishes()
|
||||||
|
.then((user_dishes: UserDishType[]) => setUserDishes(user_dishes))
|
||||||
|
.finally(() => setAreUserDishesLoading(false))
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleSkipDay = () => {
|
||||||
|
updateScheduleForDate(date, true)
|
||||||
|
.then((schedule: ScheduleType) => {
|
||||||
|
setSchedule(schedule)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleUnskipDay = () => {
|
||||||
|
updateScheduleForDate(date, false)
|
||||||
|
.then((schedule: ScheduleType) => {
|
||||||
|
setSchedule(schedule)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleChange = (e: React.ChangeEvent<HTMLSelectElement>, userId: number) => {
|
||||||
|
const userDishId = parseInt(e.currentTarget.value);
|
||||||
|
|
||||||
|
if (userDishId === 0) {
|
||||||
|
scheduleUserDish(date, userId, null, true).then(() => window.location.reload());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
scheduleUserDish(date, userId, userDishId).then(() => window.location.reload());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isScheduleLoading || areUserDishesLoading || !schedule) {
|
||||||
|
return <Spinner/>
|
||||||
|
}
|
||||||
|
|
||||||
|
const scheduleData = scheduleBuilder(schedule, users, userDishes)
|
||||||
|
|
||||||
|
return <div>
|
||||||
|
<div className="flex">
|
||||||
|
<div className="flex-none">
|
||||||
|
<PageTitle>Edit Day</PageTitle>
|
||||||
|
</div>
|
||||||
|
<div className="flex-grow">
|
||||||
|
<SectionTitle className="text-right font-size-24 capitalize font-default">{ transformDate(schedule.date) }</SectionTitle>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Hr className="mb-8" />
|
||||||
|
|
||||||
|
{
|
||||||
|
userDishes.length === 0 && <div className="my-2">
|
||||||
|
<div className="text-center w-full text-xl">No dishes found assigned to this user.</div>
|
||||||
|
<div className="text-center w-full mt-2">Go ahead and add some first, or choose to skip the day.</div>
|
||||||
|
<div className="text-center w-full">(dishes ={`>`} edit ={`>`} add user)</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
{ schedule.is_skipped
|
||||||
|
? <Label>Skipped</Label>
|
||||||
|
: (
|
||||||
|
<>
|
||||||
|
{
|
||||||
|
scheduleData
|
||||||
|
.map((scheduleData) => <div className="flex w-full py-2" key={ scheduleData.user.id }>
|
||||||
|
<div className="flex-none px-2 font-size-18 pt-2">{ scheduleData.user.name }</div>
|
||||||
|
<div className="flex-grow px-2">
|
||||||
|
<select
|
||||||
|
className="w-full bg-gray-500 border-2 border-secondary p-2 rounded"
|
||||||
|
onChange={ (e) => handleChange(e, scheduleData.user.id) }
|
||||||
|
defaultValue={ scheduleData.scheduled_user_dish?.id || 0 }
|
||||||
|
>
|
||||||
|
<option value="0">Skip day</option>
|
||||||
|
{
|
||||||
|
userDishes.map((userDish: UserDishType) => <option
|
||||||
|
key={ userDish.id }
|
||||||
|
value={ userDish.id }
|
||||||
|
>
|
||||||
|
{ userDish.dish.name }
|
||||||
|
</option>)
|
||||||
|
}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>)
|
||||||
|
}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
<div className="text-right w-full text-accent-yellow pr-3">Changes are saved automatically</div>
|
||||||
|
|
||||||
|
<Hr className="mt-8" />
|
||||||
|
|
||||||
|
<div className="pt-3 flex gap-4">
|
||||||
|
<Button variant="secondary" appearance="outline" className="flex-grow" href="/" icon={<ChevronLeftIcon />}>
|
||||||
|
Back to schedule
|
||||||
|
</Button>
|
||||||
|
<div className="flex-none w-1/3">{
|
||||||
|
schedule.is_skipped
|
||||||
|
? <Button onClick={ handleUnskipDay } variant="accent" appearance="outline" type="button">Unskip Day</Button>
|
||||||
|
: <Button onClick={ handleSkipDay } variant="accent" appearance="outline" type="button" className="w-full">Skip Day</Button>
|
||||||
|
}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ScheduleEditForm
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
import { useState} from "react";
|
||||||
|
import Modal from "@/components/ui/Modal";
|
||||||
|
import ScheduleRegenerateForm from "@/components/features/schedule/ScheduleRegenerateForm";
|
||||||
|
import {ArrowPathIcon} from "@heroicons/react/16/solid";
|
||||||
|
|
||||||
|
interface ScheduleRegenerateButtonProps {
|
||||||
|
onModalClose?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ScheduleRegenerateButton = ({ onModalClose }: ScheduleRegenerateButtonProps) => {
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
|
||||||
|
const handleCloseModal = () => {
|
||||||
|
setOpen(false)
|
||||||
|
if (onModalClose) {
|
||||||
|
onModalClose()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const modalChildren = <ScheduleRegenerateForm closeModal={() => handleCloseModal()}/>
|
||||||
|
const buttonChild = <div className="p-0 flex">
|
||||||
|
<ArrowPathIcon fontSize={24} className="h-5 w-5 mt-1 mr-2" color="gray-500" aria-hidden="true" onClick={() => setOpen(true)} />
|
||||||
|
<p>Regenerate</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
return <Modal
|
||||||
|
buttonClassName="ml-auto mr-2 py-1"
|
||||||
|
buttonChildren={buttonChild}
|
||||||
|
modalChildren={modalChildren}
|
||||||
|
modalOpen={open}
|
||||||
|
setModalOpen={setOpen}
|
||||||
|
/>
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ScheduleRegenerateButton;
|
||||||
|
|
@ -0,0 +1,78 @@
|
||||||
|
import {DialogTitle} from "@headlessui/react";
|
||||||
|
import Toggle from "@/components/ui/Toggle";
|
||||||
|
import {useEffect, useState} from "react";
|
||||||
|
import {generateSchedule} from "@/utils/api/scheduleApi";
|
||||||
|
import Alert from "@/components/ui/Alert";
|
||||||
|
import SolidButton from "@/components/ui/Buttons/SolidButton";
|
||||||
|
|
||||||
|
interface ScheduleRegenerateFormProps {
|
||||||
|
closeModal: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ScheduleRegenerateForm = ({closeModal}: ScheduleRegenerateFormProps) => {
|
||||||
|
const [overwrite, setOverwrite] = useState(false);
|
||||||
|
const [error, setError] = useState("");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
}, [overwrite]);
|
||||||
|
|
||||||
|
const close = () => {
|
||||||
|
closeModal();
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleToggle = () => {
|
||||||
|
setOverwrite(!overwrite)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSubmit = () => {
|
||||||
|
generateSchedule(overwrite)
|
||||||
|
.then(() => close())
|
||||||
|
.catch((err) => setError(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
return <>
|
||||||
|
<div className="bg-gray-500 px-4 pt-5 pb-4 sm:p-6 sm:pb-4">
|
||||||
|
<div className="sm:flex sm:items-start w-full">
|
||||||
|
<div className="mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left ">
|
||||||
|
<DialogTitle as="h3" className="text-base font-semibold text-accent-blue">
|
||||||
|
Regenerate Schedule
|
||||||
|
</DialogTitle>
|
||||||
|
<div className="mt-5">
|
||||||
|
<div className="flex">
|
||||||
|
{
|
||||||
|
error && <Alert type="error">{ error }</Alert>
|
||||||
|
}
|
||||||
|
<div className="flex-1/2 pr-5">
|
||||||
|
<label htmlFor="overwrite" className="text-accent-blue">Overwrite current schedule</label>
|
||||||
|
</div>
|
||||||
|
<div className="flex-1/2">
|
||||||
|
<Toggle onChange={handleToggle} checked={overwrite} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="bg-gray-500 px-4 py-3 sm:flex sm:flex-row-reverse sm:px-6">
|
||||||
|
<SolidButton
|
||||||
|
type="button"
|
||||||
|
onClick={() => handleSubmit()}
|
||||||
|
className="inline-flex w-full justify-center rounded-md px-3 py-2 text-sm font-semibold shadow-xs sm:ml-3 sm:w-auto"
|
||||||
|
>
|
||||||
|
Regenerate
|
||||||
|
</SolidButton>
|
||||||
|
<SolidButton
|
||||||
|
type="button"
|
||||||
|
data-autofocus
|
||||||
|
onClick={() => close()}
|
||||||
|
className="mt-3 inline-flex w-full justify-center rounded-md bg-gray-500 px-3 py-2 text-sm font-semibold text-gray-900 ring-1 shadow-xs border-secondary ring-inset sm:mt-0 sm:w-auto"
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</SolidButton>
|
||||||
|
</div>
|
||||||
|
</>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ScheduleRegenerateForm;
|
||||||
|
|
@ -0,0 +1,60 @@
|
||||||
|
import { useCallback, useEffect, useState } from "react";
|
||||||
|
import { DateTime } from "luxon";
|
||||||
|
import ScheduleCalendar from "@/components/features/schedule/ScheduleCalendar";
|
||||||
|
import PageTitle from "@/components/ui/PageTitle";
|
||||||
|
import Spinner from "@/components/Spinner";
|
||||||
|
import { ScheduleType } from "@/types/ScheduleType";
|
||||||
|
import { listSchedule } from "@/utils/api/scheduleApi";
|
||||||
|
import OnboardingBanner from "@/components/features/OnboardingBanner"
|
||||||
|
import { useFetchUsers } from "@/hooks/useFetchUsers"
|
||||||
|
import { useFetchDishes } from "@/hooks/useFetchDishes"
|
||||||
|
import ScheduleRegenerateButton from "@/components/features/schedule/ScheduleRegenerateButton";
|
||||||
|
|
||||||
|
const UpcomingDishes = () => {
|
||||||
|
const [schedule, setSchedule] = useState<ScheduleType[]>([]);
|
||||||
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
|
||||||
|
const today = DateTime.now().toFormat("yyyy-LL-dd");
|
||||||
|
|
||||||
|
const fetchSchedule = useCallback(() => {
|
||||||
|
setIsLoading(true);
|
||||||
|
listSchedule(today)
|
||||||
|
.then((dishes) => setSchedule(dishes))
|
||||||
|
.finally(() => setIsLoading(false));
|
||||||
|
}, [today]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchSchedule();
|
||||||
|
}, [fetchSchedule]);
|
||||||
|
|
||||||
|
const { users, isLoading: areUsersLoading } = useFetchUsers();
|
||||||
|
const { dishes, isLoading: areDishesLoading } = useFetchDishes();
|
||||||
|
|
||||||
|
if (isLoading || areUsersLoading || areDishesLoading) {
|
||||||
|
return <Spinner />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (users.length === 0 || dishes.length === 0) {
|
||||||
|
return <OnboardingBanner dishes={dishes} users={users} />
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="justify-items-center">
|
||||||
|
<div className="flex w-full py-2">
|
||||||
|
<div className="flex-none w-1/2 text-left pt-1">
|
||||||
|
<PageTitle>Schedule</PageTitle>
|
||||||
|
</div>
|
||||||
|
<div className="flex-none w-1/2 text-right">
|
||||||
|
<ScheduleRegenerateButton onModalClose={fetchSchedule} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{
|
||||||
|
!schedule || Object.keys(schedule).length === 0
|
||||||
|
? <div className="w-full text-center text-2xl border-white border-2 rounded-xl mt-4">No dishes scheduled</div>
|
||||||
|
: <ScheduleCalendar schedule={schedule as ScheduleType[]} />
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default UpcomingDishes;
|
||||||
|
|
@ -0,0 +1,79 @@
|
||||||
|
import {FormEvent, useMemo, useState} from "react";
|
||||||
|
import {DishType} from "@/types/DishType";
|
||||||
|
import {ScheduledUserDishType} from "@/types/ScheduledUserDishType";
|
||||||
|
import {updateScheduledUserDish} from "@/utils/api/scheduledUserDishesApi";
|
||||||
|
import Alert from "@/components/ui/Alert";
|
||||||
|
import classNames from "classnames";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
scheduledUserDish: ScheduledUserDishType
|
||||||
|
allDishes: DishType[]
|
||||||
|
}
|
||||||
|
|
||||||
|
const UserDishEditCard = ({ scheduledUserDish, allDishes }: Props) => {
|
||||||
|
const [selectedUserDishId, setSelectedUserDishId] = useState<number>(scheduledUserDish.user_dish ? scheduledUserDish.user_dish.id : 0)
|
||||||
|
const [errorMessage, setErrorMessage] = useState<string>("")
|
||||||
|
const [isSuccess, setIsSuccess] = useState(false);
|
||||||
|
|
||||||
|
const selectStyle = classNames(
|
||||||
|
'p-2', 'rounded', 'w-full', 'background-secondary',
|
||||||
|
'focus:outline-none',
|
||||||
|
'transition-[border-color] ease-out duration-1000', 'border-2', // Keep consistent base styles
|
||||||
|
{
|
||||||
|
'border-green-500': isSuccess, // Green border when successful
|
||||||
|
'border-red-500': !isSuccess && errorMessage !== "", // Red border when there's an error
|
||||||
|
'border-secondary': !isSuccess && errorMessage === "", // Default border for neutral state
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
const handleOnChange = (e: FormEvent<HTMLSelectElement>) => {
|
||||||
|
const userDishId = parseInt(e.currentTarget.value);
|
||||||
|
setSelectedUserDishId(userDishId);
|
||||||
|
|
||||||
|
updateScheduledUserDish(scheduledUserDish.id, userDishId)
|
||||||
|
.then(() => {
|
||||||
|
setIsSuccess(false);
|
||||||
|
setTimeout(() => {
|
||||||
|
setIsSuccess(true);
|
||||||
|
setTimeout(() => setIsSuccess(false), 1000);
|
||||||
|
}, 0);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
setErrorMessage(error); // Log API errors
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const filteredDishes = useMemo(() =>
|
||||||
|
allDishes.filter((dish: DishType) =>
|
||||||
|
dish.users.some((user) => user.id === scheduledUserDish.user_dish.user.id)
|
||||||
|
),
|
||||||
|
[allDishes, scheduledUserDish.user_dish.user.id]
|
||||||
|
)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="m-5 mb-10">
|
||||||
|
<div className="text-2xl">{scheduledUserDish.user_dish.user.name}</div>
|
||||||
|
|
||||||
|
{ errorMessage !== "" && <Alert type="error">{ errorMessage }</Alert> }
|
||||||
|
|
||||||
|
<label htmlFor="name" className="block text-sm font-medium mt-2">Dish</label>
|
||||||
|
<select
|
||||||
|
value={selectedUserDishId}
|
||||||
|
onChange={(e) => handleOnChange(e)}
|
||||||
|
className={selectStyle}
|
||||||
|
>
|
||||||
|
<option key={0} value={0}>Skip Dish</option>
|
||||||
|
{
|
||||||
|
filteredDishes
|
||||||
|
.map((dish: DishType) =>
|
||||||
|
<option key={dish.id} value={dish.id}>
|
||||||
|
{dish.name}
|
||||||
|
</option>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default UserDishEditCard;
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
import {DateTime} from "luxon";
|
||||||
|
import React from "react";
|
||||||
|
import classNames from "classnames";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
date: string
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const DateBadge = ({ className, date }: Props) => {
|
||||||
|
const isToday = DateTime.fromISO(date).toFormat("yyyy-LL-dd") == DateTime.now().toFormat("yyyy-LL-dd")
|
||||||
|
|
||||||
|
const textStyle = classNames("inline font-bold", {
|
||||||
|
'text-accent-blue': isToday,
|
||||||
|
'text-secondary': !isToday,
|
||||||
|
}, className)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex-none w-20 text-center my-auto pb-3 px-3">
|
||||||
|
<div className={classNames(textStyle, 'text-3xl')}>{DateTime.fromISO(date).toFormat("dd")}</div>
|
||||||
|
<br/>
|
||||||
|
<div className={classNames(textStyle, 'text-xl uppercase')}>{DateTime.fromISO(date).toFormat("LLL")}</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default DateBadge
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
import React from "react";
|
||||||
|
import {UserType} from "~/types/UserType";
|
||||||
|
import ScheduleDayCardUserDish from "~/components/features/schedule/dayCard/ScheduleDayCardUserDish";
|
||||||
|
import { FilledScheduleType, ScheduleType } from "~/types/ScheduleType";
|
||||||
|
import { Link } from "react-router";
|
||||||
|
import {PencilSquareIcon} from "@heroicons/react/24/outline";
|
||||||
|
import useRoutes from "~/hooks/useRoutes";
|
||||||
|
import DateBadge from "~/components/features/schedule/dayCard/DateBadge";
|
||||||
|
import { DateTime } from "luxon"
|
||||||
|
import classNames from "classnames"
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
schedule: ScheduleType|FilledScheduleType;
|
||||||
|
users: UserType[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const ScheduleDayCard = ({schedule, users}: Props) => {
|
||||||
|
const routes = useRoutes()
|
||||||
|
const isToday = DateTime.fromISO(schedule.date).toFormat("yyyy-LL-dd") == DateTime.now().toFormat("yyyy-LL-dd")
|
||||||
|
|
||||||
|
const containerStyles = classNames(
|
||||||
|
'w-full bg-gray-500 pt-5 pb-2 rounded-2xl text-xl', {
|
||||||
|
'border-2 text-accent-blue border-accent-blue': isToday,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="relative flex pt-3 pr-2 w-full border-1 border-accent">
|
||||||
|
<DateBadge date={schedule.date} />
|
||||||
|
|
||||||
|
<div className={containerStyles}>
|
||||||
|
{
|
||||||
|
users.map((user) => <ScheduleDayCardUserDish key={user.id} user={user} schedule={schedule}/>)
|
||||||
|
}
|
||||||
|
|
||||||
|
<div className="w-full mt-2 border-t-2 border-background">
|
||||||
|
<Link
|
||||||
|
className="w-full flex text-sm pr-3 pt-2"
|
||||||
|
aria-label="Edit dish"
|
||||||
|
to={routes.schedule.date.edit(schedule.date)}
|
||||||
|
>
|
||||||
|
<PencilSquareIcon className="h-5 w-5 mr-2 ml-auto" /> Edit
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ScheduleDayCard;
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
import React from "react";
|
||||||
|
import { ScheduledUserDishType } from "@/types/ScheduledUserDishType";
|
||||||
|
import { UserType } from "@/types/UserType";
|
||||||
|
import { FilledScheduleType, ScheduleType } from "@/types/ScheduleType";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
schedule: ScheduleType|FilledScheduleType;
|
||||||
|
user: UserType;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ScheduleDayCardUserDish = ({ schedule, user }: Props) => {
|
||||||
|
const getDish = (user: UserType) => {
|
||||||
|
const scheduled_dishes = schedule.scheduled_user_dishes.filter((scheduled_user_dish: ScheduledUserDishType) => (
|
||||||
|
scheduled_user_dish.user_dish?.user.id == user.id
|
||||||
|
))
|
||||||
|
|
||||||
|
if (scheduled_dishes.length > 0) {
|
||||||
|
return scheduled_dishes[0].user_dish.dish.name
|
||||||
|
}
|
||||||
|
|
||||||
|
return '/'
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="w-full flex background-secondary pb-1 rounded-2xl text-xl" key={ `user-${ user.id }` }>
|
||||||
|
<div className="w-1/3 font-size-16 text-right pr-3">{ user.name } : </div>
|
||||||
|
<div className="w-2/3 font-size-16">{ getDish(user) }</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ScheduleDayCardUserDish;
|
||||||
63
frontend-old/app/components/features/users/EditUserForm.tsx
Normal file
63
frontend-old/app/components/features/users/EditUserForm.tsx
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
import React, {useState} from "react";
|
||||||
|
import { useNavigate } from "react-router";
|
||||||
|
import useRoutes from "~/hooks/useRoutes";
|
||||||
|
import {updateUser} from "~/utils/api/usersApi";
|
||||||
|
import PageTitle from "~/components/ui/PageTitle";
|
||||||
|
import { Link } from "react-router";
|
||||||
|
import Alert from "~/components/ui/Alert";
|
||||||
|
import {UserType} from "~/types/UserType";
|
||||||
|
import SolidButton from "~/components/ui/Buttons/SolidButton";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
user: UserType;
|
||||||
|
}
|
||||||
|
|
||||||
|
const EditUserForm = ({ user }: Props) => {
|
||||||
|
|
||||||
|
const [name, setName] = useState<string>(user.name);
|
||||||
|
const [error, setError] = useState<string>('');
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const routes = useRoutes();
|
||||||
|
|
||||||
|
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
// validateName
|
||||||
|
if (!name.trim()) {
|
||||||
|
setError('Name cannot be empty.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateUser(user, name)
|
||||||
|
.then(() => {
|
||||||
|
navigate(routes.user.index())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="w-full flex flex-col items-center">
|
||||||
|
<PageTitle>Create User</PageTitle>
|
||||||
|
<Link to={routes.user.index()} className="mr-auto">Back to users</Link>
|
||||||
|
|
||||||
|
<form onSubmit={handleSubmit} className="w-full max-w-sm mt-4 border-secondary border-2 rounded p-4">
|
||||||
|
{
|
||||||
|
error != '' && <Alert type="error" className="mt-4">{ error }</Alert>
|
||||||
|
}
|
||||||
|
|
||||||
|
<label htmlFor="name">Name</label>
|
||||||
|
<input type="text"
|
||||||
|
placeholder=""
|
||||||
|
name="name"
|
||||||
|
id="name"
|
||||||
|
value={name}
|
||||||
|
onChange={(e) => setName(e.target.value)}
|
||||||
|
className="w-full p-2 border rounded bg-primary border-secondary bg-gray-600 text-secondary"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<SolidButton type="submit" className="mt-4">Update</SolidButton>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default EditUserForm;
|
||||||
26
frontend-old/app/components/layout/AuthGuard.tsx
Normal file
26
frontend-old/app/components/layout/AuthGuard.tsx
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
import { useAuth } from '@/context/AuthContext';
|
||||||
|
import React, { useEffect } from 'react';
|
||||||
|
import { useLocation, useNavigate } from "react-router"
|
||||||
|
|
||||||
|
export default function AuthGuard({ children }: { children: React.ReactNode }) {
|
||||||
|
const { isAuthenticated } = useAuth();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const location = useLocation();
|
||||||
|
|
||||||
|
const publicRoutes = ['/login', '/register'];
|
||||||
|
const isPublic = publicRoutes.includes(location.pathname);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Handle redirects based on auth state
|
||||||
|
if (isAuthenticated && isPublic) {
|
||||||
|
// Redirect authenticated users away from public pages
|
||||||
|
navigate('/', { replace: true });
|
||||||
|
} else if (!isAuthenticated && !isPublic) {
|
||||||
|
// Redirect unauthenticated users trying to access protected pages
|
||||||
|
navigate('/login', { replace: true });
|
||||||
|
}
|
||||||
|
}, [isAuthenticated, location.pathname, isPublic, navigate]);
|
||||||
|
|
||||||
|
// Render children for all routes - redirects will happen via useEffect
|
||||||
|
return <>{children}</>;
|
||||||
|
}
|
||||||
15
frontend-old/app/components/layout/Card.tsx
Normal file
15
frontend-old/app/components/layout/Card.tsx
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
import React from "react";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
children: React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Card = ({ children }: Props) => {
|
||||||
|
return (
|
||||||
|
<div className="w-full border-2 border-secondary p-2 pl-4 my-2 rounded flex">
|
||||||
|
{ children }
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Card
|
||||||
80
frontend-old/app/components/layout/NavBar.tsx
Normal file
80
frontend-old/app/components/layout/NavBar.tsx
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
import React, { useState } from "react";
|
||||||
|
import { Link, useNavigate } from "react-router";
|
||||||
|
import useRoutes from "~/hooks/useRoutes";
|
||||||
|
import MobileDropdownMenu from "~/components/features/navbar/MobileDropdownMenu";
|
||||||
|
import { useAuth } from "~/context/AuthContext";
|
||||||
|
|
||||||
|
const NavBar = () => {
|
||||||
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
|
const routes = useRoutes();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const {isAuthenticated, logout} = useAuth();
|
||||||
|
|
||||||
|
const handleLogout = (e: React.MouseEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
logout();
|
||||||
|
navigate('/login', { replace: true });
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<nav className="border-b-2 border-secondary shadow-sm z-50 mb-8">
|
||||||
|
<div className="relative flex justify-between items-center px-4 lg:px-8 py-2 lg:container lg:mx-auto">
|
||||||
|
{/* Logo */}
|
||||||
|
<Link to={routes.home()} className="pt-2 text-2xl font-syncopate text-primary">
|
||||||
|
DISH PLANNER
|
||||||
|
</Link>
|
||||||
|
|
||||||
|
{/* Hamburger Menu - For Mobile View */}
|
||||||
|
{ isAuthenticated && (
|
||||||
|
<>
|
||||||
|
<button
|
||||||
|
className="text-primary w-8 h-8 md:hidden flex items-center justify-center"
|
||||||
|
onClick={() => setIsOpen(!isOpen)} // Toggle menu visibility
|
||||||
|
aria-label="Toggle menu"
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
className="h-6 w-6"
|
||||||
|
fill="none"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
stroke="currentColor"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
strokeWidth={2}
|
||||||
|
d={isOpen ? "M6 18L18 6M6 6l12 12" : "M4 6h16M4 12h16M4 18h16"}
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{/* Desktop Menu */}
|
||||||
|
<div className="hidden md:flex space-x-6">
|
||||||
|
<Link to={routes.home()} className="text-accent-blue hover:background-secondary">
|
||||||
|
Home
|
||||||
|
</Link>
|
||||||
|
<Link to={routes.dish.index()} className="text-accent-blue hover:background-secondary">
|
||||||
|
Dishes
|
||||||
|
</Link>
|
||||||
|
<Link to={routes.user.index()} className="text-accent-blue hover:background-secondary">
|
||||||
|
Users
|
||||||
|
</Link>
|
||||||
|
<Link to={routes.schedule.history()} className="text-accent-blue hover:background-secondary">
|
||||||
|
History
|
||||||
|
</Link>
|
||||||
|
<Link to={routes.auth.login()}
|
||||||
|
onClick={handleLogout}
|
||||||
|
className="text-primary text-right hover:background-secondary">
|
||||||
|
Logout
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<MobileDropdownMenu isOpen={isOpen} setIsOpen={setIsOpen} handleLogout={handleLogout} />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default NavBar;
|
||||||
9
frontend-old/app/components/pages/PrivatePage.tsx
Normal file
9
frontend-old/app/components/pages/PrivatePage.tsx
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
const PrivatePage = () => {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
private
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PrivatePage
|
||||||
11
frontend-old/app/components/pages/PublicPage.tsx
Normal file
11
frontend-old/app/components/pages/PublicPage.tsx
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
import { Outlet } from "react-router"
|
||||||
|
|
||||||
|
const PublicPage = () => {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Outlet />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PublicPage
|
||||||
34
frontend-old/app/components/ui/Alert.tsx
Normal file
34
frontend-old/app/components/ui/Alert.tsx
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
import React from "react"
|
||||||
|
import classNames from "classnames";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
children: React.ReactNode;
|
||||||
|
className?: string;
|
||||||
|
type: 'error' | 'warning' | 'info' | 'success';
|
||||||
|
}
|
||||||
|
|
||||||
|
const Alert = ({ children, className, type }: Props) => {
|
||||||
|
let bgColor = 'bg-blue-200'
|
||||||
|
let fgColor = 'bg-blue-800'
|
||||||
|
|
||||||
|
if (type == 'error') {
|
||||||
|
bgColor = 'bg-red-200'
|
||||||
|
fgColor = 'bg-red-800'
|
||||||
|
} else if (type == 'warning') {
|
||||||
|
bgColor = 'bg-orange-200'
|
||||||
|
fgColor = 'bg-orange-800'
|
||||||
|
} else if (type == 'success') {
|
||||||
|
bgColor = 'border-2 border-green-500'
|
||||||
|
fgColor = 'text-green-500'
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = classNames(fgColor, bgColor, className, 'rounded')
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles}>
|
||||||
|
{ children}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Alert
|
||||||
62
frontend-old/app/components/ui/Button.tsx
Normal file
62
frontend-old/app/components/ui/Button.tsx
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
import { Link } from "react-router";
|
||||||
|
import React from "react";
|
||||||
|
import classNames from "classnames";
|
||||||
|
|
||||||
|
interface ButtonProps {
|
||||||
|
appearance?: 'solid' | 'outline' | 'text';
|
||||||
|
children: React.ReactNode;
|
||||||
|
className?: string;
|
||||||
|
href?: string;
|
||||||
|
icon?: React.ReactNode;
|
||||||
|
onClick?: () => void;
|
||||||
|
disabled?: boolean;
|
||||||
|
size?: 'small' | 'medium' | 'large';
|
||||||
|
type?: 'button' | 'submit' | 'reset';
|
||||||
|
variant?: 'primary' | 'secondary' | 'accent';
|
||||||
|
}
|
||||||
|
|
||||||
|
const Button = ({ appearance, children, className, disabled, href, icon, onClick,
|
||||||
|
size = 'medium', type,
|
||||||
|
variant = 'primary'
|
||||||
|
}: ButtonProps) => {
|
||||||
|
const styles = classNames(
|
||||||
|
"flex items-center space-x-1",
|
||||||
|
"justify-center font-size-18 py-2 px-4 rounded flex",
|
||||||
|
{
|
||||||
|
'border-2 border-primary background-red text-white': variant === 'primary' && appearance === 'solid',
|
||||||
|
'border-2 border-primary text-primary': variant === 'primary' && appearance === 'outline',
|
||||||
|
'text-primary': variant === 'primary' && appearance === 'text',
|
||||||
|
'border-2 border-secondary text-secondary': variant === 'secondary' && appearance === 'outline',
|
||||||
|
'border-2 border-accent-blue text-accent-blue': variant === 'accent' && appearance === 'outline',
|
||||||
|
},
|
||||||
|
className
|
||||||
|
)
|
||||||
|
|
||||||
|
const iconClassNames = classNames({
|
||||||
|
"h-4 w-4 mr-1": size === "small",
|
||||||
|
"h-5 w-5 mr-1": size === "medium",
|
||||||
|
"h-7 w-7 mr-2": size === "large",
|
||||||
|
});
|
||||||
|
|
||||||
|
const iconElement =
|
||||||
|
React.isValidElement(icon) &&
|
||||||
|
React.cloneElement(icon as React.ReactElement<{ className?: string }>, {
|
||||||
|
className: iconClassNames,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (href !== undefined) {
|
||||||
|
return (
|
||||||
|
<Link to={href} className={styles}>
|
||||||
|
{ icon && iconElement}
|
||||||
|
{ children}
|
||||||
|
</Link>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return <button onClick={onClick} className={styles} disabled={disabled} type={ type ?? 'button'}>
|
||||||
|
{ icon && iconElement}
|
||||||
|
{ children }
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Button
|
||||||
37
frontend-old/app/components/ui/Buttons/OutlineButton.tsx
Normal file
37
frontend-old/app/components/ui/Buttons/OutlineButton.tsx
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
import React from "react";
|
||||||
|
import classNames from "classnames";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
children: React.ReactNode;
|
||||||
|
className?: string;
|
||||||
|
disabled?: boolean;
|
||||||
|
onClick?: () => void;
|
||||||
|
size?: "small" | "medium" | "large";
|
||||||
|
type: 'submit' | 'button';
|
||||||
|
}
|
||||||
|
|
||||||
|
const OutlineButton = ({ children, className, disabled = false, onClick, size, type }: Props) => {
|
||||||
|
const style = classNames(
|
||||||
|
"justify-center border-2 border-accent font-size-18 text-accent-blue py-2 px-4 rounded flex",
|
||||||
|
{ 'text-xs': size === "small" },
|
||||||
|
className
|
||||||
|
)
|
||||||
|
|
||||||
|
if (onClick === undefined) {
|
||||||
|
onClick = () => {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
type={ type }
|
||||||
|
className={ style }
|
||||||
|
disabled={ disabled }
|
||||||
|
onClick={ onClick }
|
||||||
|
>
|
||||||
|
{ children }
|
||||||
|
</button>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default OutlineButton
|
||||||
49
frontend-old/app/components/ui/Buttons/OutlineLinkButton.tsx
Normal file
49
frontend-old/app/components/ui/Buttons/OutlineLinkButton.tsx
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
import React from "react";
|
||||||
|
import classNames from "classnames";
|
||||||
|
import { Link } from "react-router"
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
children: React.ReactNode;
|
||||||
|
className?: string;
|
||||||
|
href: string;
|
||||||
|
icon?: React.ReactNode;
|
||||||
|
size?: "small" | "medium" | "large";
|
||||||
|
variant?: "primary" | "secondary";
|
||||||
|
}
|
||||||
|
|
||||||
|
const OutlineLinkButton = ({ children, className, href, icon, size = "medium", variant }: Props) => {
|
||||||
|
const linkClassNames = classNames(
|
||||||
|
"underline font-default pt-3 pb-3 px-4 rounded mb-0 flex",
|
||||||
|
{
|
||||||
|
'text-primary border-primary': variant === "primary",
|
||||||
|
'text-secondary border-secondary': variant === "secondary",
|
||||||
|
'text-accent-blue border-accent': !variant || !["primary", "secondary"].includes(variant),
|
||||||
|
}, {
|
||||||
|
'text-size-14': size === "small",
|
||||||
|
'font-size-18': !size || size === "medium",
|
||||||
|
'text-2xl': size === "large",
|
||||||
|
},
|
||||||
|
className,
|
||||||
|
)
|
||||||
|
|
||||||
|
const iconClassNames = classNames("mt-0.5", {
|
||||||
|
"h-4 w-4 mr-1": size === "small",
|
||||||
|
"h-5 w-5 mr-1": size === "medium", // Default size
|
||||||
|
"h-7 w-7 mr-2": size === "large",
|
||||||
|
});
|
||||||
|
|
||||||
|
const iconElement =
|
||||||
|
React.isValidElement(icon) &&
|
||||||
|
React.cloneElement(icon as React.ReactElement<{ className?: string }>, {
|
||||||
|
className: iconClassNames,
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Link className={linkClassNames} to={href}>
|
||||||
|
{iconElement}
|
||||||
|
{children}
|
||||||
|
</Link>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default OutlineLinkButton
|
||||||
40
frontend-old/app/components/ui/Buttons/SolidButton.tsx
Normal file
40
frontend-old/app/components/ui/Buttons/SolidButton.tsx
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
import React from "react";
|
||||||
|
import classNames from "classnames";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
children: React.ReactNode;
|
||||||
|
className?: string;
|
||||||
|
disabled?: boolean;
|
||||||
|
onClick?: () => void;
|
||||||
|
size?: "small" | "medium" | "large";
|
||||||
|
type: 'submit' | 'button';
|
||||||
|
}
|
||||||
|
|
||||||
|
const SolidButton = ({ children, className, disabled = false, onClick, size, type }: Props) => {
|
||||||
|
const style = classNames(
|
||||||
|
"py-2 px-4 bg-primary text-white text-xl p-2 rounded hover:bg-secondary mb-0",
|
||||||
|
{
|
||||||
|
'text-xs': size === "small",
|
||||||
|
'font-size-18': !size || size === "medium",
|
||||||
|
},
|
||||||
|
className
|
||||||
|
)
|
||||||
|
|
||||||
|
if (onClick === undefined) {
|
||||||
|
onClick = () => {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
className={ style }
|
||||||
|
disabled={ disabled }
|
||||||
|
onClick={ onClick }
|
||||||
|
type={ type }
|
||||||
|
>
|
||||||
|
{ children }
|
||||||
|
</button>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default SolidButton
|
||||||
46
frontend-old/app/components/ui/Buttons/SolidLinkButton.tsx
Normal file
46
frontend-old/app/components/ui/Buttons/SolidLinkButton.tsx
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
import React from "react";
|
||||||
|
import classNames from "classnames";
|
||||||
|
import { Link } from "react-router"
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
children: React.ReactNode;
|
||||||
|
className?: string;
|
||||||
|
href: string;
|
||||||
|
icon?: React.ReactNode;
|
||||||
|
size?: "small" | "medium" | "large";
|
||||||
|
variant?: "primary" | "secondary";
|
||||||
|
}
|
||||||
|
|
||||||
|
const SolidLinkButton = ({ children, className, href, icon, size = "medium", variant }: Props) => {
|
||||||
|
const style = classNames(
|
||||||
|
"py-2 px-4 text-xl p-2 rounded hover:bg-secondary mb-0 text-center flex",
|
||||||
|
{
|
||||||
|
'background-red text-white': variant === "primary",
|
||||||
|
'background-secondary border-2 border-secondary': variant === "secondary",
|
||||||
|
},
|
||||||
|
className
|
||||||
|
)
|
||||||
|
|
||||||
|
const iconClassNames = classNames("mt-1", {
|
||||||
|
"h-4 w-4 mr-1": size === "small",
|
||||||
|
"h-5 w-5 mr-1": size === "medium", // Default size
|
||||||
|
"h-7 w-7 mr-2": size === "large",
|
||||||
|
});
|
||||||
|
|
||||||
|
const iconElement =
|
||||||
|
React.isValidElement(icon) &&
|
||||||
|
React.cloneElement(icon as React.ReactElement<{ className?: string }>, {
|
||||||
|
className: iconClassNames,
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Link className={style} to={href}>
|
||||||
|
<div className="flex-grow"></div>
|
||||||
|
{iconElement}
|
||||||
|
{children}
|
||||||
|
<div className="flex-grow"></div>
|
||||||
|
</Link>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default SolidLinkButton
|
||||||
17
frontend-old/app/components/ui/Description.tsx
Normal file
17
frontend-old/app/components/ui/Description.tsx
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
import classNames from "classnames";
|
||||||
|
import React from "react";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
children: React.ReactNode;
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Description = ({ children, className }: Props) => {
|
||||||
|
const style = classNames("italic font-size-16",
|
||||||
|
className
|
||||||
|
)
|
||||||
|
|
||||||
|
return <p className={style}>{ children }</p>
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Description
|
||||||
13
frontend-old/app/components/ui/Hr.tsx
Normal file
13
frontend-old/app/components/ui/Hr.tsx
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
import classNames from "classnames"
|
||||||
|
|
||||||
|
interface HrProps {
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Hr = ({ className }: HrProps) => {
|
||||||
|
const styles = classNames("my-4 border-secondary", className)
|
||||||
|
|
||||||
|
return <hr className={styles}/>
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Hr
|
||||||
25
frontend-old/app/components/ui/Label.tsx
Normal file
25
frontend-old/app/components/ui/Label.tsx
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
import React from "react";
|
||||||
|
|
||||||
|
interface LabelProps {
|
||||||
|
href?: string;
|
||||||
|
children: React.ReactNode;
|
||||||
|
onClick?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Label = ({ href, children, onClick }: LabelProps) => {
|
||||||
|
const styles = "items-center space-x-1 background-accent p-2 rounded"
|
||||||
|
|
||||||
|
if (href !== undefined) {
|
||||||
|
return (
|
||||||
|
<div className={styles}>
|
||||||
|
{ children}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return <button className={styles} onClick={onClick}>
|
||||||
|
{ children }
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Label
|
||||||
60
frontend-old/app/components/ui/Modal.tsx
Normal file
60
frontend-old/app/components/ui/Modal.tsx
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
import { type JSX } from "react";
|
||||||
|
import classNames from "classnames";
|
||||||
|
import Button from "@/components/ui/Button"
|
||||||
|
|
||||||
|
interface ModalProps {
|
||||||
|
buttonChildren?: JSX.Element;
|
||||||
|
buttonClassName?: string;
|
||||||
|
buttonLabel?: string;
|
||||||
|
modalChildren: JSX.Element;
|
||||||
|
modalOpen?: boolean;
|
||||||
|
setModalOpen: (open: boolean) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Modal = ({
|
||||||
|
buttonLabel,
|
||||||
|
buttonClassName,
|
||||||
|
modalChildren,
|
||||||
|
modalOpen,
|
||||||
|
buttonChildren,
|
||||||
|
setModalOpen,
|
||||||
|
}: ModalProps) => {
|
||||||
|
const buttonStyles = classNames(buttonClassName, 'anta-regular');
|
||||||
|
|
||||||
|
const closeModal = () => {
|
||||||
|
setModalOpen(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Button variant="primary" appearance="outline" type="button" onClick={() => setModalOpen(true)} className={buttonStyles}>
|
||||||
|
{buttonChildren
|
||||||
|
? buttonChildren
|
||||||
|
: buttonLabel ?? 'button'
|
||||||
|
}
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
{/*<Dialog open={modalOpen} onClose={setModalOpen} className="relative z-10">*/}
|
||||||
|
{/* <DialogBackdrop*/}
|
||||||
|
{/* transition*/}
|
||||||
|
{/* className="fixed inset-0 bg-gray-500/75 transition-opacity data-closed:opacity-0 data-enter:duration-300 data-enter:ease-out data-leave:duration-200 data-leave:ease-in"*/}
|
||||||
|
{/* />*/}
|
||||||
|
{/* <div className="fixed inset-0 z-10 w-screen overflow-y-auto">*/}
|
||||||
|
{/* <div*/}
|
||||||
|
{/* className="flex min-h-full items-start mt-5 justify-center p-4 text-center sm:items-center sm:p-0">*/}
|
||||||
|
{/* <DialogPanel*/}
|
||||||
|
{/* transition*/}
|
||||||
|
{/* className="relative transform overflow-hidden rounded-lg bg-primary text-left shadow-xl transition-all data-closed:translate-y-4 data-closed:opacity-0 data-enter:duration-300 data-enter:ease-out data-leave:duration-200 data-leave:ease-in sm:my-8 sm:w-full sm:max-w-lg data-closed:sm:translate-y-0 data-closed:sm:scale-95"*/}
|
||||||
|
{/* >*/}
|
||||||
|
{/* <XMarkIcon width={24} className="absolute top-4 right-4 cursor-pointer"*/}
|
||||||
|
{/* onClick={() => closeModal()}/>*/}
|
||||||
|
{/* {modalChildren}*/}
|
||||||
|
{/* </DialogPanel>*/}
|
||||||
|
{/* </div>*/}
|
||||||
|
{/* </div>*/}
|
||||||
|
{/*</Dialog>*/}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Modal;
|
||||||
17
frontend-old/app/components/ui/PageTitle.tsx
Normal file
17
frontend-old/app/components/ui/PageTitle.tsx
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
import classNames from "classnames";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
children: string,
|
||||||
|
className?: string,
|
||||||
|
}
|
||||||
|
|
||||||
|
const PageTitle = ({ children, className }: Props) => {
|
||||||
|
const styles = classNames(
|
||||||
|
'ml-4 text-2xl font-default uppercase w-full text-accent-blue font-bold',
|
||||||
|
className,
|
||||||
|
)
|
||||||
|
|
||||||
|
return <h1 className={styles}>{ children }</h1>
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PageTitle
|
||||||
65
frontend-old/app/components/ui/RecurrenceInput.tsx
Normal file
65
frontend-old/app/components/ui/RecurrenceInput.tsx
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
import React, {useState} from "react";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
value: number;
|
||||||
|
setValue: (value: number) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const RecurrenceInput = ({ value, setValue}: Props) => {
|
||||||
|
const [openInput, setOpenInput] = useState<'category' | 'number'>([7, 365].includes(value) ? 'category' : 'number')
|
||||||
|
|
||||||
|
const toggleInput = (e: React.MouseEvent<HTMLButtonElement>) => {
|
||||||
|
e.preventDefault()
|
||||||
|
setOpenInput(openInput == 'category' ? 'number' : 'category')
|
||||||
|
}
|
||||||
|
|
||||||
|
const toggleButton = () => {
|
||||||
|
return (
|
||||||
|
<button onClick={toggleInput} className={'mt-2'}>
|
||||||
|
{
|
||||||
|
openInput === 'number'
|
||||||
|
? 'or select from presets'
|
||||||
|
: 'or choose amount of days...'
|
||||||
|
}
|
||||||
|
</button>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const prepareValue = (v: string) => {
|
||||||
|
setValue(parseInt(v))
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div className={openInput === 'number' ? 'hidden' : ''}>
|
||||||
|
<label htmlFor="recurrence-category" className="block text-sm font-medium">Recurrence</label>
|
||||||
|
<select
|
||||||
|
id="recurrence-category"
|
||||||
|
name="recurrence-category"
|
||||||
|
value={value}
|
||||||
|
onChange={(e) => prepareValue(e.target.value)}
|
||||||
|
className="w-full p-2 mb-4 border rounded bg-primary border-secondary bg-gray-600 text-secondary"
|
||||||
|
>
|
||||||
|
<option value="7">Weekly</option>
|
||||||
|
<option value="365">Yearly</option>
|
||||||
|
</select>
|
||||||
|
{ toggleButton() }
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={openInput === 'number' ? '' : 'hidden'}>
|
||||||
|
<label htmlFor="recurrence-number" className="block text-sm font-medium">Recurrence</label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
id="recurrence-number"
|
||||||
|
name="recurrence-number"
|
||||||
|
value={value}
|
||||||
|
onChange={(e) => prepareValue(e.target.value)}
|
||||||
|
className="p-2 border rounded w-full bg-gray-500 border-secondary"
|
||||||
|
/>
|
||||||
|
{ toggleButton() }
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default RecurrenceInput
|
||||||
16
frontend-old/app/components/ui/SectionTitle.tsx
Normal file
16
frontend-old/app/components/ui/SectionTitle.tsx
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
import classNames from "classnames";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
children: string;
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SectionTitle = ({ children, className }: Props) => {
|
||||||
|
const style = classNames("block font-size-18 uppercase w-full pl-2 text-accent-blue",
|
||||||
|
className
|
||||||
|
)
|
||||||
|
|
||||||
|
return <h2 className={style}>{ children }</h2>
|
||||||
|
}
|
||||||
|
|
||||||
|
export default SectionTitle
|
||||||
41
frontend-old/app/components/ui/Toggle.tsx
Normal file
41
frontend-old/app/components/ui/Toggle.tsx
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
|
||||||
|
interface ToggleProps {
|
||||||
|
checked: boolean;
|
||||||
|
onChange: (checked: boolean) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Toggle = ({ checked, onChange }: ToggleProps) => {
|
||||||
|
const handleChange = () => {
|
||||||
|
onChange(checked);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<label
|
||||||
|
className="flex items-center relative w-max cursor-pointer select-none"
|
||||||
|
>
|
||||||
|
{/* Hidden input */}
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={checked}
|
||||||
|
onChange={() => handleChange()} // Update state using the checkbox itself
|
||||||
|
className="sr-only"
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Toggle text-accent-blue */}
|
||||||
|
<div
|
||||||
|
className={`relative transition-colors w-14 h-7 rounded-full cursor-pointer ${
|
||||||
|
checked ? "bg-green-500" : "bg-red-500"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{/* The slider dot */}
|
||||||
|
<span
|
||||||
|
className={`absolute top-0.5 left-0.5 w-6 h-6 rounded-full transform transition-transform bg-white ${
|
||||||
|
checked ? "translate-x-7" : "translate-x-0"
|
||||||
|
}`}
|
||||||
|
></span>
|
||||||
|
</div>
|
||||||
|
</label>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Toggle;
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue