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 #49 from Team-Tukka/task/7-3/tmc
Browse files Browse the repository at this point in the history
Task 7.3: ID i UI er nu blevet til navn
  • Loading branch information
dani832m committed Dec 13, 2019
2 parents b7dc666 + 7c7c626 commit 6012bfb
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 29 deletions.
19 changes: 4 additions & 15 deletions src/components/categories/AddNewSubCategory.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useState } from 'react';
import { useMutation } from '@apollo/react-hooks';
import { gql } from 'apollo-boost';
import client from '../../config/apolloClient';
import GetCategories from './GetCategories';

// Importér Reactstrap komponenter
import { Form, InputGroup, FormGroup, Input, Button, Alert } from 'reactstrap';
Expand All @@ -12,7 +13,6 @@ function AddNewSubCategory() {
client.cache.reset();

const [name, setName] = useState('');
const [categoryId, setCategoryId] = useState('');
const [imagePath, setImagePath] = useState('');
const [alertStatus, setAlertStatus] = useState(false);

Expand Down Expand Up @@ -46,15 +46,15 @@ function AddNewSubCategory() {
addSubCategory({
variables: {
name: name,
categoryId: categoryId,
categoryId: document.getElementById('chosenCategoryId').value,
imagePath: imagePath
}
});
// Sæt 'alertStatus' til at være true (så den vises)
setAlertStatus(true);
// Clear feltet, så der kan indtastes nye oplysninger
setName('');
setCategoryId('');
document.getElementById('chosenCategoryId').value = '';
setImagePath('');
}
};
Expand All @@ -80,18 +80,7 @@ function AddNewSubCategory() {
</FormGroup>
<FormGroup>
<InputGroup>
<Input
required
className="inputStyles"
type="text"
name="categoryId"
id="subCategoryCategoryId"
minLength="1"
maxLength="50"
value={categoryId}
placeholder="Kategori ID..."
onChange={event => setCategoryId(event.target.value)}
/>
<GetCategories />
</InputGroup>
</FormGroup>
<FormGroup>
Expand Down
22 changes: 22 additions & 0 deletions src/components/categories/GetCategoryById.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import { useQuery } from '@apollo/react-hooks';
import { gql } from 'apollo-boost';

function GetCategoryById(props) {
const GET_SUB_CATEGORY_BY_ID = gql`
{
getCategoryById(_id: "${props.categoryId}") {
name
}
}
`;
// Anvend Query
const { loading, error, data } = useQuery(GET_SUB_CATEGORY_BY_ID);

if (loading) return <p>Loading...</p>;
if (error) return <p>Error!</p>;

return data.getCategoryById.name;
}

export default GetCategoryById;
22 changes: 22 additions & 0 deletions src/components/categories/GetSubCategoryById.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import { useQuery } from '@apollo/react-hooks';
import { gql } from 'apollo-boost';

function GetSubCategoryById(props) {
const GET_SUB_CATEGORY_BY_ID = gql`
{
getSubCategoryById(_id: "${props.subCategoryId}") {
name
}
}
`;
// Anvend Query
const { loading, error, data } = useQuery(GET_SUB_CATEGORY_BY_ID);

if (loading) return <p>Loading...</p>;
if (error) return <p>Error!</p>;

return data.getSubCategoryById.name;
}

export default GetSubCategoryById;
3 changes: 2 additions & 1 deletion src/components/editScooter/EditScooter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState } from 'react';
import GetCategoryById from '../categories/GetCategoryById';
import { useParams } from 'react-router';
import { useMutation, useQuery } from '@apollo/react-hooks';
import { gql } from 'apollo-boost';
Expand Down Expand Up @@ -484,7 +485,7 @@ function EditScooter(props) {
</InputGroup>
</FormGroup>
<FormText color="muted" className="mb-3">
Oprettet i kategorien: {scoCategoryId}
Oprettet i kategorien: <GetCategoryById categoryId={scoCategoryId} />
</FormText>
{/* Vis alert, hvis elscooteren opdateres korrekt */}
{alertStatus === true && (
Expand Down
4 changes: 3 additions & 1 deletion src/components/editSparepart/EditSparepart.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState } from 'react';
import GetSubCategoryById from '../categories/GetSubCategoryById';
import { useParams } from 'react-router';
import { useMutation, useQuery } from '@apollo/react-hooks';
import { gql } from 'apollo-boost';
Expand Down Expand Up @@ -285,7 +286,8 @@ function EditSparepart(props) {
)}
</FormGroup>
<FormText color="muted" className="mb-3">
Oprettet under splittegningen: {spaSubCategoryId}
Oprettet under splittegningen:{' '}
<GetSubCategoryById subCategoryId={spaSubCategoryId} />
</FormText>
{/* Vis alert, hvis reservedelen opdateres korrekt */}
{alertStatus === true && (
Expand Down
3 changes: 2 additions & 1 deletion src/components/products/ScooterRows.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { Link } from 'react-router-dom';
import { useQuery } from '@apollo/react-hooks';
import { gql } from 'apollo-boost';
import GetCategoryById from '../categories/GetCategoryById';

function ScooterRows() {
// Definér først query til at hente array med alle elscootere
Expand Down Expand Up @@ -61,7 +62,7 @@ function ScooterRows() {
</td>
<td>
<Link to={`/editScooter/${_id}`} className="linkStyles">
{categoryId}
<GetCategoryById categoryId={categoryId} />
</Link>
</td>
</tr>
Expand Down
7 changes: 4 additions & 3 deletions src/components/products/SparepartRows.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { Link } from 'react-router-dom';
import { useQuery } from '@apollo/react-hooks';
import { gql } from 'apollo-boost';
import GetSubCategoryById from '../categories/GetSubCategoryById';

function SparepartRows() {
// Definér først query til at hente array med alle reservedele
Expand All @@ -13,7 +14,7 @@ function SparepartRows() {
name
price
priceVAT
categoryId
subCategoryId
}
}
`;
Expand All @@ -36,7 +37,7 @@ function SparepartRows() {

// Returnér nu alle props for hvert enkel reservedel som en tabel-række
return data.getSpareparts.map((sparepart, index) => {
const { _id, itemNo, name, price, priceVAT, categoryId } = sparepart; // Destructuring
const { _id, itemNo, name, price, priceVAT, subCategoryId } = sparepart; // Destructuring
return (
<tr key={_id} className="tableRowStyles">
<td>
Expand All @@ -61,7 +62,7 @@ function SparepartRows() {
</td>
<td>
<Link to={`/editSparepart/${_id}`} className="linkStyles">
{categoryId}
<GetSubCategoryById subCategoryId={subCategoryId} />
</Link>
</td>
</tr>
Expand Down
3 changes: 2 additions & 1 deletion src/components/scooters/ScooterCards.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Link } from 'react-router-dom';
import { useQuery } from '@apollo/react-hooks';
import { gql } from 'apollo-boost';
import dummyImgScooter from '../../assets/images/dummyImgScooter.png';
import GetCategoryById from '../categories/GetCategoryById';

// Importér Reactstrap komponenter
import {
Expand Down Expand Up @@ -83,7 +84,7 @@ function ScooterCards() {
<CardFooter className="veryLightGreenBg">
Kategori:{' '}
<Link to="#" className="linkStyles">
{categoryId}
<GetCategoryById categoryId={categoryId} />
</Link>
</CardFooter>
</Card>
Expand Down
3 changes: 2 additions & 1 deletion src/components/showScooter/ShowScooter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import GetCategoryById from '../categories/GetCategoryById';
import { useParams } from 'react-router';
import { useQuery } from '@apollo/react-hooks';
import { gql } from 'apollo-boost';
Expand Down Expand Up @@ -77,7 +78,7 @@ function ShowScooter() {
<b>SKU:</b> {scoSku}
</li>
<li>
<b>Kategori:</b> {scoCategoryId}
<b>Kategori:</b> <GetCategoryById categoryId={scoCategoryId} />
</li>
<li className="my-4">{scoDescription}</li>
<li className="priceGlow">{scoPrice} DKK</li>
Expand Down
9 changes: 3 additions & 6 deletions src/components/showSparepart/ShowSparepart.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import GetSubCategoryById from '../categories/GetSubCategoryById';
import { useParams } from 'react-router';
import { useQuery } from '@apollo/react-hooks';
import { gql } from 'apollo-boost';
Expand All @@ -19,7 +20,6 @@ function ShowSparepart() {
name,
price,
priceVAT,
categoryId,
subCategoryId
}
}
Expand All @@ -36,7 +36,6 @@ function ShowSparepart() {
const spaPrice = data.getSparepartById.price;
const spaPriceVAT = data.getSparepartById.priceVAT;
const spaItemNo = data.getSparepartById.itemNo;
const spaCategoryId = data.getSparepartById.categoryId;
const spaSubCategoryId = data.getSparepartById.subCategoryId;

return (
Expand All @@ -48,11 +47,9 @@ function ShowSparepart() {
<li>
<b>Enhedsnummer:</b> {spaItemNo}
</li>
<li>
<b>Kategori/model:</b> {spaCategoryId}
</li>
<li className="mb-4">
<b>Underkategori/splittegning:</b> {spaSubCategoryId}
<b>Underkategori/splittegning:</b>{' '}
<GetSubCategoryById subCategoryId={spaSubCategoryId} />
</li>
<li className="priceGlow">{spaPrice} DKK</li>
<li className="priceVAT">{spaPriceVAT} DKK inkl. moms</li>
Expand Down

0 comments on commit 6012bfb

Please sign in to comment.