-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feature/crud user #35
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool ^^
src/components/UserCard/index.tsx
Outdated
<BoxBase pt={2} width={1} display="flex" justifyContent="flex-end"> | ||
<BoxBase mr={1}> | ||
<ButtonBase | ||
onClick={() => userProps.onUpdate(userProps.userId)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to test this behavior so as to get full coverage, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool 🔥
interface IUpSertPageProps { | ||
userProps?: IUser; | ||
isUpdate: boolean; | ||
sendDatatoServer: (user: IUser) => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be "sendDataToServer"
}} | ||
src={user.avatar || anonymousAvatarLink} | ||
style={avatarStyle} | ||
/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use AvatarBase component instead of img tag. AvatarBase already has a BoxBase outside of it. You can easily custom it to fit your need.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok I will do it to reuse
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! But it will be better to have a record of live demo and the stories, don't you think?
const AlertBase = (props: AlertBaseProps) => { | ||
return <MaterialAlert {...props} />; | ||
}; | ||
const AlertBase = React.forwardRef(function AlertBase(props: AlertBaseProps, ref) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add generic here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sizeWidth = null, | ||
sizeHeight = null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should set a default size here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or you can force these props in the interface
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export interface SlideBaseProps extends MaterialSlideProps {} | ||
|
||
const SlideBase = React.forwardRef((props: SlideBaseProps, ref) => { | ||
return <MaterialSlide ref={ref} {...props} mountOnEnter unmountOnExit />; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should give other devs ways to customize mount behavior
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
export interface SlideBaseProps extends MaterialSlideProps {} | ||
|
||
const SlideBase = React.forwardRef((props: SlideBaseProps, ref) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add generic here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
render(<UserCard {...props} />); | ||
const UserCardButtons = screen.getByTestId("UserCard__buttons").querySelectorAll("button"); | ||
const UpdateButton = UserCardButtons[0]; | ||
fireEvent.click(UpdateButton!); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure you don't need to await this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think await is not need, because in this code, click is set updatedId = userId. This action is not needed waiting for time to test so await is not need in this test
|
||
export const anonymousAvatarLink = | ||
"https://cdn1.vectorstock.com/i/thumb-large/22/05/male-profile-picture-vector-1862205.jpg"; | ||
const UserCard = (userProps: IUserProps) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should put user's exclusive components in /pages/user or something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kien123456k hello please help me check again
|
||
const sendDataToServer = (user: IUser) => { | ||
mutate({ | ||
name: user.name || "", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should validate instead of sending ""
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/pages/Users/hooks/useGetUsers.ts
Outdated
|
||
const useGetUser = (limit: number = 1, offset: number = 0, _ilike: string = "%%") => { | ||
const queryClient = useQueryClient(); | ||
const result = useQuery(["GetUsersWithPagingQuery", { limit, offset, _ilike }], async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const result = useQuery(["GetUsersWithPagingQuery", { limit, offset, _ilike }], async () => { | |
const result = useQuery(["GetUsersWithPagingQuery", limit, offset, _ilike ], async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will change it
|
||
const sendDataToServer = (user: IUser) => { | ||
mutate({ | ||
name: user.name || "", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please validate instead of sending blank to db
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
… DrawerBase, DrawerTriggerButton, ImageBase, ListItemButtonBase and ListBase
…s after they are refactored
…r generated interface
sx={{ | ||
borderRadius: "calc(1rem + 6px)", | ||
}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is from the old code of @thienduc12311 to make the styling like in Reply design.
options?: UseMutationOptions<UpdateUserMutation, GraphQLErrorType, UpdateUserMutationVariables> | ||
) => { | ||
return useMutation<UpdateUserMutation, UpdateUserMutationVariables>({ | ||
queryKey: ["UpdateUser"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this query key is missing something, do you know what it is?
unmountOnExit?: boolean; | ||
mountOnEnter?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if it's necessary to add this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I removed it.
describe("<ButtonGroupBase />", () => { | ||
let props: ButtonGroupBaseProps; | ||
|
||
it("should exist children with primary color", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're not testing for primary color here but your test says so
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, my bad.
@@ -11,3 +12,11 @@ export type QueryInfo = { | |||
preloadedQuery: PreloadedQuery<OperationType>; | |||
queryObject: any; | |||
}; | |||
|
|||
export interface IUser { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why this is necessary?
</TypographyBase> | ||
</BoxBase> | ||
</BoxBase> | ||
<BoxBase width={1} mt={5} display="flex" justifyContent="center" alignItems="center"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should consider use grid for this one right?
Link demo: https://drive.google.com/file/d/1eCwRU8OM5I3Pjcb9gL6odnwSqWAGHmLK/view?usp=sharing