From 4f122cc57c9210f19fb8a36782fd16b3c42a3112 Mon Sep 17 00:00:00 2001 From: Bryce Vonilten Date: Thu, 6 Jun 2019 14:30:27 -0700 Subject: [PATCH] Added a test to make sure updated numbers do not match existing ones --- src/screens/ArtisanHub/AddArtisan.js | 15 +++++++++++++++ src/screens/ArtisanHub/EditArtisan.js | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/screens/ArtisanHub/AddArtisan.js b/src/screens/ArtisanHub/AddArtisan.js index 37f8977..97e12c8 100644 --- a/src/screens/ArtisanHub/AddArtisan.js +++ b/src/screens/ArtisanHub/AddArtisan.js @@ -56,6 +56,21 @@ export default class AddArtisan extends Component { validFields = this.displayErrorMessage("Only alphabetic characters allowed for name.") } } + + if (this.state.phoneNumber) { + //console.log("Artisans ======> " + JSON.stringify(this.props.Artisans)) + //console.log("Tried entering phone nuber: " + this.state.phoneNumber) + + let phoneMatch = this.props.Artisans.some((artisan) => { + //console.log(JSON.stringify(artisan)) + return artisan.phoneNumber == this.state.phoneNumber + }) + + if (phoneMatch) { + console.log("Found matching number!"); + validFields = this.displayErrorMessage("Phone field cant be used already") + } + } if (!this.state.phoneNumber) validFields = this.displayErrorMessage("Phone field required") diff --git a/src/screens/ArtisanHub/EditArtisan.js b/src/screens/ArtisanHub/EditArtisan.js index 5ea1ee5..fb36868 100644 --- a/src/screens/ArtisanHub/EditArtisan.js +++ b/src/screens/ArtisanHub/EditArtisan.js @@ -62,6 +62,21 @@ class EditArtisan extends Component { validFields = this.displayErrorMessage("Only alphabetic characters allowed for name.") } } + + if (this.state.phoneNumber) { + //console.log("Artisans ======> " + JSON.stringify(this.props.Artisans)) + //console.log("Tried entering phone nuber: " + this.state.phoneNumber) + + let phoneMatch = this.props.Artisans.some((artisan) => { + //console.log(JSON.stringify(artisan)) + return artisan.phoneNumber == this.state.phoneNumber + }) + + if (phoneMatch) { + console.log("Found matching number!"); + validFields = this.displayErrorMessage("Phone field cant be used already") + } + } if (!this.state.phoneNumber) validFields = this.displayErrorMessage("Phone field required")