Skip to content

Commit

Permalink
Grab company info for project form + disable inputs (#408)
Browse files Browse the repository at this point in the history
  • Loading branch information
juancwu authored Feb 4, 2025
2 parents ca07d1e + 78b0366 commit 6aa5725
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 9 deletions.
12 changes: 12 additions & 0 deletions backend/internal/v1/v1_projects/questions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"KonferCA/SPUR/db"
"KonferCA/SPUR/internal/v1/v1_common"
"net/http"
"time"

"github.com/google/uuid"
"github.com/labstack/echo/v4"
Expand Down Expand Up @@ -80,6 +81,17 @@ func (h *Handler) handleGetQuestions(c echo.Context) error {
return v1_common.Fail(c, http.StatusBadRequest, "Failed to get questions (2)", err)
}

if projectID != "" {
// this only applies when the project questions are fetched for a specific project
// aka a project that belongs to an existing company
if arr, ok := questions.([]db.GetQuestionsByProjectRow); ok {
// first question is the company name
arr[0].Answer = company.Name
// second question is the date founded
arr[1].Answer = time.Unix(company.DateFounded, 0).Format("2006-01-02")
}
}

teamMembers, err = q.ListTeamMembers(c.Request().Context(), company.ID)
if err != nil && err.Error() != "no rows in result set" {
return v1_common.Fail(c, http.StatusInternalServerError, "Failed to get questions", err)
Expand Down
23 changes: 14 additions & 9 deletions frontend/src/components/DateInput/DateInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface DateInputProps {
name?: string;
max?: Date;
min?: Date;
disabled?: boolean;
}

export const DateInput: React.FC<DateInputProps> = ({
Expand All @@ -21,15 +22,21 @@ export const DateInput: React.FC<DateInputProps> = ({
error,
max,
min,
disabled,
}) => {
const formatDate = (date?: Date) => {
if (!date) return '';
return date.toISOString().split('T')[0];
try {
return date.toISOString().split('T')[0];
} catch (e) {}
return '';
};

const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const date = new Date(e.target.value);
onChange(date);
try {
const date = new Date(e.target.value);
onChange(date);
} catch (e) {}
};

return (
Expand Down Expand Up @@ -57,13 +64,11 @@ export const DateInput: React.FC<DateInputProps> = ({
} rounded-lg text-gray-900 focus:outline-none focus:ring-2 ${
error ? 'focus:ring-red-500' : 'focus:ring-blue-500'
} text-base`}
disabled={disabled}
/>
</div>
{error && (
<p className="mt-1 text-sm text-red-500">
{error}
</p>
)}
{error && <p className="mt-1 text-sm text-red-500">{error}</p>}
</div>
);
};
};

3 changes: 3 additions & 0 deletions frontend/src/components/QuestionInputs/QuestionInputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const QuestionInputs: FC<QuestionInputsProps> = ({
: ''
}
required={field.required}
disabled={field.disabled}
/>
);

Expand All @@ -63,6 +64,7 @@ export const QuestionInputs: FC<QuestionInputsProps> = ({
? 'This input has invalid content'
: ''
}
disabled={field.disabled}
/>
);

Expand Down Expand Up @@ -116,6 +118,7 @@ export const QuestionInputs: FC<QuestionInputsProps> = ({
<DateInput
value={field.value.value}
onChange={(v) => onChange(question.id, field.key, v)}
disabled={field.disabled}
/>
);

Expand Down
1 change: 1 addition & 0 deletions frontend/src/config/forms/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export function groupProjectQuestions(
)
: undefined,
value: {},
disabled: q.disabled,
};

switch (inputField.type) {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/pages/user/_auth/project/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ const NewProjectPage = () => {
questions: subsection.questions.map((question) => ({
...question,
inputFields: question.inputFields.map((field) => {
if (field.disabled) {
return field;
}

const key = `${question.id}_${field.key}`;

// Skip file and team input types
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface FormField {
validations?: ZodTypeAny[];
value: FormFieldValue;
invalid?: boolean;
disabled?: boolean;
}

export interface FormSection {
Expand Down

0 comments on commit 6aa5725

Please sign in to comment.