Skip to content

Commit

Permalink
--ammend
Browse files Browse the repository at this point in the history
  • Loading branch information
ndahimana154 committed Sep 13, 2024
1 parent 0630b22 commit 09c5f9d
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 84 deletions.
59 changes: 27 additions & 32 deletions src/components/GoogleForm/SaveForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import axios from '../../redux/actions/axiosconfig';
import { showSuccessToast, showErrorToast } from './../../utils/toast';
import { useFormik } from 'formik';
import * as Yup from 'yup';
import SelectField from "../ReusableComponents/Select"

const validationSchema = Yup.object().shape({
link: Yup.string().required('Please enter a Google Form link'),
Expand Down Expand Up @@ -160,11 +161,10 @@ function SaveFormDetails() {
<div className='mt-1'>
<input
autoComplete='title'
className={`block w-full text-primary rounded-md border-gray-300 py-3 px-4 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 ${
formik.touched.title && formik.errors.title
? 'border-red-500'
: ''
}`}
className={`block w-full text-primary rounded-md border-gray-300 py-3 px-4 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 ${formik.touched.title && formik.errors.title
? 'border-red-500'
: ''
}`}
id='title'
name='title'
onChange={formik.handleChange}
Expand All @@ -190,27 +190,24 @@ function SaveFormDetails() {
<label className='sr-only' htmlFor='jobpost'>
Job Post
</label>

<select
className={`block w-full text-primary rounded-md border-gray-300 py-3 px-4 pl-20 focus:border-indigo-500 focus:ring-indigo-500 ${
formik.touched.jobpost && formik.errors.jobpost
? 'border-red-500'
: ''
}`}
<SelectField
className={`block w-full text-primary rounded-md border-gray-300 py-3 px-4 pl-20 focus:border-indigo-500 focus:ring-indigo-500 ${formik.touched.jobpost && formik.errors.jobpost
? 'border-red-500'
: ''
}`}
id='jobpost'
name='jobpost'
onChange={formik.handleChange}
onBlur={formik.handleBlur}
value={formik.values.jobpost}>
{jobposts.length === 0 && (
<option disabled>Select Job Post</option>
)}
{jobposts.map((jobpost) => (
<option key={jobpost.id} value={jobpost.id}>
{jobpost.title}
</option>
))}
</select>
value={formik.values.jobpost}
options={
jobposts.map((jobpost) => (
<option key={jobpost.id} value={jobpost.id}>
{jobpost.title}
</option>
))
}
/>
</div>
{formik.touched.jobpost && formik.errors.jobpost && (
<div className='text-red-500'>{formik.errors.jobpost}</div>
Expand All @@ -228,11 +225,10 @@ function SaveFormDetails() {
<div className='mt-1'>
<input
autoComplete='link'
className={`block w-full text-primary rounded-md border-gray-300 py-3 px-4 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 ${
formik.touched.link && formik.errors.link
? 'border-red-500'
: ''
}`}
className={`block w-full text-primary rounded-md border-gray-300 py-3 px-4 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 ${formik.touched.link && formik.errors.link
? 'border-red-500'
: ''
}`}
id='link'
name='link'
onChange={formik.handleChange}
Expand All @@ -255,11 +251,10 @@ function SaveFormDetails() {

<div className='mt-1'>
<textarea
className={`block w-full text-primary rounded-md border-gray-300 py-3 px-4 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 ${
formik.touched.description && formik.errors.description
? 'border-red-500'
: ''
}`}
className={`block w-full text-primary rounded-md border-gray-300 py-3 px-4 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 ${formik.touched.description && formik.errors.description
? 'border-red-500'
: ''
}`}
defaultValue=''
id='description'
name='description'
Expand Down
21 changes: 8 additions & 13 deletions src/components/GradingBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { connect } from 'react-redux';
import { toast } from 'react-toastify';
import { getAllAssessment } from '../redux/actions/getAssessments';
import { useAppDispatch } from "../hooks/hooks";
import SelectField from './ReusableComponents/Select';

interface Grade {
attribute: string;
Expand Down Expand Up @@ -256,25 +257,19 @@ function GradingBox(props: any) {
</div>
<div className="input mt-4 mb-4 h-9 ">
<div className="grouped-input flex items-center h-full w-full rounded-md">
<select
name=""
<SelectField
className=" dark:text-white dark:bg-dark-tertiary border border-primary rounded outline-none px-5 font-sans text-sm py-2 w-full pt-4"
defaultValue=""
value={assessmentM}
onChange={(e) => {
setAssessmentM(e.target.value)
changeAssess(0, e.target.value)
}}
>
<option disabled hidden value="">{"---Choose Assessment---"}</option>
{
allAssessments?.data &&
(allAssessments?.data.map((element) => {
return (
<option value={element.id}>{element.title}</option>)
})
)}
</select>
options={[{ value: "--- Choose assessment---", label: "Choose assessment" },
allAssessments?.data.map((element) => ({
value: element.id, label: element.label
})
)]}
/>
{assessmentM &&
<div className='h-full w-[10%] pl-2 py-1 items-center'>
<input
Expand Down
82 changes: 43 additions & 39 deletions src/components/ReusableComponents/Select.tsx
Original file line number Diff line number Diff line change
@@ -1,42 +1,46 @@
import React from 'react'
import React from 'react';

interface SelectFieldProps {
id?: string;
name?: string;
value?: string | number;
options: { value: string | number; label: string }[];
onChange?: (e: React.ChangeEvent<HTMLSelectElement>) => void;
ref?: React.Ref<HTMLSelectElement>;
className?: string;
defaultValue?: string | number;
}
id?: string;
name?: string;
value?: string | number;
options: { value: string | number; label: string }[];
onChange?: (e: React.ChangeEvent<HTMLSelectElement>) => void;
ref?: React.Ref<HTMLSelectElement>;
className?: string;
defaultValue?: string | number;
onBlur?: (e: React.FocusEvent<HTMLSelectElement>) => void;
}

const SelectField: React.FC<SelectFieldProps> = ({
id,
name,
value,
options,
onChange,
ref,
className = "",
defaultValue,
}) => {
return (
<select
id={id}
name={name}
ref={ref}
defaultValue={defaultValue}
value={value}
onChange={onChange}
className={`dark:bg-dark-tertiary dark:text-white shadow appearance-none py-2 px-3 rounded w-full leading-tight focus:outline-none focus:shadow-outline ${className}`}
>
{options.map((option) => (
<option key={option.value} value={option.value}>
{option.label}
</option>
))}
</select>
);
};
export default SelectField;
const SelectField: React.FC<SelectFieldProps> = ({
id,
name,
value,
options,
onChange,
ref,
className = "",
defaultValue,
onBlur
}) => {
return (
<select
id={id}
name={name}
ref={ref}
defaultValue={defaultValue}
value={value}
onChange={onChange}
className={`dark:bg-dark-tertiary dark:text-white shadow appearance-none py-2 px-3 rounded w-full leading-tight focus:outline-none focus:shadow-outline ${className}`}
onBlur={(e: React.FocusEvent<HTMLSelectElement>) => onBlur?.(e)}
>
{options.map((option) => (
<option key={option.value} value={option.value}>
{option.label}
</option>
))}
</select>
);
};

export default SelectField;

0 comments on commit 09c5f9d

Please sign in to comment.