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

feat: company update page #149

Merged
merged 11 commits into from
Mar 1, 2024
Merged

feat: company update page #149

merged 11 commits into from
Mar 1, 2024

Conversation

chetannn
Copy link
Collaborator

@chetannn chetannn commented Feb 24, 2024

Closes #91

PS: I haven't added audit logs though. Will be there in a new PR ;)

Copy link

github-actions bot commented Feb 24, 2024

Thank you for following the naming conventions for pull request titles! 🙏

@chetannn chetannn requested review from dahal and G3root February 27, 2024 13:23
@chetannn chetannn marked this pull request as ready for review February 27, 2024 13:24
Copy link
Collaborator

@G3root G3root left a 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, {
Copy link
Collaborator

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

Copy link
Collaborator Author

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(() => {
Copy link
Collaborator

@G3root G3root Feb 27, 2024

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]
Copy link
Collaborator

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({
Copy link
Collaborator

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.

Copy link
Collaborator Author

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,
Copy link
Collaborator

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)

@dahal dahal merged commit 8ef36f8 into main Mar 1, 2024
2 checks passed
@dahal dahal deleted the feat/company-edit-page branch March 1, 2024 05:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Company update endpoint
3 participants