Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added users edit form #10

Merged
merged 4 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Box, Typography } from "@mui/material";
import { GameShow } from "./games/GameShow";
import { Route } from "react-router";
import { UserList } from "./users/UserList";
import { UserEdit } from "./users/UserEdit";

const instanceUrl =
import.meta.env.VITE_SUPABASE_API_URL || "http://127.0.0.1:54321";
Expand Down Expand Up @@ -67,8 +68,9 @@ const App = () => {
options={{ label: "Games" }}
></Resource>
<Resource
name="users_view"
name="users"
slax57 marked this conversation as resolved.
Show resolved Hide resolved
list={UserList}
edit={UserEdit}
options={{ label: "Users" }}
></Resource>
<CustomRoutes noLayout>
Expand Down
22 changes: 22 additions & 0 deletions src/users/UserEdit.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {
Edit,
SimpleForm,
TextInput,
EmailField,
ReferenceInput,
AutocompleteInput,
} from "react-admin";

export const UserEdit = () => (
<Edit resource="users">
<SimpleForm>
<TextInput source="username" label="Username" />
<TextInput source="first_name" label="First Name" />
<TextInput source="last_name" label="Last Name" />
<EmailField source="email" label="Email" />
julienjme marked this conversation as resolved.
Show resolved Hide resolved
<ReferenceInput source="league_id" reference="leagues">
<AutocompleteInput optionText="name" label="League" />
julienjme marked this conversation as resolved.
Show resolved Hide resolved
</ReferenceInput>
</SimpleForm>
</Edit>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ALTER TABLE games DROP CONSTRAINT IF EXISTS games_first_player_id_fkey;
ALTER TABLE games DROP CONSTRAINT IF EXISTS games_second_player_id_fkey;

ALTER TABLE games
ADD CONSTRAINT games_first_player_id_fkey
FOREIGN KEY (first_player_id)
REFERENCES users(id)
ON DELETE CASCADE;

ALTER TABLE games
ADD CONSTRAINT games_second_player_id_fkey
FOREIGN KEY (second_player_id)
REFERENCES users(id)
ON DELETE CASCADE;