-
Notifications
You must be signed in to change notification settings - Fork 99
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
feat: company update page #149
Conversation
Thank you for following the naming conventions for pull request titles! 🙏 |
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.
Awesome Work BTW ❤️ . I've left some comments suggesting a few changes in the code review.
const { update } = useSession(); | ||
const router = useRouter(); | ||
const { toast } = useToast(); | ||
const companyQuery = api.company.getCompany.useQuery(undefined, { |
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 should be fetched in a server component and passed as a prop
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.
Thought about passing the prop from the server component. Didn't want to mix trpc and server components but passing prop will remove useEffect
. That will be good one.
}, | ||
}); | ||
|
||
useEffect(() => { |
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.
we don't need this effect. we can create a similar conditional type for the prop and pass it on the default values of react-hook-form
type FormType =
| {
type: "create";
data?: never;
}
| {
type: "edit";
data: Data[];
}
| {
type: "onboard";
data?: never;
};
type CompanyFormProps = {
user: User;
} & FormType;
name: data?.name, | ||
incorporationType: data?.incorporationType, | ||
incorporationDate: data?.incorporationDate | ||
? new Date(data.incorporationDate).toISOString().split("T")[0] |
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.
date manipulation should be handled by day-js
getCompany: withAuth.query(async ({ ctx }) => { | ||
const user = ctx.session.user; | ||
|
||
const company = await ctx.db.company.findFirstOrThrow({ |
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's safe to query the user's company through membership because sometimes JWTs are stale. In case the user is removed from the company and the JWT isn't updated, this query won't fail; it would work fine.
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.
Hmm.. Good catch. Thanks for the heads up
|
||
await ctx.db.company.update({ | ||
where: { | ||
id: ctx.session.user.companyId, |
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.
use the companyId
from previously fetched Membership Data (memberAuthorized)
Closes #91
PS: I haven't added audit logs though. Will be there in a new PR ;)