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 all 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
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}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should use bulkActionButtons={false} instead (it completely hides the checkboxes)

Suggested change
<Datagrid isRowSelectable={() => false}>
<Datagrid bulkActionButtons={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">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also add mutationOptions to provide a onSuccess with a refresh()

https://marmelab.com/react-admin/Edit.html#mutationoptions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to change the redirect on the DeleteButton

<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}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<Datagrid isRowSelectable={() => false}>
<Datagrid bulkActionButtons={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;