Skip to content

Commit

Permalink
fix: prevent joining non-existent productions
Browse files Browse the repository at this point in the history
  • Loading branch information
martinstark committed Apr 16, 2024
1 parent f1e19b7 commit 705b140
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions src/components/landing-page/join-production.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type TProps = {
export const JoinProduction = ({ preSelected }: TProps) => {
const [joinProductionId, setJoinProductionId] = useState<null | number>(null);
const {
formState: { errors },
formState: { errors, isValid },
register,
handleSubmit,
reset,
Expand Down Expand Up @@ -156,7 +156,6 @@ export const JoinProduction = ({ preSelected }: TProps) => {
/>
</>
)}

<FormLabel>
<DecorativeLabel>Username</DecorativeLabel>
<FormInput
Expand All @@ -173,7 +172,6 @@ export const JoinProduction = ({ preSelected }: TProps) => {
name="username"
as={StyledWarningMessage}
/>

<FormLabel>
<DecorativeLabel>Input</DecorativeLabel>
<FormSelect
Expand All @@ -191,7 +189,6 @@ export const JoinProduction = ({ preSelected }: TProps) => {
)}
</FormSelect>
</FormLabel>

<FormLabel>
<DecorativeLabel>Output</DecorativeLabel>
{outputDevices.length > 0 ? (
Expand All @@ -211,31 +208,40 @@ export const JoinProduction = ({ preSelected }: TProps) => {
</StyledWarningMessage>
)}
</FormLabel>

{!preSelected && (
<FormLabel>
<DecorativeLabel>Line</DecorativeLabel>
{production ? (
<FormSelect
// eslint-disable-next-line
{...register(`lineId`)}
>
{production &&
production.lines.map((line) => (
<option key={line.id} value={line.id}>
{line.name || line.id}
</option>
))}
</FormSelect>
) : (

<FormSelect
// eslint-disable-next-line
{...register(`lineId`, {
required: "Line id is required",
minLength: 1,
})}
style={{
display: production ? "block" : "none",
}}
>
{production &&
production.lines.map((line) => (
<option key={line.id} value={line.id}>
{line.name || line.id}
</option>
))}
</FormSelect>
{!production && (
<StyledWarningMessage>
Please enter a production id
</StyledWarningMessage>
)}
</FormLabel>
)}

<ActionButton type="submit" onClick={handleSubmit(onSubmit)}>
<ActionButton
type="submit"
disabled={!isValid}
onClick={handleSubmit(onSubmit)}
>
Join
</ActionButton>
</>
Expand Down

0 comments on commit 705b140

Please sign in to comment.