Skip to content
This repository has been archived by the owner on Aug 12, 2020. It is now read-only.

Commit

Permalink
Merge pull request #61 from Team-Tukka/task/6/tmc
Browse files Browse the repository at this point in the history
Task 6: Regex på elscooter beskrivelsen
  • Loading branch information
Matttuu committed Jan 6, 2020
2 parents 80ffd19 + f32fa1b commit a81bcda
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function App() {
<Router>
<ApolloProvider client={client}>
<Header />
<AdminNav />
{localStorage.token && <AdminNav />}
<Switch>
{/* Routes til offentligt tilgængeligt indhold */}
<Route path="/" exact component={Textarea} />
Expand Down
8 changes: 5 additions & 3 deletions src/components/addNewScooter/AddNewScooter.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,12 @@ function AddNewScooter() {
name="description"
id="scooterDescription"
minLength="1"
maxLength="200"
value={description}
maxLength="500"
defaultValue={description}
placeholder="Beskrivelse..."
onChange={event => setDescription(event.target.value)}
onChange={event =>
setDescription(event.target.value.replace(/\r?\n/g, '<br>'))
}
/>
<InputGroupAddon
addonType="append"
Expand Down
35 changes: 21 additions & 14 deletions src/components/adminNav/AdminNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,46 @@ import {
NavLink
} from 'reactstrap';

// ME query defineres
export const ME = gql`
{
me {
_id
}
}
`;

// AdminNav komponent
function AdminNav(props) {
function AdminNav() {
// ME2 query defineres
const ME2 = gql`
{
me2(token: ${localStorage.token}) {
_id
firstName
lastName
}
}
`;

// Client initialiseres til at være ME2 query
const { loading, error, data, client } = useQuery(ME2);

// States med React Hooks
const [isOpen, setIsOpen] = useState(false);

// Toggle til at åbne og lukke AdminNav
const toggle = () => setIsOpen(!isOpen);

// Client initialiseres til at være ME query
const { client } = useQuery(ME);

// Funktion der smider token og redirecter til login-siden
const Logout = () => {
localStorage.clear();
client.resetStore();
window.location = '/login';
};

if (loading) return <p className="text-center m-3">Loading...</p>;
if (error) return <p className="text-center m-3">Error!</p>;

return (
<React.Fragment>
{localStorage.token && (
<Navbar className="veryLightGreenBg adminNavStyles" light expand="md">
<Container>
<NavbarBrand></NavbarBrand>
<NavbarBrand href="/welcome">
{data.me2.firstName + ' ' + data.me2.lastName}
</NavbarBrand>
<NavbarToggler onClick={toggle} />
<Collapse isOpen={isOpen} navbar>
<Nav className="ml-auto" navbar>
Expand Down
37 changes: 18 additions & 19 deletions src/components/editScooter/EditScooter.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,23 +206,23 @@ function EditScooter(props) {
const imageUrl =
'https://tukka.fra1.digitaloceanspaces.com/' + blob.name;
setImagePath(imageUrl);
updateScooterById({
variables: {
name: name,
price: price,
sku: sku,
tags: tags,
brand: brand,
description: description,
itemNo: itemNo,
imagePath: imagePath
}
});
// Sæt 'alertStatus' til at være true (så den vises)
setAlertStatus(true);
}
});
}
updateScooterById({
variables: {
name: name,
price: price,
sku: sku,
tags: tags,
brand: brand,
description: description,
itemNo: itemNo,
imagePath: imagePath
}
});
// Sæt 'alertStatus' til at være true (så den vises)
setAlertStatus(true);
}
};

Expand Down Expand Up @@ -261,7 +261,6 @@ function EditScooter(props) {
</InputGroupText>
</InputGroupAddon>
<Input
required
className="inputStylesEditScooter"
type="text"
name="itemNo"
Expand Down Expand Up @@ -310,7 +309,6 @@ function EditScooter(props) {
</InputGroupText>
</InputGroupAddon>
<Input
required
className="inputStylesEditScooter"
type="text"
name="name"
Expand Down Expand Up @@ -552,9 +550,11 @@ function EditScooter(props) {
id="scooterDescription"
minLength="1"
maxLength="200"
defaultValue={description}
defaultValue={description.replace(/<br ?\/?>/g, '\n')}
placeholder="Beskrivelse..."
onChange={event => setDescription(event.target.value)}
onChange={event =>
setDescription(event.target.value.replace(/\r?\n/g, '<br>'))
}
/>
<InputGroupAddon
addonType="append"
Expand Down Expand Up @@ -587,7 +587,6 @@ function EditScooter(props) {
<FormGroup>
<InputGroup>
<Input
required
className="inputStyles p-2"
type="file"
id="scooterImagePath"
Expand Down
2 changes: 0 additions & 2 deletions src/components/editSparepart/EditSparepart.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ function EditSparepart(props) {
</InputGroupText>
</InputGroupAddon>
<Input
required
className="inputStylesEditSparepart"
type="text"
name="itemNo"
Expand Down Expand Up @@ -217,7 +216,6 @@ function EditSparepart(props) {
</InputGroupText>
</InputGroupAddon>
<Input
required
className="inputStylesEditSparepart"
type="text"
name="name"
Expand Down

0 comments on commit a81bcda

Please sign in to comment.