redux-form wizard with ant.design or antd Steps - wizard

I want to use redux-form with antd normal components can be handled via renderField component but I want to use antd Steps https://ant.design/components/steps/ with redux-form. How to implement this? Can someone guide me?

Here is where i started from:
Redux-form wizard form
Antd steps
and here is my redux-form with antd steps combined.
The <Form /> is inside the modal. Steps are stored in redux store. In my case steps are controlled by saga (if response success > increment to step 3, if requires additional verification > increment to step 2 etc...) but you can increment/set steps by clicking next/submit or decrement/reset steps by clicking on previous/close modal.
const Form = ({ hide, isLoading, step, name, setStep }) => (
<FormCard>
{step === 1 && <StepOneText name={name} />}
{step === 2 && <StepTwoText name={name} />}
{step === 3 && <StepThreeText name={name} hide={hide} />}
<Steps
initial={1}
size="small"
current={step}
style={{ padding: '20px 0' }}
>
<Step
status={stepStatus(step)}
title="Auth"
icon={<Icon type={step === 1 && isLoading ? 'loading' : 'user'} />}
/>
<Step
title="Verify"
icon={<Icon type={step === 2 && isLoading ? 'loading' : 'solution'} />}
/>
<Step
status={step === 3 ? 'finish' : 'wait'}
title="Done"
icon={<Icon type="smile-o" />}
/>
</Steps>
{step === 1 && <RegisterForm />}
{step === 2 && <ChallengeForm />}
{step === 3 && <CallForAction hide={hide} setStep={setStep} />}
</FormCard>
);

Related

How to Implement a search function in reactJS using MaterialUI

I try to develop a pokedex using the pokeapi. For now it works fine, the pokemon are fetched correctly and are displayed in a container. Now i want to implement a function to search and filter the pokemon. Therefore i used MaterialUI to put a searchBar on top of the App.
The fetched pokemon are given from App.js to my Component PokemonList which maps the data. My idea is now to filter the pokemonData before it is given to PokemonList to map only the pokemon i am looking for. But here i am stuck. I have no idea how to connect the search function with my pokemonData Hook from App.js . Can you help me?
This is my searchBar Component:
const SearchAppBar = () => {
const [search, setSearch] = useState("");
console.log(search)
return (
<Box sx={{ flexGrow: 1 }}>
<AppBar position="static" sx={{ bgcolor: "black"}}>
<Toolbar>
<IconButton
size="large"
edge="start"
color="inherit"
aria-label="open drawer"
sx={{ mr: 2 }}
>
<MenuIcon />
</IconButton>
<Typography
variant="h6"
noWrap
component="div"
sx={{ flexGrow: 1, display: { xs: 'none', sm: 'block' } }}
>
<img src={logo} alt="logo" width="150" height="auto" />
</Typography>
<Search>
<SearchIconWrapper>
<SearchIcon />
</SearchIconWrapper>
<StyledInputBase
onChange={(e) => setSearch(e.target.value)}
id = 'searchbox'
placeholder="Search for Pokémon..."
inputProps={{'aria-label': 'search'}}
/>
</Search>
</Toolbar>
</AppBar>
</Box>
);
}
export default SearchAppBar;
you should save the entered value from input into a state and filter your data based on that state

How to dynamically change the css style of a particular item inside a map function

I currently have two map functions to render a board for a chess game like this:
<div className='board'>
{rows.map((item) => (
<div key={item} className='row'>
{item.map((square) => (
# The square <div> => <div key={square[0]} className='square' onClick={() => {
board.select !== null &&
checkColour(board.select[1]) !== checkColour(square[1]) && dispatch(move(square))
}}>
{isNaN(square[1]) && <img src={square[1]} alt={square[1]}
onClick={() => { board.turns === checkColour(square[1]) && dispatch(select(square)) }}
className={board.select === square ? 'piece-selected' : 'piece'} />}
</div>
))}
</div>
))}
</div>
Now, I want to change the css style of certain squares <div> after I selected a pawn piece in order to forecast a shadow for showing the possible moves. I want to know is it possible to access the css style of that particular square <div> using the key of that <div>?
Feel free the drop a comment below if you have any insight or idea. Let me know if you want more info. Much appreciated.

react-router-dom v6 NavLink is always active

