Skip to content

Commit

Permalink
Merge pull request #10 from marmelab/features/edit-users
Browse files Browse the repository at this point in the history
added users edit form
  • Loading branch information
slax57 authored Feb 4, 2025
2 parents 908e75d + 57165bc commit a18439e
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 2 deletions.
2 changes: 2 additions & 0 deletions 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 @@ -69,6 +70,7 @@ const App = () => {
<Resource
name="users_view"
list={UserList}
edit={UserEdit}
options={{ label: "Users" }}
></Resource>
<CustomRoutes noLayout>
Expand Down
2 changes: 1 addition & 1 deletion src/games/GameList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const postFilters = [

export const GameList = () => (
<List filters={postFilters}>
<Datagrid>
<Datagrid isRowSelectable={() => false}>
<TextField source="id" />
<TextField source="first_player" label="First player" />
<TextField source="second_player" label="Second player" />
Expand Down
Empty file added src/users/UserDataProvider.tsx
Empty file.
30 changes: 30 additions & 0 deletions src/users/UserEdit.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {
Edit,
SimpleForm,
TextInput,
ReferenceInput,
AutocompleteInput,
email,
} from "react-admin";

const filterToQuery = (searchText: any) => ({
"name@ilike": `%${searchText}%`,
});

export const UserEdit = () => (
<Edit resource="users" redirect="/users_view">
<SimpleForm>
<TextInput source="username" label="Username" />
<TextInput source="first_name" label="First Name" />
<TextInput source="last_name" label="Last Name" />
<TextInput source="email" label="Email" validate={email()} />
<ReferenceInput source="league_id" reference="leagues">
<AutocompleteInput
optionText="name"
label="League"
filterToQuery={filterToQuery}
/>
</ReferenceInput>
</SimpleForm>
</Edit>
);
2 changes: 1 addition & 1 deletion src/users/UserList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const postFilters = [

export const UserList = () => (
<List filters={postFilters}>
<Datagrid>
<Datagrid isRowSelectable={() => false}>
<TextField source="id" />
<TextField source="username" label="Username" />
<TextField source="first_name" label="First name" />
Expand Down
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;

0 comments on commit a18439e

Please sign in to comment.