Skip to content

Add handling for contractor applications #69

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jumraiya
Copy link

Draft PR.

I have added the model code needed to create new contractor listings along with isDraft set to 1.

I need some guidance on adding tests (seems like current smoke tests are skipped). Also we should probably add some kind of a confirmation page which tells the user their application was submitted and under review.

I am typescript newbie so I am not sure if I should be using a type for api request payloads right now it's a regular js object which generates a warning in vscode.

@jumraiya jumraiya requested a review from sheldon-b April 18, 2025 19:39
Copy link
Member

@sheldon-b sheldon-b left a comment

Choose a reason for hiding this comment

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

Nice! This looks good. I'm happy with this if you can clean up the type errors. I tested it locally and it worked

I agree on the confirmation page. Will create a ticket for that.

@@ -61,3 +65,51 @@ export const getContractors = async (page = 1, pageSize = 10) => {
throw new Error("Failed to fetch contractors");
}
};

export async function createContractor(data) {
Copy link
Member

Choose a reason for hiding this comment

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

Not sure this'll fix the typescript error -- I haven't tried it -- but it'd be my first attempt.

Also -- the createContractor function would be a helpful constructor to have on the Contractor data model instead of a helper method here. Just a suggestion. You don't have to do it in this PR

Suggested change
export async function createContractor(data) {
export async function createContractor(contractor: Contractor) {

@@ -1,6 +1,7 @@
import { MetaFunction, ActionFunctionArgs, redirect } from "@remix-run/node";
import { Form, useActionData } from "@remix-run/react";
import React, { useState, Dispatch, SetStateAction } from "react";
import { createContractor } from "~/models/contractor.server";
Copy link
Member

Choose a reason for hiding this comment

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

Running npm run lint:fix should fix this error and any other auto-fixable lint errors

@@ -502,25 +506,40 @@ export async function action({ request }: ActionFunctionArgs) {
errors.website = "Please provide a valid website URL.";
}

let statesServed = null;
let statesServed: Array<String> = [];
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
let statesServed: Array<String> = [];
let statesServed: string[] = [];

errors.statesServed = "Please select at least one state.";
}

let services = null;
let services: Array<String> = [];
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
let services: Array<String> = [];
let services: string[] = [];

@@ -48,5 +49,37 @@ describe("smoke tests", () => {

cy.findByText("No notes yet");
});

it.skip("should allow contractors to request to be listed", () => {
Copy link
Member

Choose a reason for hiding this comment

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

Cool! Feel free to unskip this if it passes

I know it's not great but we just haven't been writing tests. The timeline is so short that we've just been aiming to get it working and then flesh out tests after May 10th.

try {
const statesServed = []
for (const stateName of data["statesServed"]) {
const state: State = await prisma.state.findFirst({where: {name: stateName}});
Copy link
Member

Choose a reason for hiding this comment

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

I suggest using findFirstOrThrow here and for services and certifications, so you don't have to check for null yourself

Suggested change
const state: State = await prisma.state.findFirst({where: {name: stateName}});
const state = await prisma.state.findFirstOrThrow({where: {name: stateName}});

}
});
} catch (error) {
console.log("Error creating contractor", error);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
console.log("Error creating contractor", error);
console.error("Error creating contractor", error);

@sheldon-b
Copy link
Member

sheldon-b commented Apr 22, 2025

Oh, also, you can check for lint failures with npm run lint and type errors with npm run typecheck. You can also run npm run validate which basically runs all of the checks that the CI does (including lint and typechecking)

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.

2 participants