I followed Upgrading from v5 guide and I cannot get the NavLink component to work correctly.
https://reactrouter.com/docs/en/v6/upgrading/v5#upgrading-from-v5
v6 Navlinks:
<NavLink
className={(isActive) =>
cx(isActive ? classes.linkActive : classes.link)
}
to="/seafarers"
end
>
Seafarers
</NavLink>
<NavLink
className={(isActive) =>
cx(isActive ? classes.linkActive : classes.link)
}
end
to="/"
>
Planning
</NavLink>
Routes
<BrowserRouter>
<Routes>
<Route path="/" element={<LoginScreen />} />
<Route path="login" element={<LoginScreen />} />
<Route path="forgot-password" element={<ForgotPasswordScreen />} />
<Route path="seafarers" element={<SeafarersScreen />} />
</Routes>
</BrowserRouter>
Both "/" and "/seafarers" have active class
Note: NavLink elements are located in SeafarersScreen screen
How can I correct this issue?
Turns out I had to deconstruct the property of className as ternary operator always returned true for objects
<NavLink
className={({isActive}) => //(isActive) --> ({isActive})
cx(isActive ? classes.linkActive : classes.link)
}
to="/seafarers"
end
>
Seafarers
</NavLink>
For react-router-dom v6
This example demonstrates how to make a custom <Link> component to render something different when the link is "active" using the useMatch() and useResolvedPath() hooks.
Official doc for active link
Add end prop on parent route. This work for react-router-dom: 6.4.4.
<NavLink
to="/"
end
className={({ isActive }) =>`nav-link ${isActive && 'active'}`}>
Notes
</NavLink>
From react-router documentation, here is the link: https://reactrouter.com/en/main/components/nav-link
<NavLink
to="/"
style={({ isActive }) => ({ color: isActive ? "green" : "blue" })}
className={yourClasses}
>
Profile
</NavLink>

Render products grouped by dynamic category [duplicate]

This question already has answers here:
Render products grouped by category
(2 answers)
Closed 2 years ago.
I have a catalog page with a sidebar which contains a dynamic list:
This sidebar lists products.category and updates whenever there is a new category created/removed.
What I want to achieve
Is to be able to show the filtered table based on category that was clicked. Kind of like using props so I can use products.category to automatically fill the filter without hardcoding each category.
I may be approaching this problem wrong.
const showTable = (props) => {
return (
<>
{products && products.length !== 0 ? (
products
.filter((item) => item.category === props.table) // Kind of like this
.map((product) => ExtendedProduct(product))
) : (
<Loader />
)}
</>
);
};
const TableRoutes = () => {
return (
<>
{products &&
productCategories.map((product) => (
<Tab.Pane key={product.category} eventKey={product.category}>
<ShowTable table={product.category} />
</Tab.Pane>
))}
</>
);
};
The productCategories is where I remove the duplicated categories so they won't be doubled when rendered.
The code above is a functional component.
I'm using https://react-bootstrap.netlify.app/components/tabs/#tabs-custom-layout which explains Tab.Pane.
Things I've looked into:
Render products grouped by category [class-based]
After ~12 hours of fiddling around, apparently the solution is quite the same in the linked question.
Render products grouped by category
const TableRoutes = () => {
return (
<>
<Tab.Pane eventKey="default">
<ExtendedTable
data={
products && products.map((product) => ExtendedProduct(product))
}
/>
</Tab.Pane>
{/* Table filtered by product categories */}
{products &&
productCategories.map((categories) => (
<Tab.Pane key={categories.category} eventKey={categories.category}>
<ExtendedTable
data={
products &&
products
.filter((pane) => pane.category === categories.category)
.map((product) => ExtendedProduct(product))
}
/>
</Tab.Pane>
))}
{/* Table filtered by product types */}
{products &&
productTypes.map((types) => (
<Tab.Pane key={types.type} eventKey={types.type}>
<ExtendedTable
data={
products &&
products
.filter((pane) => pane.type === types.type)
.map((product) => ExtendedProduct(product))
}
/>
</Tab.Pane>
))}
</>
);
};
I guess this can be marked as duplicate...

Algolia - How to customize the tags display name in the menuSelect dropdown list

I found this menuSelect widget in Algolia instantSearch and I implemented successfully. But currently the filter names it displayed are the tags directly from the indices config. Is there a way to replace those name with my own filters? e.g. instead of react_pwa, display React storefront Here is the html output.
<MenuSelect class="tags" attribute="tags" transformItems={items =>
items.map(item => ({
...item,
}))}/>
Does anyone know if I can play around with transformItemsprops to solve this problem? Thanks!
Build a custom menuSelect widget can do it.
const MenuSelect = ({ items, currentRefinement, refine }) => (
<select
value={currentRefinement || ''}
onChange={event => refine(event.currentTarget.value)}
>
<option value="">See all options</option>
{items.map(item => (
<option
key={item.label}
value={item.isRefined ? currentRefinement : item.value}
>
{item.label==="react_pwa" && 'React PWA Storefront'}
{item.label==="cloudops-aws" && 'CloudOps for AWS'}
{item.label==="commerce-manager" && 'Commerce Manager'}
{item.label==="cloudops-azure" && 'CloudOps for Azure'}
{item.label==="chatbot" && 'Reference Chatbot'}
{item.label==="alexa-skill" && 'Alexa Skill'}
{item.label==="account-management" && 'Account Management'}
</option>
))}
</select>
);
const CustomMenuSelect = connectMenu(MenuSelect);
then in the search class add <CustomMenuSelect attribute="tags" />