I am looking to sort the salary information based on the radio button selected

When I click on the radio button in the code, I want to filter the data of the salary Array. The rendered data should be filtered according to the text on the radio button. The check box Array filtering is working fine, but after applying the same concept, the radio type is not working properly.

Here's the code snippet:

import {Component} from 'react'
    import Cookies from '[Jobby App](https://i.sstatic.net/ZLavA3Qm.png)js-cookie'
    import {FcSearch} from 'react-icons/fc'
    import {IoMdStar} from 'react-icons/io'
    import {BsFillBagFill} from 'react-icons/bs'
    import {ImLocation2} from 'react-icons/im'
- import './index.css'

const employmentTypesList = [
  {
    label: 'Full Time',
    employmentTypeId: 'FULLTIME',
  },
  {
    label: 'Part Time',
    employmentTypeId: 'PARTTIME',
  },
  {
    label: 'Freelance',
    employmentTypeId: 'FREELANCE',
  },
  {
    label: 'Internship',
    employmentTypeId: 'INTERNSHIP',
  },
]

const salaryRangesList = [
  {
    salaryRangeId: '1000000',
    label: '10 LPA and above',
  },
  {
    salaryRangeId: '2000000',
    label: '20 LPA and above',
  },
  {
    salaryRangeId: '3000000',
    label: '30 LPA and above',
  },
  {
    salaryRangeId: '4000000',
    label: '40 LPA and above',
  },
]

class JobsRoute extends Component {
  state = {
    profileList: [],
    jobsList: [],`your text`
    searchInput: '',
    EmployList: [],
    SalaryList: [],
  }

  componentDidMount() {
    this.renderProfile()
    this.renderJobsApi()
  }

  searchBox = event => {
    this.setState({searchInput: event.target.value})
  }

  renderProfile = async () => {
    //Code for fetching profile details
  }

  renderJobsApi = async () => {
    //Code for fetching jobs API based on filters
  }

  EmployLists = event => {
    //Function to handle checkbox selection for employment types
  }

  SalaryLists = event => {
    //Function to handle radio button selection for salary ranges
  }

  buttonSearch = () => {
    //Function to trigger job search
  }

  searchInputDown = event => {
    //Function to trigger job search on pressing Enter key
  }

  render() {
    return (
      <div className="job-container">
        //Rendering profile info
        //Employment Type checkboxes
        //Salary Range radio buttons

        //Job search input and button
          
          // Job list based on selected filters
       </div>
    )
  }
}
export default JobsRoute

The salary details should be dynamically filtered upon clicking the radio button (salary range).

Answer №1

If you're looking to make a small adjustment, here's a suggestion for you:

// To keep track of the selected salary range ID in the state
state = {
  // Add a new property to hold the selected salary range ID
  selectedSalaryRangeId: '', 
}

// Update the SalaryLists function
SalaryLists = event => {
  const { selectedSalaryRangeId } = this.state;
  const salaryRangeId = event.target.id;
  const isChecked = event.target.checked;

  if (isChecked) {
    // Set the selectedSalaryRangeId when a radio button is checked
    this.setState({ selectedSalaryRangeId: salaryRangeId });
  } else {
    // Clear the selectedSalaryRangeId when a radio button is unchecked
    this.setState({ selectedSalaryRangeId: '' });
  }
}

// Modify the renderJobsApi function to filter based on selectedSalaryRangeId
renderJobsApi = async () => {
  const { selectedSalaryRangeId, searchInput } = this.state;
  const JobsUrl = `https://apis.ccbp.in/jobs?employment_type=${EmployList}&package_per_annum=${selectedSalaryRangeId}&search=${searchInput}`;
  // Keep the rest of the function as it is...
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Dealing with automatic indentation in the Node.js REPL while pasting content

I'm in search of a general idea on how to tackle the issue at hand. I currently have two REPLs - one for my Scheme based LISP written in JavaScript called LIPS, and another one using node.js with readline. The final problem that requires solving is ad ...

Using jQuery to Convert CSV Data into an HTML Table

I've been exploring the incredible jquery.csvtotable.js plugin for converting csv files to html tables. One question that has been on my mind is how can I allow users to select a .csv file using a browse button that isn't a server-side control? ...

Using Typescript types or a linter can help avoid mistakenly rendering the raw function in JSX instead of its executed return value

Seeking a resolution to prevent the recurring mistake I often make, as shown below: export function scratch_1 (props: scratch_1Props): ReactElement | null { function renderA (): string { return "A"; } function renderB (): string { ...

Mastering the art of MUI V4: Implementing conditional row coloring

I've encountered an issue with my basic Material UI v4 datagrid. I'm attempting to change the color of any row that has an age of 16 to grey using color: 'grey'. However, I'm finding it challenging to implement this. The documentat ...

Implement a delay for a specific function and try again if the delay expires

In my TypeScript code, I am utilizing two fetch calls - one to retrieve an access token and the other to make the actual API call. I am looking to implement a 1-second timeout for the second API call. In the event of a timeout, a retry should be attempted ...

Guide on making a Horizontal Flatlist in React Native displaying 2 rows and 3 columns at a time

I am looking to create a Horizontal Scrolling Flatlist with 2 rows and 3 columns visible, pulling dynamic data from an API. Currently, I have successfully implemented a vertical scrolling Flatlist that resembles the following: https://i.sstatic.net/oJJyA. ...

Waiting for Selenium in Javascript

I'm having trouble using Selenium Webdriver with Node.js to scrape Google Finance pages. The driver.wait function is not behaving as expected. I've configured my Mocha timeout at 10 seconds and the driver.wait timeout at 9 seconds. The test passe ...

Utilizing the power of Bootstrap Navbar within React.js

I recently started working with React and I'm trying to create dropdown menus for my navigation. However, I am facing difficulties in getting everything to function as intended. Despite searching for a solution, I haven't been able to make it wor ...

Transfer the values of two divs into a unified output div

I am working on a task that involves two text boxes, one with an id and the other with a class. The goal is to copy the values from both text boxes into a single div when a button is clicked. So far, I have made an attempt at this but only the value from t ...

What is the main reason express.js applications are typically positioned behind nginx or another web server?

From my experience with node.js express app deployment, I've noticed a common trend. Despite the speed and performance advantages of node.js, many developers opt to use nginx as a front-end server for their express apps. This decision often leaves me ...

Achieving consistent alignment for text on a curved path

I am working on a unique "flow-builder" project and I need to achieve this specific result: https://i.sstatic.net/6TTuS.png At the moment, my current edge looks like this: https://i.sstatic.net/9ydzx.png The text on the edge is currently aligned with the ...

JS/TS Strategies for Sharing Code Across Multiple Projects

Perhaps there is a different approach that has not crossed my mind. I have spent some time exploring various methods like js/ts with npm link, git submodules, tsconfig paths, symlink, npm/pnpm/yarn workspace, npm pack & npm link, package.json exports, ...

Determine all the child nodes using Xpath

How can I extract all child nodes (option tags) from the following HTML using Html Agility Pack? <select name="akt-miest" id="onoffaci"> <option value="a_0">Všetci</option> <option value="a_1">Iba prihlásení</option> <o ...

Utilizing Bootstrap 4 to customize the background color of a cell within a table

Working with Boostrap 4, I have a table cell that has the following appearance: https://i.sstatic.net/DSaOu.png I am aiming for the background color to cover the entire cell. How can I remove the white line that shows up between the bottom border of the ...

Bootstrap Model Footer Button Alignment

click hereI'm facing an issue while adding buttons to the model footer. The buttons are not aligning in line, instead they move to the next line. <div class="modal-footer"> <form method="post" action="admin_view"> ...

Issues arose while attempting to upload dependencies to a private npm repository

After setting up a private nexus repository to host my custom nodejs libraries, I encountered an issue where the dependencies of my package were not being published along with it. To publish the package, I followed these steps: npm set registry <regis ...

Reducing the length of Javascript code

Recently, I have been working on a project where I needed to use a piece of Javascript code to insert text into an input element when its label is double-clicked. $(document).ready(function() { $('#name-label').dblclick(function(){ $ ...

CSS classes designed to mimic JavaScript object attribute-value pairs

I stumbled upon some interesting css class-value combinations within HTML tags. It seems like a specific JavaScript code is interpreting this, but it's something I haven't encountered before. I came across this on www.woothemes.com/flexslider/ (y ...

What is the method for customizing the default dropdown color of a bootstrap 4 selectpicker?

In my form, there are single and multiple dropdown selects. To keep things simple, I use the selectpicker class for both types. However, I want to customize the default grey color for Bootstrap 4 Dropdown with the selectpicker class to a clear color. Which ...

Conceal a div once the content in a separate div has finished loading

After loading an image in slices inside a div, I want to ensure that the entire content is loaded before displaying the div. To achieve this, I am using another div as a mask while the content loads: <div id="prepage" style="position:absolute; left:0px ...